Example of a script to automatically bring Snapper up
Below is an example of a script to automatically bring Snapper up:
#!/usr/bin/perl## Survox Snapper failure script# This will check to see if a snapper process is running and will # attempt to bring one up if none is detected. Optionally an email # notification can be set up.# USAGE: snapcron.pl <email address of whom to notify (optional)># Set this up in a cron job to run every 5 or 10 minutes, e.g.:# # snapper failure notify# 05,15,25,35,45,55 * * * * csh -c "setenv CFMC (your normal CFMC env var); /cfmc/bin/snapcron.pl you@yourcompany.com"#####################################################require "/cfmc/cfg/cfmce761.pl";# Comment the line above and uncomment the lines below if running version 7.7# if ( -e "$ENV{CFMC}go/cfmcen77.pl") {# require "$ENV{CFMC}go/cfmcen77.pl";# } else {# die "ERROR: CFMC Environment Variable is set to: $ENV{CFMC}n $ENV{CFMC}go/cfmcen77.pl does not exist.n $0 requires this file in order to run.n We must quit.n";# }# &cfmcenv();# &whoami();$error = 0; # set error to 0 for no output if snapper already running, 1 will send email no matter what#####################################################open(STDERR,">&STDOUT");$usage = "$0 <opt:email address>";($email) = @ARGV;die "ERROR: USAGE $usagen" if ($email and index($email,"@")<0);# print "DEBUG: email:$email:n";<STDIN>;$logsnap = "${CFMC}super/log.snap";$message;@snapid1 = &findproc("snap$VERS","id");if ($#snapid1<0) {$message = "${message}WARNING: No snapper processes detected, we will attempt to start one upn";$error += 1;$logsnap = "${CFMCSUPER}log.snap";$mverr = rename("$logsnap","$logsnap.last") if ( -e "$logsnap");if ($mverr=0) { $message = "${message}ERROR: Cannot rename $logsnapnYou ($whoami) are probably the wrong user nWe must exitn"; $error += 1;} else {$snapper = "${CFMC}go/snap$VERS";if (! -x $snapper) {$subject = "CfMC Snapper not running and user '$whoami' cannot start it";$message = "${message}ERROR: $snapper either does not exist or is not executable by the user '$whoami'n";} else {$snapcom = "csh -cf "$snapper log con con ldev:batch >& $logsnap &"";$err = `$snapcom`;if ($?>0) {$subject = "CfMC Snapper cannot start";$message = "${message}ERROR: Cannot run snapper:n$errn";$error += 1;} else { # print "DEBUG: snaprun: $errn";<STDIN>;@snapid2 = &findproc("snap$VERS","id");if ($#snapid2<0) {$subject = "CfMC Snapper run has problems";$message = "${message}ERROR: Snapper runs without error but process cannot be found in process listingn"; $error += 1;} else {$subject = "CfMC Snapper was not running but now is running";$message = "${message}A new CfMC SnapShot program is now running as process #$snapid2[0]n";}}}}} else {$subject = "CfMC Snapper process running normally";$message = "${message}Snap$VERS process already running as process #$snapid1[0]n";}if ($error > 0) {if ($email) {&sendemail($subject,$message,$email);} else {print "$message";}} exit(0);#####################################################sub sendemail {$mail = "/bin/mail";($subj,$mess,$name) = @_; $err = `echo "$mess"