#!/usr/local/bin/perl require "/root/scripts/utils.pl"; ####################################### $remote_ip = "128.59.172.6"; $local_name = "My"; $remote_name = "Your"; $is_nfs_client = 1; $from_email = "dl105\@columbia.edu"; ####################################### # list of recipients to get the alerts via email $recipient{"systems"} = "systems\@claven.gsb.columbia.edu"; $recipient{"systems-cell"} = "systems-cell\@claven.gsb.columbia.edu"; $recipient{"web-alerts"} = "web-alerts\@claven.gsb.columbia.edu"; $recipient{"web-cell"} = "web-cell\@claven.gsb.columbia.edu"; $iface = "hme0:2"; $ping = "/usr/sbin/ping"; # time in seconds to wait for ping reply $timeout = 5; $up_str = "alive"; $command = "$ping $remote_ip $timeout"; $out = `$command`; if ($out =~ $up_str){ print "*$remote_name* is up!\n"; } # the remote machine is down! else { print "*$remote_name* is down!\n"; # if this machine's courseware 'library' points to the library on # the remote machine, thus being a NFS client, the script should # first remove the 'library' symbolic link that's pointing to # the remote machine via NFS, since it's no longer available. # Then, it should re-create the 'library' symbolic link and point # it to the local copy, which is synchronized to the remote copy # every 10 minutes. if ($is_nfs_client == 1){ # remove link to NFS-mounted 'library' $command = "rm -f /export/home/apache/library"; print "Command: *$command*\n"; $out = `$command`; # point 'library' to a local rsynced copy 'library2' $command = "ln -s /export/home/apache/library2 /export/home/apache/library"; print "Command: *$command*\n"; $out = `$command`; } # send out email alerts $time_string = `date`; @times = split(/[ ]+/, $time_string); $time = $times[3]; $time .= ", "; $time .= $times[1]; $time .= " "; $time .= $times[2]; $subject = "*$local_name* took over *$remote_name*"; $body .= "*$local_name* has taken over *$remote_name* at $time\n"; foreach $dest (sort(keys %recipient)){ print "Sending to $recipient{$dest} ...\n"; &sendmail($from_email, $recipient{$dest}, $subject, $body); } # take over the remote machine $command = "/sbin/ifconfig $iface $remote_ip netmask 255.255.255.0 up"; print "Command: *$command*\n"; $out = `$command`; } exit 0;