FNG Question: Test if remote server has booted


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FNG Question: Test if remote server has booted
# 8  
Old 08-12-2009
Thanks for that! I didn't have the [ true ] portion in my mock up (which may explain why I never got it to work...). I like reading your responses; I always learn something. Thanks again, and I'll try not to be a burden for a while!
# 9  
Old 08-12-2009
Word of warning...

Your server may respond to a ping request during the fsck - the network interface is initialized before advancing to the multi-user run level. You may find that the network interface may respond to ICMP echo requests, yet still be in single-user mode. (Your mileage may vary)

One way to test if multi-user services are up, is to attempt to telnet to port 22 (the ssh port). If the service is up, you should see something like:

Code:
root(me)@myhost2# telnet myhost1 22
Trying 192.168.1.101...
Connected to myhost1.
Escape character is '^]'.
SSH-2.0-Sun_SSH_1.1

If the service is not yet up, you should see something like:
Code:
root(me)@myhost2# telnet myhost1 22
Trying 192.168.1.101...
telnet: Unable to connect to remote host: Connection refused

- Avron
# 10  
Old 08-13-2009
Veeeery interesting... Thanks for that Avron. If that is the case, it would really defeat the whole purpose of this check. For the longest time, my basic script simply waited (via 'sleep') for a set time (that I measured for how long the server would take to boot). Howeve during
the first 'fsck', that time was no longer applicable and the script errored out. I appreciate the insight, as it may very well have errored out still. I'll do some testing and see what exact messages are kicked back when the service is ready or not and search stdout for those messages, basing the scripts behavior on those results. Thanks again!

---------- Post updated at 09:12 PM ---------- Previous update was at 07:28 AM ----------

Quote:
Originally Posted by dr.house
Code:
#! /bin/bash

while [ true ]
do
  ping -c 1 $SERVER > /dev/null 2>&1
  if [ $? -eq 0 ]
  then
    echo "ping"
    exit
  else
    echo "pong"
    sleep 5
  fi
done

exit 0

Hello there, I tried the above and am wondering if I am missing something... While the server is booting, the script does as it should, and echoes 'pong' until the server answers back. The problem is that as soon as the server answers back, the 'exit' quits the script, not the just the loop. I am assuming that there must be some way to continue with the script after this loop, but... Of course, being an experimenter, I removed the 'exit', and it simply echoed 'ping' thousands of times after the server came up. Will I need to have the 'echo "ping"' dump to a file, then have the backup script search that file every few seconds, looking for the "ping"? I know there is probably a more elegant way to do it, but whatever works...

---------- Post updated at 09:40 PM ---------- Previous update was at 09:12 PM ----------

Quote:
Originally Posted by dr.house
Code:
#! /bin/bash

while [ true ]
do
  ping -c 1 $SERVER > /dev/null 2>&1
  if [ $? -eq 0 ]
  then
    echo "ping"
    break
  else
    echo "pong"
    sleep 5
  fi
done

exit 0

WOOHOO! I got it to work by putting a 'break' in place of the 'exit'. I guess I just hadn't read enough when I posted my last query. Thanks for the help!

** CLARIFICATION **
Just to clarify... the above code was entered into my script (I wasn't using it as a stand-alone script). So, I have a section of the script that runs Ether-wake to send a magic packet to the server, then the above loop to wait for the server to be available. After this loop finishes with a successful ping, the script continues with rsync and encryption. Good times...

Last edited by vwgtiturbo; 08-13-2009 at 01:44 AM.. Reason: Clarification
# 11  
Old 08-13-2009
Quote:
Originally Posted by vwgtiturbo
I know there is probably a more elegant way to do it, but whatever works ...
My way (not made explicit - sorry for that):

Code:
#! /bin/bash

function doTheRealWork
{
  # whatever ;-)
}

while [ true ]
do
  ping -c 1 $SERVER
  if [ $? -eq 0 ]
  then
    doTheRealWork
    exit 0
  else
    sleep 5 # wait
  fi
done

exit 0

# 12  
Old 08-13-2009
I haven't messed with functions at all. I like that example though. It looks like I have more reading to do... As I stated earlier, I always learn something from your replies Smilie Thanks again for lending your experience!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

2. UNIX for Beginners Questions & Answers

How to test if remote dir exist?

Hello, :) I'm trying to test if a remote directory exist per ssh, I have already made a ssh key and it works : #!/bin/bash HOST="10.10.1.22" FILE_PATH="/var/wwww/html" ssh -q $HOST ] && echo "Directory exists" || echo "Directory does not exist"; Output : ... (4 Replies)
Discussion started by: Arnaudh78
4 Replies

3. Shell Programming and Scripting

Sudo connect to a remote server and execute scripts in remote server

Hello Every one!! I am trying to write a shell script which will connect to a remote server and execute scripts which are at a certain path in the remote server. Before this I am using a sudo command to change the user. The place where I am stuck is, I am able to connect to the... (6 Replies)
Discussion started by: masubram
6 Replies

4. Shell Programming and Scripting

Test if Remote server is up and running before SFTP'ing files (in batch mode)

Hello, In our Data Warehouse environment, before our batch SFTP jobs kick off to pull the files from remote servers, I would like to setup a pre-sftp job that would test if all the remote servers from where the files are being pulled, are up and running. If any one of the remote serer is... (2 Replies)
Discussion started by: Dippu
2 Replies

5. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

6. Programming

SFTP from one remote server to another remote server from desktop

Hi, I have 1. lappy 2. server A 3. server B Now, what i need is to run a command from lappy that will sftp a file from server A to server B. Please guide me to achieve this. -akash (1 Reply)
Discussion started by: akash.mahakode
1 Replies

7. Shell Programming and Scripting

preserving the timestamp of a file when copied from remote server to local server using ftp

Hi, I need to copy few files from remote server to local server. I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed. ... (5 Replies)
Discussion started by: arunkumarmc
5 Replies

8. UNIX for Advanced & Expert Users

execute a script on test server from dev server

I need to execute a script from dev server which is located on Test server.I can use ftp to connect to dev server and from there how can i execute a command on test server. Thanks (5 Replies)
Discussion started by: ukatru
5 Replies

9. Shell Programming and Scripting

Rsh: test $? on remote system.

Hi, a little help. I need to test the return code of a list file command on a remote system (Unix) using the rsh command. More exactly, to test is a directory exists, I try the following command: rsh $remoteHost "ls -la " $DirRemote Now, if the $DirRemote is not correct and I test... (3 Replies)
Discussion started by: gio123bg
3 Replies
Login or Register to Ask a Question