LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   ssh - using variables in call to start remote script from local script (https://www.linuxquestions.org/questions/linux-networking-3/ssh-using-variables-in-call-to-start-remote-script-from-local-script-646761/)

babag 06-03-2008 03:18 PM

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

colucix 06-03-2008 03:37 PM

Quote:

Originally Posted by babag (Post 3173647)
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.

babag 06-03-2008 04:50 PM

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


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