LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-24-2011, 11:12 PM   #1
tfarnsworth74
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Rep: Reputation: Disabled
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
 
Old 06-25-2011, 04:41 AM   #2
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi

I don't think that this line
Code:
`ssh orcadmin@$device "sh run int lo $lb1" ; "exit" > conf_info1`
lets the script to stay connected, in fact I think that you should implement a "password" for the user "orcadmin" to log in as this line states it requires password:
Quote:
orcadmin@core1.sjo1's password:
after that the script will run
Quote:
`cat conf_info1 | grep Loopback > lb_int`
`cat conf_info1 | grep address > lb_addr`
`cat conf_info1 | grep description > lb_desc`
...

Last edited by lithos; 06-25-2011 at 04:44 AM.
 
Old 07-09-2011, 12:19 PM   #3
tfarnsworth74
LQ Newbie
 
Registered: Jun 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
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
 
Old 07-09-2011, 12:58 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
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

tada=blah

`echo $tada`
When run:
Code:
$ ./test.sh
./test.sh: line 5: blah: command not found
 
Old 07-10-2011, 08:03 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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
cat somefile
echo $var1
var2=$var1

# reqd
var1=`cat somefile`

Last edited by chrism01; 07-10-2011 at 08:06 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching signed and unsigned integers in BASH madyogi Linux - Software 4 12-30-2010 02:50 PM
bash catching the function returning value into a variable patolfo Linux - General 6 03-19-2010 12:58 PM
proper way to setup notepad++ to execute bash scripts? PiNPOiNT Programming 4 04-25-2009 12:27 PM
bash script, empty (enter button pushing only) value catching junust Programming 2 12-25-2008 05:18 AM
Bash signal catching meblost Programming 3 11-22-2004 08:38 PM


All times are GMT -5. The time now is 04:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration