This script will give an overview on all changes
against VMTEL.txt-file of previous day.
#
vmtelcomp.pl
# author: Stefan Joris, Synstar
# created May 8, 2003
# last reviewed May 15, 2003
# version 1.0a
#
# compares input user files and writes changes to text file and
html file
#
# example output:
#
# Added users:
# 0444 JBETON 1000 ANT 5555
BETON
(FEI)Jan
# Deleted users:
# 0276 BARBIN 0067 067 3029
BARBIN
(FEI)Wilma
# 0223 AMENDOLA 1899 AMT 3029
AMENDOLA (FEI)Tony
# Modified telephone numbers:
# 9223 RODE 0082 082 3029
RODE
(FEI)Stephanie
# Modified users:
# 1609 VAZQUEZ 6572 A72 4123 VAZQUEZ
(OP) Maria Jesus Alaaf!
#
use File::Copy;
#define global vars
$oldusersfile="vmtel_old.txt";
$newusersfile="vmtel_new.txt";
$outfile="vmtelcomp.txt";
$outfilehtm="vmtelcomp.htm";
#read source files in memory
open(VMNEW,$newusersfile) or die "cannot open $newusersfile";
open(VMOLD,$oldusersfile) or die "cannot open $oldusersfile";
foreach(readline(VMNEW))
{chomp;
$key=substr($_,5,8);
$tel=substr($_,0,4);
$vmnew{$key}=$_;
$vmnewtels{$key}=$tel;}
foreach(readline(VMOLD))
{chomp;
$key=substr($_,5,8);
$tel=substr($_,0,4);
$vmold{$key}=$_;
$vmoldtels{$key}=$tel;}
close(VMNEW);
close(VMOLD);
#find deleted users
foreach $key (keys(%vmoldtels))
{push (@deletedtels, $vmold{$key}) unless
exists($vmnew{$key});
}
#find new users, modified telnrs and modified users
foreach $key (keys(%vmnewtels))
{if (exists($vmold{$key}))
{next if ($vmold{$key} eq
$vmnew{$key});
push (@modifiedtels,
$vmnew{$key}) if ($vmoldtels{$key} ne
$vmnewtels{$key});
push (@modifiedusers, $vmnew{$key})
if (($vmold{$key} ne $vmnew{$key})
&& ($vmoldtels{$key} eq $vmnewtels{$key}));
}
else
{push (@addedtels, $vmnew{$key})
}
}
#write output to txt file
open(OUTFILE,">$outfile");
print OUTFILE "Added users:\n";
foreach(@addedtels) {print OUTFILE "$_\n";}
print OUTFILE "Deleted users:\n";
foreach(@deletedtels) {print OUTFILE "$_\n";}
print OUTFILE "Modified telephone numbers:\n";
foreach(@modifiedtels) {print OUTFILE "$_\n";}
print OUTFILE "Modified users:\n";
foreach(@modifiedusers) {print OUTFILE "$_\n";}
close(OUTFILE);
#write output to htm file
#html header
open(OUTHTM,">$outfilehtm");
print OUTHTM "<HTML>\n<BODY
bgcolor=\"#9cc2e4\"><font face=\"verdana\">\n";
#top table (title)
print OUTHTM "<table width=\"702\" cellpadding=\"1\"
cellspacing=\"0\" bgcolor=\"#3F2DFF\">\n";
print OUTHTM "<tr><td>\n";
print OUTHTM "<table width=\"700\" cellspacing=\"1\"
bgcolor=\"#D4D4FA\">\n";
print OUTHTM "<tr>\n";
print OUTHTM "<td align=\"left\" valign=\"top\"><font
size=\"-2\"><a
href=\"http://lofty\">home</a></td>\n";
print OUTHTM "<td align=\"center\"><strong><font
color=\"#0000ED\" size=\"-1\">TNG Unicenter Service
Desk</font></BR>\n";
print OUTHTM "<font size=\"-2\" color=\"#7575FF\">B.E.I.
Implementation by
Synstar</font></strong></td>\n";
print OUTHTM "<td align=\"right\" valign=\"top\"><font
size=\"-2\"><a href =
\"javascript:history.back()\">back</a></td>\n";
print OUTHTM "</tr>\n";
print OUTHTM
"</table></td></tr></table>\n";
#content table (header)
print OUTHTM "<table width=\"702\" cellpadding=\"1\"
cellspacing=\"0\" bgcolor=\"#3F2DFF\">\n";
print OUTHTM "<tr><td>\n";
print OUTHTM "<table width=\"700\" cellspacing=\"1\"
bgcolor=\"#35A3D1\">\n";
print OUTHTM "<tr><td align=\"center\" bgcolor=\"#7EBEE4\"
colspan=\"4\"><strong><font size=\"- 1\">ADDED
USERS</font></strong></td></tr>\n";
print OUTHTM "<tr bgcolor=\"#7EBEE4\">\n";
print OUTHTM "<td><font
size=\"-1\"><strong>Public
Phone</strong></font></td>\n";
print OUTHTM "<td><font
size=\"-1\"><strong>UserId</strong></font></td>\n";
print OUTHTM "<td><font size=\"-1\"><strong>First
Name</strong></font></td>\n";
print OUTHTM "<td><font size=\"-1\"><strong>Last
name</strong></font></td>\n";
print OUTHTM "</tr>\n";
#detail lines
foreach(@addedtels)
{
$kol1=substr($_,0,4);
$kol2=substr($_,5,8);
$kol6=substr($_,28,20);
$kol7=substr($_,48);
print OUTHTM "
<tr>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol1</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol2</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol7</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol6</font></td>\n";
print OUTHTM "
</tr>\n";
}
print OUTHTM
"<tr><td> </td></tr>";
print OUTHTM " <tr><td align=\"center\"
bgcolor=\"#7EBEE4\" colspan=\"4\"><strong><font
size=\"-1\">DELETED
USERS</font></strong></td></tr>\n";
print OUTHTM " <tr
bgcolor=\"#7EBEE4\">\n";
print OUTHTM " <td><font
size=\"-1\"><strong>Public
Phone</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>UserId</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>First
Name</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>Last
name</strong></font></td>\n";
print OUTHTM " </tr>\n";
foreach(@deletedtels)
{
my $kol1=substr($_,0,4);
my $kol2=substr($_,5,8);
my $kol3=substr($_,14,4);
my $kol4=substr($_,19,3);
my $kol5=substr($_,23,4);
my $kol6=substr($_,28,15);
my $kol7=substr($_,43);
print OUTHTM "
<tr>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol1</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol2</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol7</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol6</font></td>\n";
print OUTHTM "
</tr>\n";
}
print OUTHTM
"<tr><td> </td></tr>";
print OUTHTM " <tr><td align=\"center\"
bgcolor=\"#7EBEE4\" colspan=\"4\"><strong><font
size=\"-1\">MODIFIED TELEPHONE
NUMBERS</font></strong></td></tr>\n";
print OUTHTM " <tr
bgcolor=\"#7EBEE4\">\n";
print OUTHTM " <td><font
size=\"-1\"><strong>Public
Phone</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>UserId</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>First
Name</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>Last
name</strong></font></td>\n";
print OUTHTM " </tr>\n";
foreach(@modifiedtels)
{
$kol1=substr($_,0,4);
$kol2=substr($_,5,8);
$kol6=substr($_,28,20);
$kol7=substr($_,48);
print OUTHTM "
<tr>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol1</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol2</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol7</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol6</font></td>\n";
print OUTHTM "
</tr>\n";
}
print OUTHTM
"<tr><td> </td></tr>";
print OUTHTM " <tr><td align=\"center\"
bgcolor=\"#7EBEE4\" colspan=\"4\"><strong><font
size=\"-1\">MODIFIED
USERS</font></strong></td></tr>\n";
print OUTHTM " <tr
bgcolor=\"#7EBEE4\">\n";
print OUTHTM " <td><font
size=\"-1\"><strong>Public
Phone</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>UserId</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>First
Name</strong></font></td>\n";
print OUTHTM " <td><font
size=\"-1\"><strong>Last
name</strong></font></td>\n";
print OUTHTM " </tr>\n";
foreach(@modifiedusers)
{
$kol1=substr($_,0,4);
$kol2=substr($_,5,8);
$kol6=substr($_,28,20);
$kol7=substr($_,48);
print OUTHTM "
<tr>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol1</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol2</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol7</font></td>\n";
print OUTHTM "
<td><font
size=\"-1\">$kol6</font></td>\n";
print OUTHTM "
</tr>\n";
}
print OUTHTM
"<tr><td> </td></tr>";
print OUTHTM "</table>\n";
print OUTHTM "</td></tr>\n";
print OUTHTM "</table>\n";
#bottom table (BACK button)
print OUTHTM "<table width=\"702\" cellpadding=\"1\"
cellspacing=\"0\" bgcolor=\"#3F2DFF\">\n";
print OUTHTM "<tr><td>\n";
print OUTHTM "<table width=\"700\" cellspacing=\"1\"
bgcolor=\"#D4D4FA\">\n";
print OUTHTM "<tr>\n";
print OUTHTM "<td><strong><font size=\"-1\"><a
href = \"javascript:history.back()\">Go
back</a></font></strong></td>\n";
print OUTHTM "<td align=\"right\"><strong><font
size=\"-1\"><a href = \"http://lofty/users/log/\">Go to
LOG
folder</a></font></strong></td>\n";
print OUTHTM "</tr>\n";
print OUTHTM
"</table>\n</tr></td>\n</table>\n";
#close HTML
print OUTHTM "</font></BODY>\n</HTML>\n";
close(OUTHTM);
#copy OUTHTM to logfile
@date = localtime();
$mday=$date[3];
$mon=$date[4];
$outfilehtmlog=sprintf("logvm%02d%02d.htm",++$mon,$mday);
copy ($outfilehtm, $outfilehtmlog);
#display info on screen
#print "Added users:\n";
#foreach(@addedtels) {print "$_\n";}
#print "Deleted users:\n";
#foreach(@deletedtels) {print "$_\n";}
#print "Modified telephone numbers:\n";
#foreach(@modifiedtels) {print "$_\n";}
#print "Modified users:\n";
#foreach(@modifiedusers) {print "$_\n”;}
#
Written by Daniel Paessens (Synstar Coe)
#
version: 0.1
# Filename: vmcomp.sh
# File location: /opt/script
cd /opt/script/VMComp
cp -f /opt/script/VMTEL.TXT /opt/script/VMComp/vmtel_new.txt
perl /opt/script/VMComp/vmtelcomp.pl
cp -f /opt/script/VMComp/vmtelcomp.htm
/var/www/html/users/vmtelcomp.htm
cp -f /opt/script/VMComp/vmtel_new.txt
/opt/script/VMComp/vmtel_old.txt
cp -f /opt/script/VMComp/logvm*.htm
/var/www/html/users/log/logvm*.htm
rm /opt/script/VMComp/logvm*.htm –f