Unidentified error in bash script that notepad ++ is not catching
Hello,
I've been debugging the following script all evening and am now stuck...this script is supposed to ssh to a router, pull interface conf, 'cut' 3 pieces of info, and then print the results of 2 as well as the 3rd (after running a ping cmd on the linux box): SCRIPT_CODE #! /bin/bash lb1="0" lb2="3"; device=core1.sjo1 while `env test "$lb1" -le "$lb2"` do `ssh orcadmin@$device "sh run int lo $lb1" ; "exit" > conf_info1` echo "`cat conf_info1`" `cat conf_info1 | grep Loopback > lb_int` `cat conf_info1 | grep address > lb_addr` `cat conf_info1 | grep description > lb_desc` interface=`cut -f2 lb_int -d " "` address=`cut -f3 lb_addr -d " "` description=`cut --characters=14- lb_desc` `echo $interface $address` pinginfo=`ping "$address"`; printf "\n $pinginfo" echo "$device $interface is reachable, as the following shows, $pinginfo" lb1=`expr $lb1 + 1` done SCRIPT RUNNING: [linux]$ sh dev* orcadmin@core1.sjo1's password: Connection to core1.sjo1 closed by remote host. : command not found ping: unknown host core1.sjo1 is reachable, as the following shows, --Any assistance/add'l_info would be greatly appreciated |
Hi
I don't think that this line Code:
`ssh orcadmin@$device "sh run int lo $lb1" ; "exit" > conf_info1` Quote:
Quote:
|
I figured out that there is no way to specify a password via ssh...apparently the linux/unix ssh application expects the password to arrive via a TTY session (user input)...thus, the best way I could find, to resolve my issue, was to run an expect script within the shell script...thanks much for your assistance
|
You do know that the construct `` is designed to allow you to return information, generally to a variable.
So your prolific use of it is not doing anything. In fact I am surprised that the script runs at all. As an example: Code:
#!/bin/bash Code:
$ ./test.sh |
To automate ssh, use auth keys instead of putting passwd in a script.
Also, as mentioned, using backquotes is not reqd when running a cmd normally. You do need it to collect the results of a cmd into a var, so Code:
# backquotes not reqd |
All times are GMT -5. The time now is 05:45 PM. |