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
# 1  
Old 08-08-2009
FNG Question: Test if remote server has booted

Hello again, I have a script on my media server that wakes up my backup server, performs an 'rsync' backup, then shuts the backup server down. Currently, I have it send the Wake on LAN packet, and sleep for 5 minutes, just to give the backup server time to boot (of course it doesn't take that long, but just in case...). It occurred to me today that that isn't always going to cut it, in the sense that after so many days, the filesystem gets run through fsck (which takes a bit of time on these monster drives).
So, the question... Is it possible to include in a script, maybe a ping mechanism that can be run, then based on the results, determine if the remote server is booted or not? I did some reading on 'ping' (remember, I did use FNG in the title Smilie ) and the man page made a mention of using ping's exit status to determine if a server was up or not, but I honestly am not clear on exactly how I would implement that (i.e. if I used:

if [ ping remotehost ]
then blahblah
else blahblahblah
fi

would that necessarily be looking for the exit code 0 (successful), or am I just way out there? The example above seems to be missing something, but... Thanks again, you guys/girls are a great help!
# 2  
Old 08-08-2009
Code:
ping -c 1 SERVER > /dev/null 2>&1
if [ $? -ne 0 ]
then
  # bail out
fi
# do the job

# 3  
Old 08-08-2009
I used the bellow to check the remote server is up and accepting remote login ( here i checked if telnet port is open or not.

Code:
MACHINE=8.8.3.200 # Change to what ever you need
exec 3>/dev/tcp/${MACHINE}/23
if [ $? -eq 0 ]
then
    echo "Server is up Telnet accepting connections"
else
    echo "Telnet connections not possible"
fi

# 4  
Old 08-09-2009
Quote:
Originally Posted by dr.house
Code:
ping -c 1 SERVER > /dev/null 2>&1
if [ $? -ne 0 ]
then
  # bail out
fi
# do the job

Dr. House is at it again! Thanks for the example, once again. It appears I have more reading to do though, as there re some bits that I don't understand. The '2>&1'... that sends stderr to the same spot as stdout, right? In this case, /dev/null... But I am foggy about the '$?'. I havent used that one before...

---------- Post updated at 10:40 AM ---------- Previous update was at 10:38 AM ----------

Quote:
Originally Posted by amitranjansahu
I used the bellow to check the remote server is up and accepting remote login ( here i checked if telnet port is open or not.

Code:
MACHINE=8.8.3.200 # Change to what ever you need
exec 3>/dev/tcp/${MACHINE}/23
if [ $? -eq 0 ]
then
    echo "Server is up Telnet accepting connections"
else
    echo "Telnet connections not possible"
fi

Thank you very much for that example as well! It looks like I have two options, one to see if the machine is up, and one to check if the service itself is up. Thanks again!
# 5  
Old 08-09-2009
Quote:
Originally Posted by vwgtiturbo
The '2>&1'...
... is merely a "geek's quicky", meant to keep the shell clean, but completely irrelevant to the task at hand (- see this page for details).

Quote:
Originally Posted by vwgtiturbo
[...]the '$?'


... is meant to inform you about success or failure of the preceeding command, i.e. your pinging of a server (- see this page for details).
# 6  
Old 08-10-2009
Is it possible to incorporate this into a while loop, so that it would ping every 5 seconds or so, and if '$?' is -ne to 0, keep pinging until $?= 0 (then once it does equal 0, continue with the script)? I came up with one sample, but of course, it didn't do anything, but give me a nice error Smilie
# 7  
Old 08-11-2009
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

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