LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-14-2011, 06:48 AM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
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?
 
Old 04-14-2011, 07:40 AM   #2
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

Rep: Reputation: 115Reputation: 115
KISS.

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

Last edited by zordrak; 04-14-2011 at 07:41 AM. Reason: link
 
Old 04-14-2011, 07:53 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Why is it not possible to put both commands in a single script?
 
Old 04-14-2011, 08:02 AM   #4
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
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?
 
Old 04-14-2011, 09:19 AM   #5
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
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.
 
Old 04-14-2011, 09:22 AM   #6
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

Rep: Reputation: 115Reputation: 115
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.
 
Old 04-14-2011, 09:23 AM   #7
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
nvm
 
Old 04-14-2011, 09:30 AM   #8
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
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.

Last edited by xeon123; 04-14-2011 at 09:33 AM.
 
Old 04-14-2011, 09:32 AM   #9
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
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?
 
Old 04-14-2011, 09:40 AM   #10
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
Quote:
Originally Posted by xeon123 View Post
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
 
  


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
Invoking remote commands from ssh hamtavs Linux - Software 5 06-27-2009 09:03 AM
ssh remote commands dcfnef Linux - Security 1 11-15-2007 12:39 PM
ssh running remote commands Nikee Linux - Security 5 02-04-2006 04:00 AM
execute multiple ssh remote commands tom221 Linux - Newbie 2 01-28-2005 02:00 PM
remote ssh commands on multiple hosts evilchild Linux - Software 6 08-12-2004 11:48 PM


All times are GMT -5. The time now is 03:44 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration