LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   wait for ssh remote commands. (https://www.linuxquestions.org/questions/linux-newbie-8/wait-for-ssh-remote-commands-874957/)

xeon123 04-14-2011 05:48 AM

wait for ssh remote commands.
 
Hi,

I'm running a scripts that launches remotely another script with ssh. Here's the script:

main.sh
Code:

ssh user@remote "~/script1.sh"
ssh user@remote "~/script2.sh"

Here's the remote script:

script1.sh
Code:

java -jar pkg.jar
script2.sh
Code:

java -jar prg.jar
When I run the main.sh, the script1.sh and script2.sh will be launched. But what I want, is that the main.sh must run script2.sh only after script1.sh ends. What is happening, is that, the main.sh don't wait for script1.sh to ends before run script2.sh.

How can I add this capability?

zordrak 04-14-2011 06:40 AM

KISS.

Quote:

ssh user@remote "~/script1.sh"
sleep 10
ssh user@remote "~/script2.sh"

Nylex 04-14-2011 06:53 AM

Why is it not possible to put both commands in a single script?

brownie_cookie 04-14-2011 07:02 AM

you can do something like this

script1.sh:
Code:

java -jar pkg.jar
echo 1

main.sh:
Code:

VAR=`ssh user@remote "~/script1.sh"`

# i do this echo to see if $VAR contains something
echo $VAR

if [ $VAR == 1 ]; then
ssh user@remote "~/script2.sh"
else
echo did not run
fi

maybe this works?

xeon123 04-14-2011 08:19 AM

A smarter answer better that KISS, is like Nylex said. Put everything in one script. This is simple, and does not use the command "sleep" that was really unnecessary.

zordrak 04-14-2011 08:22 AM

My response was based on the assumption that there was a reason the scripts are separate. I don't like to answer a post with "you're doing it wrong" if I don't have detailed context.

brownie_cookie 04-14-2011 08:23 AM

nvm :p

xeon123 04-14-2011 08:30 AM

zordrak, It's not you're doing wrong. I simply don't know when script1.sh would end. It can take minutes, just like it can take hours. I din't explain that because I just didn't remembered. Anyway, thanks for the help also.

xeon123 04-14-2011 08:32 AM

By the way, not related to the post, it exists so many acronyms, that I simply don't understand all. The KISS acronym is new for me. And by the way, what nvm means?

brownie_cookie 04-14-2011 08:40 AM

Quote:

Originally Posted by xeon123 (Post 4324479)
By the way, not related to the post, it exists so many acronyms, that I simply don't understand all. The KISS acronym is new for me. And by the way, what nvm means?

nvm = never mind ;)
i posted something but it already been answered, and because i can't delete my post I edited to nvm ;)


All times are GMT -5. The time now is 01:50 PM.