LinuxQuestions.org
Visit Jeremy's Blog.
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 06-15-2014, 03:41 PM   #1
rsh015
LQ Newbie
 
Registered: Jun 2014
Posts: 1

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


Code:
#!/bin/bash
for servers in `cat ~/servers`
do
rosh -l root -n $servers 'if [ -d /opt/ca ]
then
echo $HOSTNAME
else
exit 1
fi'
done
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
coralfang
Member
 
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 391
Blog Entries: 2

Rep: Reputation: 96
You could use $?

Code:
if [[ $? != 0 ]] ; then
    echo "command failed!"
fi
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.
 
  


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
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


All times are GMT -5. The time now is 06:13 AM.

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