Some perl scripts I have written...

Lists network servers running unix

#!/usr/bin/perl
use strict($line, @split_line, @unix_server_list, $unix_server_list, $split_line, $server_by_os, %server_by_os, $server, $server_by_os);
###################################################
################## housekeeping ###################
my($holder);
$holder="";
#
# prep and test file line10
open (RAW_LIST, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/raw_list.txt") ||
      die "cannot open unix_server_list.txt\n";
close(RAW_LIST) || die "cannot close file\n";
#
# prep and test file
open (UNIX_LIST, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_server_list.txt") ||
      die "cannot open unix_server_list.txt\n";
close(UNIX_LIST) || die "cannot close file\n";
#
# prep and test file line 20
open (OS_LIST, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_os_list.txt") ||
      die "cannot open unix_os_list.txt\n";
close(OS_LIST) || die "cannot close file\n";
#
############### end of housekeeping ###############
#################################################
#
# open the master list of servers for reading
open (RAW_LIST, ">>/usr/local/scripts/cust_file_bkp_dir/data_file_dir/raw_list.txt");
open (GET_LIST, "rsh cidcsweb03 cat /usr/local/apache/htdocs/flatdbase/newserver.txt | awk '/UNIX/{print $1 }' |");
while () { # line31
      print RAW_LIST; }
close(GET_LIST);
close(RAW_LIST);
#
# generate the arrays
open (RAW_LIST, "/usr/local/scripts/cust_file_bkp_dir/data_file_dir/raw_list.txt");
foreach $line() {
      @split_line = split(/\s/,$line);
           if ($split_line[0] ne $holder) { # line40
                push (@unix_server_list, $split_line[0]."\n"); }
           $holder=$unix_server_list; }
      close(RAW_LIST);
#
open (UNIX_LIST, ">>/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_server_list.txt");
print UNIX_LIST sort @unix_server_list;
close(UNIX_LIST);
#
# open server list file for read line49
open (UNIX_LIST, "/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_server_list.txt")
      || die "cannot open unix_server_list.txt\n";
# get array (list of servers)
foreach $server() {
      push (@server_list, $server); }
close(UNIX_LIST);
#
# open unix server list for appends
open (OS_LIST, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_os_list.txt")
      || die "cannot open unix_os_list.txt\n";
#
# body line61
for ($i=0; $i<@server_list; $i++) {
      chomp($server=@server_list[$i]);
      (open(GET_OS, "rsh $server -n uname |"));
      $server{$server_by_os}=;
           if ($server{$server_by_os} eq "") {
                $server{$server_by_os}="NotAvail\n"; }
      print OS_LIST $server . " " . $server{$server_by_os};
      close(GET_OS);
      } # end of while loop line70
close(OS_LIST) || die "cannot close file unix_os_list.txt\n";
# end of program (for now, aynway...)

Takes output of server_lister.pl and goes out and finds the OS

#!/usr/bin/perl
use strict($server, $server_by_os);
#
# open server list file for read
open (UNIX_LIST, "/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_server_list.txt")
      || die "cannot open unix_server_list.txt\n";
# get array (list of servers)
foreach $server() {
      push (@server_list, $server); }
close(UNIX_LIST);
#
# open unix server list for appends
open (OS_LIST, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_os_list.txt")
      || die "cannot open unix_os_list.txt\n";
#
# body
for ($i=0; $i<@server_list; $i++) {
      chomp($server=@server_list[$i]);
      (open(GET_OS, "rsh $server -n uname |"));
      $server{$server_by_os}=;
      if ($server{$server_by_os} eq "") {
           $server{$server_by_os}="NotAvail\n"; }
      print OS_LIST $server . " " . $server{$server_by_os};
close(GET_OS);
} # end of while loop
close(OS_LIST) || die "cannot close file\n";
# end of script

This one finds out what version of perl is on the unix serers

#!/usr/bin/perl
use strict($server, $server_by_os);
#
# open server list file for read
open (UNIX_LIST, "/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_server_list.txt")
      || die "cannot open unix_server_list.txt\n";
# get array (list of servers)
foreach $server() {
      push (@server_list, $server); }
close(UNIX_LIST);
#
# open unix server list for appends
open (OS_LIST, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/perl_version_list.txt")
      || die "cannot open perl_version_list.txt\n";
#
# body
for ($i=0; $i<@server_list; $i++) {
      chomp($server=@server_list[$i]);
      (open(GET_OS, "rsh $server perl -v | grep 'perl, v' |"));
      $server{$server_by_os}=;
           if ($server{$server_by_os} eq "") {
           $server{$server_by_os}="NotAvail\n"; }
      print OS_LIST $server . " " . $server{$server_by_os};
      close(GET_OS);
      } # end of while loop
close(OS_LIST) || die "cannot close file\n";
# end of script

This one checks for specific users on network unix servers

#!/usr/bin/perl
use strict($server, $server_by_os);
#
# open server list file for read
open (UNIX_LIST, "/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_server_list.txt")
      || die "cannot open unix_server_list.txt\n";
#
# get array (list of servers)
foreach $server() { push (@server_list, $server); } close(UNIX_LIST);
#
# clear and open account list
open (GOT_ACCT, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_acct_list.txt")
      || die "cannot open unix_acct_list.txt\n";
open (GOT_ACCT, ">>/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_acct_list.txt")
      || die "cannot open unix_acct_list.txt\n";
#
# body
for ($i=0; $i<@server_list; $i++) {
      chomp($server=@server_list[$i]);
      open (STDERR, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/get_acct_errors.txt");
#
      (open(GET_ACCT, "rsh $server grep bq404 /etc/passwd |"));
      chomp($server{$checked}=);
      #
      open (ERRS, "/usr/local/scripts/cust_file_bkp_dir/data_file_dir/get_acct_errors.txt");
      chomp($serr=); close(ERRS);
      #
      if (($server{$checked} eq "") && ($serr eq "")) {
           $server{$checked}="No Account for bq404\n";
           print GOT_ACCT $server . " " . $server{$checked} . "\n"; }
      else {
           print GOT_ACCT $server . " " . $server{$checked} . $serr . "\n";
      }
      #
      open (CLEARER, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/get_acct_errors.txt");
      close(CLEARER); $serr="";
      close(GET_ACCT);
      } # end of body loop
close(GOT_ACCT) || die "cannot close file\n";
# end of script

This one runs maintenance on LotusNotes servers on a Solaris machine (manual version)

#!//usr/bin/perl
system(clear);
chomp($user=`whoami`);
chomp($domain=`pwd`);
@server=(split"\/", $domain);
#$path_name=$server[1] . "a" . "/notes/data";
$server_name="$user" . "a";
print "$server_name\n";
$path_name="$server_name" . "/notes/data";
print "$path_name\n";
$script_base="/opt/lotus/bin/";
$compact="/opt/lotus/bin/compact";
$updall="/opt/lotus/bin/updall";
$fixup="/opt/lotus/bin/fixup";
#
VERY_TOP:
print "\n$user, enter the file you wish to run maintenance on: ";
chomp($file_name=());
$mm_file="/$path_name/$file_name";
print "$mm_file\n";
-e $mm_file || (print "$mm_file does nott exist" && goto VERY_TOP);
TOP:
print "$user, select a task below\n
1\.\) compact
2\.\) updall
3\.\) fixup
4\.\) exit\n
enter your selection number: ";
chomp($select=());
#
if ($select eq "1") {
      system(clear);      print "\nYou have selected to run compact on domino server $server_name /$path_name/$file_name
      \(y\|n\) to proceed\: "; chomp($confirm=());
      if ($confirm !~ /(y|Y)/) { goto TOP; }
      else { print "confirmed.\n"; system("$compact /$path_name/$file_name -B -D"); }
      }
elsif ($select eq "2") {
      system(clear);
      print "\nYou have selected to run updall on domino server $server_name /$path_name/$file_name
      \(y\|n\) to proceed\: "; chomp($confirm=());
      if ($confirm !~ /(y|Y)/) { goto TOP; }
      else { print "confirmed.\n"; system("$updall /$path_name/$file_name"); }
      }
elsif ($select eq "3") {
      system(clear);
      print "\nYou have selected to run fixup on domino server $server_name /$path_name/$file_name
      \(y\|n\) to proceed\: "; chomp($confirm=());
      if ( $confirm !~ /(y|Y)/) { goto TOP; }
      else { print "confirmed.\n"; system("$fixup /$path_name/$file_name"); }
      }
elsif ($select eq 4) {
      system(clear);
      print "\nYou have selected to exit this program\n"; exit 0; }
elsif (($select ne "4") || ($select !~ /\d/)) {
      system(clear);
      print "\nThat was not a valid selection.\n"; }
#
goto(TOP);
# end of script

Here is the automatic version...

#!/usr/bin/perl
#
# NotesAutoMM.pl
# Monthly Maintenance for Lotus Domino server
# written Nov 2002, LM-UNIX, Daniel Sprouse
#
#
########################
# ~/~ HOUSEKEEPING ~/~ #
########################
# ~/~ VARIABLE DECLARATIONS ~/~ #

%file_list=(names  =>  ["names.nsf",       "queued", "queued", "queued"],
                admin4 =>   ["admin4.nsf",      "queued", "queued", "queued"],
                car   =>      ["car.nsf", "queued", "queued", "queued"],
                ceab  =>     ["ceab.nsf", "queued", "queued", "queued"],
                cldb  =>     ["cldbdir.nsf", "queued", "queued", "queued"],
                mgp   =>     ["mailgroups.nsf", "queued", "queued", "queued"],
                strp  =>     ["statrep.nsf", "queued", "queued", "queued"],
                eve   =>      ["events.nsf", "queued", "queued", "queued"],
                m0b   =>      ["mail.box", "queued", "queued", "queued"],
                m1b   =>      ["mail1.box", "queued", "queued", "queued"],
                m2b   =>      ["mail2.box", "queued", "queued", "queued"],
                m3b   =>      ["mail3.box", "queued", "queued", "queued"],
                m4b   =>      ["mail4.box", "queued", "queued", "queued"],
                ced   =>      ["common/ced.nsf", "queued", "queued", "queued"]);
#
#
$month=`date +%b`; $date=`date`; chomp($user=`whoami`);
$down_yet="";
$server_name="$user" . "a";
$path_name="$server_name" . "/notes/data";
chomp($start_file=`grep -l "$user" /etc/rc2.d/S*`);
$compact="/opt/lotus/bin/compact"; $updall="/opt/lotus/bin/updall"; $fixup="/opt/lotus/bin/fixup";
$log_file_base="/usr/users/$user/logfiles/MasterMMLog$month";
#
chomp($down_yet=`ps -fu $user | grep /opt/lotus/notes/latest/sunspa/server | grep -v grep`);
if ("$down_yet" ne "") {
      print"Domino server $user is still running. Attempting shutdown.\n";
      (open(SERVERQ, "server -q 2>&1>$log_file_base/tmp_errors1.txt |") || open(NSDKILL, "nsd -kill 2>&1>$log_file_base/tmp_errors2.txt |"))
           || die "Could not stop domino server $user, stop manually and retry. Aborting Maintenance\n";
      open(MAILER, "/usr/bin/mail [email protected] < $log_file_base/tmp_errors1.txt |"); close MAILER;
      open(MAILER, "/usr/bin/mail [email protected] < $log_file_base/tmp_errors2.txt |"); close MAILER;
      print "Domino server $user stopped\n";
}
# ~/~ End of Housekepping ~/~ #
#
#############################
# ~/~ MAIN PROGRAM BODY ~/~ #
#############################
MAIN:
foreach $file(keys %file_list) {
      #/$path_name/$file_name{$file}[0]
      FILE_TEST:
      $mm_file="$path_name" . "/" . "$file_list{$file}[0]"; #print "$mm_file\n\n";
      if (-r $mm_file) {
           COMPACT(); UPDALL(); FIXUP(); }
      else { NO_FILE(); }
      EXCEPTION:
}
END_RUN();
#
##############################
# ~/~ SUBROUTINES SECTION ~/~#
##############################
sub REPORT {
$date=`date`;
open(STATUSREPORT, ">/usr/users/$user/logfiles/Status");
write (STATUSREPORT) ; close STATUSREPORT; }
#
sub COMPACT {
      $file_list{$file}[1]="Running";
      $current_message1="Now running COMPACT on domino server $server_name $file_list"; REPORT();
      #open(COMPACT, "$compact $mm_file -B -D 2>&1>$log_file_base/$file.compact.log |");
      print "$compact $mm_file -B -D 2>&1>$log_file_base/$file.compact.log\n";
      $file_list{$file}[1]="Done";
      open(MAILER, "/usr/bin/mail [email protected] < $log_file_base/$file.compact.log |"); close MAILER;
      $current_message1="Finished running COMPACT on server $server_name."; REPORT();
}
#
sub UPDALL {
      $file_list{$file}[2]="Running";
      $current_message1="Now running UPDALL on domino server $server_name $file_list"; REPORT();
      #open(UPDALL, "$updall $mm_file 2>&1>$log_file_base/$file.updall.log |");
      print "$updall $mm_file 2>&1>$log_file_base/$file.updall.log\n";
      $file_list{$file}[2]="Done";
      open(MAILER, "/usr/bin/mail [email protected] < $log_file_base/$file.compact.log |"); close MAILER;
      $current_message1="Finished running UPDALL on server $server_name."; REPORT();
}
#
sub FIXUP {
      $file_list{$file}[3]="Running";
      $current_message1="Now running FIXUP on domino server $server_name $file_list"; REPORT();
      #open(UPDALL, "$fixup $mm_file 2>&1>$log_file_base/$file.fixup.log |");
      print "$fixup $mm_file 2>&1>$log_file_base/$file.fixup.log\n";
      $file_list{$file}[3]="Done";
open(MAILER, "/usr/bin/mail [email protected] < $log_file_base/$file.compact.log |"); close MAILER;
$current_message1="Finished running FIXUP on server $server_name."; REPORT();
}
#
sub NO_FILE {
      $file_list{$file}[1]="missing"; $file_list{$file}[2]="missing"; $file_list{$file}[3]="missing";
      $current_message1="$file_list{$file} not found on domino server $server_name"; REPORT();}
#
sub END_RUN {
      $current_message1="Monthly Maintenance has COMPLETED on $server_name.";
      $current_message2="Restarting domino server."; REPORT();
      open(STARTUPDOMINO, "$start_file start 2>&1>$log_file_base/tmp_errors3.txt|");
      if ($? eq "0") {
      $current_message2="Domino server has been restarted."; REPORT(); }
      else { $current_message2="Domino server will need to be restarted manually."; REPORT(); }
      open(MAILER, "/usr/bin/mail [email protected] < $log_file_base/tmp_errors3.txt |"); close MAILER;
}
#
format STATUSREPORT =


Monthly Maintenance for @<<<<<<<<
$user
@<<<<<<<<<<<<<<<<<<<<<<<
$date
Monthly Maintenance Status Report


names admin4 car ceab cldbdir statrep events
compact @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<
$file_list{names}[1], $file_list{admin4}[1], $file_list{car}[1], $file_list{ceab}[1], $file_list{cldb}[1], $file_list{strp}[1], $file_list{eve}[1]
updall @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<
$file_list{names}[2], $file_list{admin4}[2], $file_list{car}[2], $file_list{ceab}[2], $file_list{cldb}[2], $file_list{strp}[2], $file_list{eve}[2]
fixup @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<
$file_list{names}[3], $file_list{admin4}[3], $file_list{car}[3], $file_list{ceab}[3], $file_list{cldb}[3], $file_list{strp}[3], $file_list{eve}[3]

mailgroups mail.box mail1.box mail2.box mail3.box mail4.box ced
compact @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<
$file_list{mgp}[1], $file_list{m0b}[1], $file_list{m1b}[1], $file_list{m2b}[1], $file_list{m3b}[1], $file_list{m4b}[1], $file_list{ced}[1]
updall @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<
$file_list{mgp}[2], $file_list{m0b}[2], $file_list{m1b}[2], $file_list{m2b}[2], $file_list{m3b}[2], $file_list{m4b}[2], $file_list{ced}[2]
fixup @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<< @<<<<<<<<<<
$file_list{mgp}[3], $file_list{m0b}[3], $file_list{m1b}[3], $file_list{m2b}[3], $file_list{m3b}[3], $file_list{m4b}[3], $file_list{ced}[3]

@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$current_message1
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$current_message2

.
# that period on the line above - marks the end of the format, leave it the hell alone.
# end of script

This one greps the motd for the UNIX Tru64 version...

#!/usr/bin/perl.
#.
open (OS_LIST, "/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_os_list.txt").
      || die "cannot open unix_os_list.txt\n";.
#.
foreach $line() {.
      @split_line = split(/\s/,$line);.
      if ($split_line[1] eq OSF1) {.
           push (@unix_tru64_list, $split_line[0]."\n"); }}.
; close OS_LIST;.
#.
open (T64_LIST, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_tru64.txt").
      || die "cannot open unix_tru64.txt\n"; close T64_LIST;.
open (T64_LIST, ">>/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_tru64.txt").
      || die "cannot open unix_tru64.txt\n";.
#.
for ($i=0; $i<@unix_tru64_list; $i++) {.
      chomp($server=@unix_tru64_list[$i]);.
      print "$server\n";.
      (open(GET_OS, "rsh $server grep V /etc/motd |"));.
      chomp($t64server=);.
      print T64_LIST "$server $t64server\n\n";.
      close(GET_OS);.
      }.

This moves a symbolic link and cofirms it in a report...

#!/usr/bin/perl
#
open (OS_LIST, "/usr/local/scripts/cust_file_bkp_dir/data_file_dir/unix_os_list.txt")
      || die "cannot open unix_os_list.txt\n";
open (T64LIST, ">/usr/local/scripts/cust_file_bkp_dir/data_file_dir/T64list.txt");
close T64LIST;
foreach $line() {
      @split_line = split(/\s/,$line);
      if ($split_line[1] eq OSF1) {
           push (@unix_tru64_list, $split_line[0]."\n"); }}
close OS_LIST;
#
for ($i=0; $i<@unix_tru64_list; $i++) {
      chomp($server=@unix_tru64_list[$i]);
      open (T64LIST, ">>/usr/local/scripts/cust_file_bkp_dir/data_file_dir/T64list.txt");
      (open(UNLINK_SSH, "rsh $server /usr/sbin/unlink /sbin/rc2.d/S*ssh |"));
      close UNLINK_SSH;
      (open(RELINK_SSH, "rsh $server /usr/bin/ln -s /sbin/init.d/ssh /sbin/rc3.d/S80ssh |"));
      close RELINK_SSH;
      print T64LIST "$server -- ";
      (open(GET_LS, "rsh $server /usr/bin/ls -lF /sbin/rc3.d/S*ssh |"));
      $data=;
      print T64LIST "$data";
      close T64LIST; close(GET_LS);
}

Hosted by www.Geocities.ws

1