[ale] Need a bit of help with bash.

Chuck Peters cp at axs.org
Thu Feb 10 19:18:03 EST 2011


On Thu, Feb 10, 2011 at 1:20 PM, Chuck Payne <terrorpup at gmail.com> wrote:

> Guys,
>
> I have a script that does a wget, but if a server is not responing,
> the the script deads. What is the best way to say if host x doesn't
> return a value after 10 sec to stop.  I seen several example of
> timeout function, but it looks I need to write a pid is that true?
>

This uses fping, I used it to backup machines on the lan which aren't on all
the time.

$ cat /tmp/ptest.sh
#!/bin/bash
#HOSTS="xp darwin"
HOSTS="xp u2"
for h in $HOSTS
do
  fping -u $h >& /dev/null
  if [ $? -ne 0 ]; then
          echo ${h} host is down
          #echo ${h} host is down send email `date` >>
/var/log/backup-hosts.log
          # mail -s "Host ${h} down" admin at example.com
else
          echo $h is up
          #echo  ${h} host backup run `date` >> /var/log/backup-hosts.log
          #/usr/local/sbin/backup-$h-to-u2.sh
  fi
done

$ bash /tmp/ptest.sh
xp host is down
u2 is up


I changed the way I do the backups, and I am still looking into how I will
redo the backups for the windows machines.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20110210/a6c08271/attachment.html 


More information about the Ale mailing list