Cover V06, I01
Article
Figure 1
Listing 1

jan97.tar


Listing 1: Update system files

#!/usr/local/bin/perl
# This script will add the PC to the NIS+ hosts and netgroup table.
# Then it will added to the /etc/hosts.lpd file for printing.  The PC
# will then be added to the nameserver.
#
#
if ($#ARGV != 1 || $ARGV[1] !~ "60.60")
{
die("ERROR usage:n$0 pc_name ip_numbern");
}

($pc_name, $ip_number) = @ARGV;
$pc_name =~ tr/A-Z/a-z/;
print ("$pc_name $ip_numbern");

system "/usr/bin/echo Adding the PC $pc_name to server";
chdir("/usr/local/adm/pc_tmp");
`/usr/lib/nis/nisaddent -d hosts > hosts`;
open(hfile, 'hosts');
open(hfilen, '>hosts.new');
$hosts_upd = 1;
while(<hfile>)
{
if ($_ =~ /s$pc_names|$ip_numberD/)
{
if ($_ =~ "$ip_numbert$pc_name")
{
print hfilen "$_";
$hosts_upd = 0;
}
else
{
system "/usr/bin/echo The following entry is being replaced in
the NIS+ hosts file:";

system "/usr/bin/echo $_";
}
}
else
{
print hfilen "$_";
}
}

if ($hosts_upd)
{
print hfilen "$ip_numbert$pc_name ${pc_name}.domain.comn";
close hfile;
close hfilen;
system "/usr/bin/echo 'nUpdating NIS+ hosts table...'";
system "/usr/lib/nis/nisaddent -m -f hosts.new hosts";
}
else
{
close hfile;
close hfilen;
}

system "/usr/lib/nis/nisaddent -d netgroup > netgroup";
if (`/usr/bin/grep -c $pc_name netgroup` == 0)
{
open(nfile,'netgroup');
open(nfilen,'>netgroup.new');
while(<nfile>)
{
if ($_ =~ "^pcgroup")
{
chop($_);
print nfilen "$_ $pc_namen";
}
else
{
print nfilen;
}
}
print nfilen "$pc_namett(${pc_name},,domain.com)
(${pc_name}.domain.com,,domain.com)n";
system "/usr/bin/echo Updating the NIS+ netgroup table...";
close nfile;
close nfilen;
system "/usr/lib/nis/nisaddent -m -f netgroup.new netgroup";
}


if (`/usr/bin/grep -c $pc_name /etc/hosts.lpd` == 0)
{
system "/usr/bin/echo 'nAdding $pc_name to /etc/hosts.lpd file for
printing.'";
system "/usr/bin/echo $pc_name >> /etc/hosts.lpd";
}

system "/usr/bin/echo 'nAdding $pc_name to the nameserver...'";
system "/opt/local/adm/bin/nsupdate.pc ${pc_name}.domain $ip_number";
print "nn";
`/bin/rm -f /opt/local/adm/pc_tmp/*`;
if (`niscat hosts.org_dir | /usr/bin/grep -c "$pc_name $ip_number"` == 0)
{
print ("nnError!!!n");
print ("The PC $pc_name was NOT found in the NIS+ hosts table.n");
exit 0;
}
if (`niscat netgroup.org_dir | /usr/bin/grep -c "$pc_name"` == 0)
{
print ("nnError!!!n");
print ("The PC $pc_name was NOT found in the NIS+ netgroup
table.n");
exit 0;
}
if (`/usr/bin/grep -c "$pc_name" /etc/hosts.lpd` == 0)
{
print ("nnError!!!n");
print ("The PC $pc_name was NOT found in the /etc/hosts.lpd
table.n");
exit 0;
}
system "/usr/bin/echo 'nThe PC $pc_name with the IP address $ip_number
has been successfully added.'";

exit 0;

# End of File