LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2008, 04:18 PM   #1
babag
Member
 
Registered: Aug 2003
Posts: 426

Rep: Reputation: 31
ssh - using variables in call to start remote script from local script


using mandriva 2007.1.

having trouble using variables in a bash script that i'm
trying to use to call a remote bash script. how do i get
this to work so i can shorten the script by using variables
in these calls?

where:

PLZ=0
BOX=1 to 6 in a loop
IPADD=6 ip addresses held in if/elif conditions,

this doesn't work:
Code:
	ssh "processing-"$PLZ$BOX"@"$IPADD" nohup /home/processing-"$PLZ$BOX"/Documents/Scripts/d2u_and_nconvert.sh "&
but if i explicitly call each box, without the variables,
everything works fine:
Code:
	if [ $BOX -eq 1 ]
	then
	   ssh processing-01@192.168.1.122 nohup /home/processing-01/Documents/Scripts/d2u_and_nconvert.sh &
	elif [ $BOX -eq 2 ]
	then
	   ssh processing-02@192.168.1.124 nohup /home/processing-02/Documents/Scripts/d2u_and_nconvert.sh &
	elif [ $BOX -eq 3 ]
	then
	   ssh processing-03@192.168.1.126 nohup /home/processing-03/Documents/Scripts/d2u_and_nconvert.sh &
	elif [ $BOX -eq 4 ]
	then
	   ssh processing-04@192.168.1.128 nohup /home/processing-04/Documents/Scripts/d2u_and_nconvert.sh &
	elif [ $BOX -eq 5 ]
	then
	   ssh processing-05@192.168.1.130 nohup /home/processing-05/Documents/Scripts/d2u_and_nconvert.sh &
	else [ $BOX -eq 6 ]
	   ssh processing-06@192.168.1.132 nohup /home/processing-06/Documents/Scripts/d2u_and_nconvert.sh &
	fi
also tried this (excludes nohup in the call), which also works:
Code:
	if [ $BOX -eq 1 ]
	then
	   ssh processing-01@192.168.1.122 /home/processing-01/Documents/Scripts/d2u_and_nconvert.sh &
	elif [ $BOX -eq 2 ]
	then
	   ssh processing-02@192.168.1.124 /home/processing-02/Documents/Scripts/d2u_and_nconvert.sh &
	elif [ $BOX -eq 3 ]
	then
	   ssh processing-03@192.168.1.126 /home/processing-03/Documents/Scripts/d2u_and_nconvert.sh &
	elif [ $BOX -eq 4 ]
	then
	   ssh processing-04@192.168.1.128 /home/processing-04/Documents/Scripts/d2u_and_nconvert.sh &
	elif [ $BOX -eq 5 ]
	then
	   ssh processing-05@192.168.1.130 /home/processing-05/Documents/Scripts/d2u_and_nconvert.sh &
	else [ $BOX -eq 6 ]
	   ssh processing-06@192.168.1.132 /home/processing-06/Documents/Scripts/d2u_and_nconvert.sh &
	fi
thanks,
BabaG

Last edited by babag; 06-03-2008 at 04:22 PM.
 
Old 06-03-2008, 04:37 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by babag View Post
this doesn't work:
Code:
	ssh "processing-"$PLZ$BOX"@"$IPADD" nohup /home/processing-"$PLZ$BOX"/Documents/Scripts/d2u_and_nconvert.sh "&
What "doesn't work" means? Which error message did you get? The only thing I see here, is a missing space between $IPADD and the double quotes. The following should work
Code:
ssh processing-$PLZ$BOX@$IPADD "nohup /home/processing-$PLZ$BOX/Documents/Scripts/d2u_and_nconvert.sh"
I stripped out some double quotes, actually not needed.
 
Old 06-03-2008, 05:50 PM   #3
babag
Member
 
Registered: Aug 2003
Posts: 426

Original Poster
Rep: Reputation: 31
thanks for the reply, colucix.

meant that the remote script never started when i said
my command didn't work. actually just finished testing
another solution i found elsewhere online and it worked
well. here's the link:

http://systemsboy.blogspot.com/2006/...n-scripts.html

that solution suggested that the entire command needed
to be wrapped into a line of text as a variable and then
executed:
Code:
sshcmd="ssh processing-"$PLZ$BOX"@"$IPADD" nohup /home/processing-"$PLZ$BOX"/Documents/Scripts/d2u_and_nconvert.sh "

$sshcmd &
thanks again,
BabaG

Last edited by babag; 06-03-2008 at 05:52 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
Possible to call a client side command from a script on server, via SSH connection. a2brute Linux - Networking 7 04-07-2008 01:11 PM
bash - start remote script from local script? babag Programming 7 04-06-2008 06:46 PM
set variables in a bash script; ansi PS1 color script donnied Programming 4 11-21-2007 12:33 PM
clamd upgradation in remote mach through local mac by script to be run on local mach Narayandutt Programming 3 11-29-2006 11:00 AM
shell script to compare filese b/w local and remote and delete files from local serve dsids Linux - Networking 9 08-23-2006 08:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:37 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