LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 02: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 02:57 PM.
 
Old 06-15-2014, 04:30 PM   #2
coralfang
Member
 
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 836
Blog Entries: 3

Rep: Reputation: 297Reputation: 297Reputation: 297
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 04:31 PM.
 
  


Reply



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 04:59 PM
Shell Script running in another shell script and then exit dreamervlk Linux - General 3 09-16-2011 06: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 10:17 PM
shell script for remote ssh login sefaklc Programming 5 08-28-2007 09:03 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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