#!/usr/bin/perl ######################################################################## # # Just a simple interface meant to simplify the maintenance of the film # and video library database server for those not really accustomed to # unix stuff... # # Things it will do: # 1. Do a manual clean of the logfiles. # 2. Do a manual disk mirror operation. # 3. Reboot the machine. # 4. Reboot the machine and check and repair disks. # 5. Shutdown the machine. # 6. Change the email addy that root mail goes to. # 7. Exit to command shell. # ######################################################################## # Formatting stuff for the interface...very simplistic. $line = "========================================================================\n"; #Clear the screen initially so we have a clean page system 'clear'; print "\n"; # Repeat the entire thing unless they exit voluntarily. $command = "X"; while ( $command ne "7" ) { # Where does root email currently go? (This should go before the # instructions are printed...so they will have the current info.) open ( IN, "; chop ( $rootmail ); close ( IN ); # Print out the instructions text. &Instructions; $command = ; chop ( $command ); if ( $command =~ /1|2|3|4|5|6|7/ ) { # Good, they entered a valid command... if ( $command eq "1" ) { system 'clear'; print $line; print "SYSTEM: Performing manual log cleaning\n"; print $line; system '/etc/logrotate.cron'; sleep (2); system 'clear'; } elsif ( $command eq "2" ) { system 'clear'; print $line; print "SYSTEM: Performing disk mirroring.\n"; print " ....this may take some time.\n"; print $line; # Insert command here. system 'dd if=/dev/hda2 of=/dev/hdb2'; sleep (2); system 'clear'; } elsif ( $command eq "3" ) { $rebootme = "X"; system 'clear'; print $line; print "WARNING - WARNING - WARNING - WARNING\n"; print " You are about to shutdown and restart this machine!\n"; print $line; print "SYSTEM: Are you sure you want to reboot??\n"; print "SYSTEM: Type: \"reboot\" and hit 'enter' if you're serious.\n"; print "SYSTEM: Type anything else and hit enter to abort.\n"; print $line; $rebootme = ; chop ( $rebootme ); if ( $rebootme eq "reboot" ) { print "Rebooting the machine...\n"; # Commented out for 'safe' mode. system '/sbin/reboot'; exit (1); } else { system 'clear'; print $line; print "Aborting reboot...machine will NOT be restarted.\n"; print $line; sleep (2); system 'clear'; } #end elsif for option 3. } elsif ( $command eq "4" ) { $rebootme = "X"; system 'clear'; print $line; print "WARNING - WARNING - WARNING - WARNING\n"; print " You are about to shutdown and restart this machine!\n"; print $line; print "SYSTEM: Are you sure you want to reboot and check disks??\n"; print "SYSTEM: Type: \"reboot\" and hit 'enter' if you're serious.\n"; print "SYSTEM: Type anything else and hit enter to abort.\n"; print $line; $rebootme = ; chop ( $rebootme ); if ( $rebootme eq "reboot" ) { print "Rebooting the machine...\n"; print "You can turn off power at the next login prompt."; # Commented out for 'safe' mode. system '/sbin/reboot -f'; exit (1); } else { system 'clear'; print $line; print "Aborting reboot...machine will NOT be restarted.\n"; print $line; sleep (2); system 'clear'; } #end elsif for option 4. } elsif ( $command eq "5" ) { $rebootme = "X"; system 'clear'; print $line; print "WARNING - WARNING - WARNING - WARNING\n"; print " You are about to shutdown and this machine!\n"; print $line; print "SYSTEM: Are you sure you want to shut this machine off?\n"; print "SYSTEM: Type: \"shutdown\" and hit 'enter' if you're serious.\n"; print "SYSTEM: Type anything else and hit enter to abort.\n"; print $line; $rebootme = ; chop ( $rebootme ); if ( $rebootme eq "shutdown" ) { print "Shutting down the machine...\n"; # Commented out for 'safe' mode. system '/sbin/shutdown now'; exit (1); } else { system 'clear'; print $line; print "Aborting shutdown...machine will NOT be restarted.\n"; print $line; sleep (2); system 'clear'; } #end elsif for option 5. } elsif ( $command eq "6" ) { system 'clear'; print $line; print " Changing email address that mail sent to user 'root'\n"; print " is forwarded to. (Currently: $rootmail)\n"; print $line; $rootm = ; open ( FORWARD, ">/root/.forward" ); print FORWARD "$rootm\n"; close ( FORWARD ); print $line; print "Root mail will now go to: $rootm\n"; print "WARNING:\n If this is not a valid email address, \n"; print " bounced emails may fill disk space...\n\n"; print $line; sleep (5); system 'clear'; # End elsif for option 6. } else { system 'clear'; } # Else, they didn't enter a valid command...dammit. } else { print $line; print "Error: Please enter a valid command number.\n"; print $line; sleep (2); system 'clear'; } # This bracket closes the BIG while loop....leave it alone. } # Say goodnight... $date = `date`; print $line; print "Exited sysutil on $date"; print "WARNING: You are logged in as user 'root'...all changes you\n"; print "make will be PERMANENT and may cause system damage.\n\n"; print "Type 'sysutil' to get back to the management utility.\n"; print $line; #-----------------Subroutines begin here-----------------# # This is just in case I have to call this at some weird place # at a later time I won't have to re-write it. sub Instructions { print $line; print " Welcome To The Film Video Library Server\n"; print $line; print "| Here you'll find basic commands to do the essential system\n"; print "| administration tasks. Make your selection from the menu below.\n"; print "| (Just enter the number to the left and press 'enter'.)\n"; print $line; print " 1 - Do a manual clean of the logfiles.\n"; print " 2 - Do a manual disk mirror operation.\n"; print " 3 - Reboot the machine.\n"; print " 4 - Reboot the machine and check and repair disks.\n"; print " 5 - Shutdown the machine.\n"; print " 6 - Change the email addy that root mail goes to.\n"; print " Currently: $rootmail\n"; print " 7 - Exit to command shell.\n"; print $line; print " Hint: If you make a typo, type Ctrl-U to erase the line\n"; print $line; }