Category: | Utility Scripts |
Author/Contact Info | penguinfuz at gmail dot com |
Description: | I wrote this script to address an issue I had with Apache authentication and multiple load-balanced web servers, and I run it from a cronjob every so often. Basically I keep ONE copy of the relevent .htaccess files and NFS export their location to the other web servers in the cluster. I am sure this script could be extended further, but I have not messed with it since it serves the basic purpose I started towards. I hope someone else will find this code useful as well. ;) UPDATE: Added "use strict;" and found a missing semicolon at: my $ip_add = "192.168.0.10" And a global @mntargs; hanging around. |
#! /usr/bin/perl -w use strict; my $thisdir = "/path/to/thisdir"; my $thatdir = "/path/to/thatdir"; my $ip_add = "192.168.0.10"; my @mntargs; if (!(-d "$thisdir")) { @mntargs = ("/bin/mount", "${ip_add}:$thisdir", "$thisdir"); print "Mounting ${ip_add} for CC-Proc1 .htpasswd access...\n"; system (@mntargs); if (!(-d "$thisdir")) { email_error(${ip_add}); } } if (!(-d "$thatdir")) { @mntargs = ("/bin/mount", "${ip_add}:$thatdir", "$thatdir"); print "Mounting ${ip_add} for CC-Proc2 .htpasswd access...\n"; system (@mntargs); if (!(-d "$thatdir")) { email_error(${ip_add}); } } sub email_error { my $ip_add = shift; my $hostname = `/bin/hostname`; open(SENDMAIL, "|/usr/lib/sendmail -oi -t") or die "Cannot fork for sendmail: $!\n"; print SENDMAIL <<EOF; From: NFS Watcher <root\@${hostname}> To: System Admin <penguinfuz\@anotherdomain.dom> Subject: Something is broken with the NFS mount! This email is generated by the NFS Watcher script on $hostname... I noticed the NFS export from ${ip_add} was NOT mounted, but whenever I tried mounting it, something didn't work. Remember, until the NFS export from ${ip_add} is properly mounted, the .htpasswd authentication will not work %100! EOF close(SENDMAIL) or warn "Oops, sendmail did not close nicely\n"; } |
|
---|
Back to
Code Catacombs