Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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";
}
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://167001]
help
Chatterbox?
[holli]: it's probably the autist in you. I am like that too, no fucks given about what others think about me
james28909 checks, yep... htere are no fucks to give
[james28909]: another thing i am sick of is hurting others feelings
[1nickt]: james28909 You lost me a bit when you said "show me evolution from intelligence to ignorance". I guess we would have to define the terms, but as I look around at my species and how we are destroying our habitat ...
[james28909]: seems like a person cant even have a belief without hurting someones feelings. i never said my way is the only way. i just said i have pretty good scientific evidence, and then asked for opposing side to present evidence
[james28909]: was downvoted and left without a reply. go figure
[holli]: but then you DO give a fuck
[1nickt]: I don;t think beliefs should be down-voted, just behaviours.
[james28909]: im not quite how to explain it any better nick. you evolved from ignorance to intelligence. not the other way. the universe evolves from gas coulds and debris into planets stars and galaxies ect. it doesnt happen any other way. hence it has ....
[james28909]: some kind of logic behind it

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (13)
As of 2017-12-15 14:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (433 votes). Check out past polls.

    Notices?