Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-15-2014, 03:41 PM   #1
LQ Newbie
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
How to exit shell script if remote login unsuccessful?

for servers in `cat ~/servers`
rosh -l root -n $servers 'if [ -d /opt/ca ]
exit 1
I am executing above script in opsware global shell. I have few servers in the for loop that is powered off, so whenever I execute my script, it works fine if all the servers are on, but when it tries to execute the script in the servers that are powered off, my script just hangs there. Please provide me with some hints. I am new to shell scripting. Thank you very much

Last edited by rsh015; 06-15-2014 at 03:57 PM.
Old 06-15-2014, 05:30 PM   #2
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 502
Blog Entries: 3

Rep: Reputation: 165Reputation: 165
You could use $?

if [[ $? != 0 ]] ; then
    echo "command failed!"
Each time you run a command, you can check $? for an exit status code.

Last edited by coralfang; 06-15-2014 at 05:31 PM.


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
Shell script using expect to login to couple of remote servers and read "crontab -l" jaipsharma Linux - Networking 3 03-16-2013 05:59 PM
Shell Script running in another shell script and then exit dreamervlk Linux - General 3 09-16-2011 07:40 AM
I am unable to exit my script that uses ssh to login to a remote server jtbinuya Linux - Newbie 2 06-12-2008 11:17 PM
shell script for remote ssh login sefaklc Programming 5 08-28-2007 10:03 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 03:34 PM > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration