Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

NFS Watcher

by penguinfuz (Pilgrim)
on May 16, 2002 at 13:13 UTC ( #167001=sourcecode: print w/ replies, xml ) Need Help??

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";
}

Comment on NFS Watcher
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://167001]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (13)
As of 2014-10-21 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (103 votes), past polls