LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 10: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, 03: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 03:44 AM.
 
Old 07-09-2011, 11:19 AM   #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, 11:58 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
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, 07:03 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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 07:06 PM.
 
  


Reply



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 01:50 PM
bash catching the function returning value into a variable patolfo Linux - General 6 03-19-2010 11:58 AM
proper way to setup notepad++ to execute bash scripts? PiNPOiNT Programming 4 04-25-2009 11:27 AM
bash script, empty (enter button pushing only) value catching junust Programming 2 12-25-2008 04:18 AM
Bash signal catching meblost Programming 3 11-22-2004 07:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:31 PM.

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
Open Source Consulting | Domain Registration