[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Sheflug] Weird happenings with PERL script and cron
I've got a PERL script that runs on one of our servers which rebuilds our
LDAP database.
Basically, the job runs as root from CRON. When it runs under cron, the last
file ("/tmp/ldap-entries") gets missed off and not built in to the address
book (which is what we use LDAP for). If I run the job from command line,
the last file isn't included.
However, if I issue the last batch of "system" commands from command line,
everything appears as it should, implying that the /tmp/ldapbuild file is
correct.
So, the question is, why isn't the file included correctly? I would have
thought that by specifying fully qualified file names, there shouldn't be
any problems finding anything, and indeed, the ldap server is certainly
being restarted.
I'm not (in the nicest sense of the statement) expecting anyone to offer an
immediate answer (BICBW), but any ideas would be welcome.
(I've included the offending script below).
TIA,
**********************************
#!/usr/bin/perl -w
#
# This routine builds the base file for import into the LDAP database
# then imports the data.
#
# It includes a user in the alias fileif the user group is 100 or 103
#
# This version is designed to run on scooby, copying the required files
# from goofy using rcp before building the database
#
#
# Copy files from goofy...
#
system("rcp *************:/etc/passwd /tmp");
system("rcp *************:/home/monroeit/omusers.txt /tmp");
system("rcp *************:/var/qmail/alias/ldap-entries /tmp");
open(PASSWD, "/tmp/passwd") || die "Sorry - couldn't open /etc/passwd\n\n";
open(LDAP, ">/tmp/ldapbuild") || die "No alias\n\n";
open(MONROE, "/tmp/omusers.txt") || die "No Monroe input file\n\n";
open(LDE, "/tmp/ldap-entries") || die "No LDAP entries\n\n";
print LDAP "dn: c=UK\n";
print LDAP "c: UK\n";
print LDAP "objectclass: country\n";
print LDAP "\n";
print LDAP "dn: o=ALLVAC,c=UK\n";
print LDAP "o: ALLVAC\n";
print LDAP "c: UK\n";
print LDAP "objectclass: organization\n";
print LDAP "\n";
while (<PASSWD>)
{
@passwd = split(/:/, $_);
if ((($passwd[3] == 100) || ($passwd[3] == 103)) && (substr($passwd[4],0,1)
ne "#")) {
#
# put the basic data extracted from the passwd file into ldif format
#
($surname,$givenname,$department) = split(/ /,$passwd[4]);
$emailaddress = "$passwd[0]\@allvac.co.uk";
$distinctname = "$givenname $surname";
print LDAP "dn: cn=$distinctname,o=ALLVAC,c=UK\n";
print LDAP "cn: $distinctname\n";
print LDAP "display-name: $distinctname\n";
print LDAP "sn: $surname\n";
print LDAP "givenname: $givenname\n";
print LDAP "mail: $emailaddress\n";
if ($department eq "") {
$department = "?";
}
print LDAP "department: $department\n";
print LDAP "o: ALLVAC\n";
print LDAP "c: UK\n";
print LDAP "objectclass: person\n";
print LDAP "\n";
}
}
# now, process the Monroe file...
while (<MONROE>) {
($givenname,$surname,$junk) = split(",", $_);
$emailaddress = $givenname.".".$surname."\@allvac.com";
$distinctname = "$givenname $surname";
print LDAP "dn: cn=$distinctname,o=ALLVAC,c=UK\n";
print LDAP "cn: $distinctname\n";
print LDAP "display-name: $distinctname\n";
print LDAP "sn: $surname\n";
print LDAP "givenname: $givenname\n";
print LDAP "mail: $emailaddress\n";
print LDAP "o: ALLVAC\n";
print LDAP "c: UK\n";
print LDAP "objectclass: person\n";
print LDAP "\n";
}
# now the LDAP alias entries....
while(<LDE>) {
chomp $_;
($keyword,$part1,$part2,$email) = split(",", $_);
$distinctname = "$part1 $part2";
print LDAP "dn: cn=$keyword,o=ALLVAC,c=UK\n";
print LDAP "cn: $keyword\n";
print LDAP "display-name: $distinctname\n";
print LDAP "sn: $keyword\n";
print LDAP "givenname: $keyword\n";
print LDAP "mail: $email\n";
print LDAP "o: ALLVAC\n";
print LDAP "c: UK\n";
print LDAP "objectclass: person\n";
print LDAP "\n";
print "Included group $keyword\n";
}
# ...now the 'postamble' !
# ... kill the ldap server...
$slapdpid = `cat /var/run/slapd.pid`;
print "Killing slapd process# $slapdpid...\n";
system("kill $slapdpid");
# the 'sleep' may give the 'kill' enough time to work and
# let slapd shut down
sleep(20);
print "Deleting old database...\n";
system("rm /usr/ldap/*");
print "Creating new database...\n";
system("/usr/sbin/ldif2ldbm -i /tmp/ldapbuild -f /etc/openldap/slapd.conf -s
/usr/sbin");
print "Restarting slapd server...\n";
system("/usr/libexec/openldap/slapd -f /etc/openldap/slapd.conf");
print "All done\n";
**********************************
--
David Morris
IT Manager, ALLVAC Ltd, Sheffield, UK
work: david [at] allvac.co.uk (ICQ: 53264726) http://www.allvac.co.uk
home: david [at] brassedoff.net (ICQ: 52728733) http://www.davidm.demon.co.uk
---------------------------------------------------------------------
Sheffield Linux User's Group - http://www.sheflug.co.uk
To unsubscribe from this list send mail to
- <sheflug-request [at] vuw.ac.nz> - with the word
"unsubscribe" in the body of the message.
GNU the choice of a complete generation.