LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2018, 07:11 AM   #1
nareshreddyn
LQ Newbie
 
Registered: Sep 2017
Posts: 10

Rep: Reputation: Disabled
Bash script unable to exit from shell after executing over SSH


Bash script unable to exit from shell after executing over SSH.Need to manually enter CTRL+C to exit.

Tried placing /dev/null 2>&1 & in the script which is working fine.But i need to write the ouput to LOGFILE.

Please help

Code:
ssh ${appUsr}@${adminHost} "cd $svrscript; ls -ltr; ./startup_WL.sh start" >> ${LOG_FILE}
 
Old 09-11-2018, 07:15 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
did you try using just the ampersand, & to put it into the background?
Code:
.....  ./startup_WL.sh start" >> ${LOG_FILE} &
something like that?
 
Old 09-11-2018, 07:24 AM   #3
nareshreddyn
LQ Newbie
 
Registered: Sep 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Yes.. That will work but the next commands on local script are executed without the completion of SSH execute command. I want to execute the next lines of script on my localhost once the ssh script is executed.

After starting all the servers on remote host, i will capture the status of each server in LOGFILE. If i place &, i am unable to get the status.


Code:
echo  "#####################################"
echo  "Starting All Servers" >> ${LOG_FILE}
echo  "#####################################"
ssh  ${appUsr}@${adminHost} "cd $svrscript; ls -ltr; ./startup_WL.sh start" >> ${LOG_FILE}

sleep 10;

echo "Servers are Starting.Please wait" >> ${LOG_FILE}

echo "################################"
echo " Server Status " >> ${LOG_FILE}
echo "################################"
ssh ${appUsr}@${adminHost} "cd $svrscript; ls -ltr; ./startup_WL.sh status" >> ${LOG_FILE}

Last edited by nareshreddyn; 09-11-2018 at 07:33 AM.
 
Old 09-11-2018, 07:27 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Remove the -f from that line because it sends the SSH client into the background just before command excution. So the client stays in the background and does not return. See "man ssh" for details.
 
Old 09-11-2018, 07:33 AM   #5
nareshreddyn
LQ Newbie
 
Registered: Sep 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Sorry there is no f option.I just gave a try to check.Thanks for the finding
 
Old 09-11-2018, 07:36 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
What happens when you run "./startup_WL.sh status" by itself manually? Does it even exit? If it fails to exit, then the SSH client won't exit either when it runs it.
 
Old 09-11-2018, 07:43 AM   #7
nareshreddyn
LQ Newbie
 
Registered: Sep 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Yes. I am able to exit when i run it manually or over SSH for "./startup_WL.sh status"

For "./startup_WL.sh start" manually its working but over SSH able to exit from the script but not from the shell and return back to local host.

Last edited by nareshreddyn; 09-11-2018 at 07:45 AM.
 
Old 09-11-2018, 07:55 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,792

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
so probably you need to fix that shell script. try ssh -t
 
1 members found this post helpful.
Old 09-11-2018, 09:25 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Guess the starting script might write some lines to the original standard output/error, before redirecting them to files,
and you want to save those lines.

Perhaps something like this:
Code:
ssh -t user@host 'trap "" HUP; /path/startbatch.sh & sleep 10' >>/path/remotestart.log

Last edited by NevemTeve; 09-11-2018 at 12:23 PM.
 
1 members found this post helpful.
  


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
[Bash script] Executing commands in the current shell, while not launching subshells Longeron Linux - Newbie 10 01-27-2013 07:55 PM
[SOLVED] Bash Shell Script Exit Codes metallica1973 Programming 4 01-25-2012 11:14 AM
I am unable to exit my script that uses ssh to login to a remote server jtbinuya Linux - Newbie 2 06-12-2008 10:17 PM
Hi, I am a complete n00b in need of help executing her bash shell script. savoirefaire Linux - Newbie 4 03-12-2007 06:14 AM
what is the script which runs at the exit bash shell supersubu123 Linux - General 6 01-24-2007 12:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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