I am currently stuck with a situation where i need to hide the resolved value of a variable, i.e., the value should not appear when the code runs in the debug mode i.e., ksh -x.
I have seen other threads on similar kind of problem but there, a way has been provided when the value is read from STDIN, with the help of read -s option. But i do not have to read the value from STDIN.
Kindly help me with this.
Thanks,
Amit
When the field to be hidden is unique (something like a strong password), you can make a wrapper that changes the output of the script.
You should only take care for the special characters in the variable such as a slash. Try something like
mycode.sh 2>&1 | sed "s/${myvar}/xxxxxxxx/g"
When you use the variable on a few places only, a good alternative is testing the mode you are running in, and turn off the debug mode before using the variable (and turn on one line later).
Related
While working on my project at work, I came across a startup script for the application which just kind of sets up all the environment variable, paths that sort of thing. I see variables assigned to values like this
set abc=%def%
and also like this:
set xyz=#pqr#
Whats the difference between using #xxxx# against %xxxx% ? I haven't done any batch scripting but looked around could not find an answer to this strangely.
% marks things as variables, which you can set, change, and read, (You can also use ! if delayed expansion is enabled.) while # is just a character, which will print as is and is not used for variables.
ssh to an IP supplied via user input
Inject show running-config command
Search the output of the command and look for specific parameters like ports, QoS, VTY lines, SMTP settings, IP helpers etc.
Output only if the predefined parameters are not in place
If I store the output of the ssh run in a variable, is there a method I can use for parsing through it and just go with endless if, elsif, and else statements? How would that look?
It can be in Python bash or Perl, doesn't matter to me really but I don't know how to structure the thing and then fill in the gaps and expand the script.
Here's where I imagine starting from
use Net::SSH2
use File::Slurp;
print "\nEnter command list filename: ";
my $commandlist = <STDIN>;
chomp($commandlist);
my #commandfile = read_file($commandlist, chomp => 1);
my $commandsize = #commandfile;
How would I store the output of the commands in a variable or a temporary file and parse through it with conditions?
This is a very broad question, and it is unclear exactly what is puzzling you
The documentation for
Net::SSH2
and
Net::SSH2::Channel
describes clearly how to open a channel, send commands to it, and receive the response
You ask how you could store the results of the command in a variable, but it would be very awkward to do anything else. Again, the documentation describes this clearly
I suggest that you try writing some working code and experiment with it. It will be much easier to help you when you have a specific question
Now i try find the way to prove that a clear command is working correctly on my own REPL
Example
$ cd ~
$ pwd
/home/user
$ echo "hello"
hello
then type clear
$
but sometime some unexpected behavior is occurred after using a clear command
e.g.
[one blank line here]
$
A one blank line after using clear command is undesirable behavior and I hope this kind of bug can be detected automatically via a unit test. If you have any idea to prove that clear command is working correctly please purpose.
There is no easy way to do this. "clear" sends a sequence of bytes that tells the terminal to clear its screen. Different terminals use different sequences. There is a table called "termcap" (terminal capabilities) that lists the difference sequences for different types of terminals. The environment variable "TERM" should be set to the type of terminal you are using.
TERM is usually set to "xterm", "xterm-color", "vt100", or related value. On my Mac OS X Terminal it is set to "xterm-256color".
TERM should be set automatically for you. If your OS is set up properly you shouldn't have to set it yourself. However in the old days you had to set it manually. Therefore you'll find a lot of old .profile/.bashrc/.cshrc files that set it. Check to see if that is happening and remove that (comment it out) to see what is automatically set.
Your question boils down to "how can I tell if my TERM variable is set right?" and the answer is: You can't. You could do things like clear the screen then ask the user if they saw their screen clear. However, if programs did that on start-up, it would be very annoying.
When using Mac OS X including iTerm, I can simply press
Shift+$ and the line in bash that I am currently tiping will get a # added to the beginning and the line returns. I like this very much as it prevents from actually executing that command while still editing it and I don't have to jump to the beginning of the line to insert that # character there.
However, when I log onto our cluster, this functionality is lost. I tried to search for this feature but only found posts about using sed etc. so suggestions which are not for the interactive kind of using bash that I am referring to.
Could somebody please point me to a resource where this functionality is explained (bash-guide?) so I could look up how to make it work when logging in to other machines? Or is this something Mac/iTerm-specific? But then, I would expect it to work also on our cluster, as long as I use my machine of course.
This might work for you
See insert-comment (M-#)
I must work with tcsh.
I am using an internal tool that provides basic completion for some of its commands.
I would like to extend the completion.
I mean that in future releases the default completion may evolve.
I tried something like this:
set def_cmpl = complete tool
complete tool $def_cmpl 'n/-l/(reg short long gui)/'
But I don't understand the result I get.
Indeed, the quotes inside $def_cmpl are doubled:
tcsh> complete tool
''n#-t#$script#'' n/-l/(reg short long gui)/'
I tried some tricks with echo, sed, etc. but I can't avoid those ''.
Could somebody help me?
Please don't say go on bash... The tool doesn't support it...
Finally, I did not find a solution to keep the data inside the script. So, the solution was to redirect the output of the complete command inside a file and then to append new lines to the file.