#!/usr/local/bin/expect -f # ## PROPERTY OF BRANT PUTTKAMMER, PLEASE CONTACT ME IF YOU HAVE QUESTIONS ## PLEASE USE CAUTION WHEN RUNNING THIS PROGRAM ON YOUR SYSTEM set force_conservative 1 ;# set to 1 to force conservative mode even if ;# script wasn't run conservatively originally if {$force_conservative} { set send_slow {1 .1} proc send {ignore arg} { sleep .1 exp_send -s -- $arg } } # BEGIN EXPECT SCRIPT BELOW #* PROPERTY OF BRANT PUTTKAMMER, PLEASE CONTACT ME IF YOU HAVE QUESTIONS # SET THE EMAIL COMMANDS FOR COMPLETION AND ERRORS set UECUEmail "bputtkammer@uecu.coop" set AlertUECUEmail "bputtkammer@uecu.coop,brant.puttkammer@gmail.com" set SMSUECUEmail "123456789@txt.att.net" set EmailCommand "echo 'Subject:Problem with Manual Manual Merge\nManual Merge did not complete' | sendmail AlertUECUEmail" set DoneCommand "echo 'Subject:Done with Manual Merge\nManual Merge completed!' | sendmail UECUEmail" set BackupFailedCommand "echo 'Subject:Manual Merge Incomplete!\nManual Merge did not complete!' | sendmail AlertUECUEmail" # DATEADD FUNCTIONS AND VARIABLES INCLUDED BELOW source /udadmin/expectscripts/DateFormats.exp source /udadmin/expectscripts/ExpectConfig.exp set EmailCommand "echo 'Subject:Problem with Manual Manual Merge\nManual Merge did not complete on $SMSDate!' | sendmail AlertUECUEmail" set DoneCommand "echo 'Subject:Done with Manual Merge\nManual Merge completed for $SMSDate!' | sendmail UECUEmail" set BackupFailedCommand "echo 'Subject:Manual Merge Incomplete!\nManual Merge did not complete on $SMSDate!' | sendmail AlertUECUEmail" # TURN ON LOGGING - SET LOG VARIABLE NAME set LogFileName "/udadmin/expectlogs/ManualMergeMirrors$FileDate.log" log_file $LogFileName # CHANGE FILE PERMISSIONS AND OWNER ON LOG FILE system "chmod 777 $LogFileName" system "chown expect $LogFileName" # SET THE TIMEOUT TO 3 MINUTES set timeout 180 set EmailText "\n" set LineBreak "\n" set EmailNotes "" set AccountDirectory "$DefaultLiveAccountPath" set ScriptName "manual_merge.exp" if {$AccountDirectory == "/eom/MEA.EOM"} { set EmailSubject "Manual Merge - TEST" set LoginScript "/udadmin/expectscripts/TrainUsers.exp" } else { set EmailSubject "Manual Merge - LIVE" set LoginScript "/udadmin/expectscripts/LiveUsers.exp" } system "/udadmin/expectscripts/enable_users.exp" # START THE TELNET SESSION spawn telnet $HOSTADDRESS # LOGIN expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail $AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "login:" { send -- "$USERNAME\r" append EmailText $expect_out(0,string)$LineBreak } } # SEND PASSWORD expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail $AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "Password:" { send -- "$PASSWORD\r" append EmailText $expect_out(0,string)$LineBreak } } # Systems Administration Main Menu expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "Systems Administration Main Menu*Selection:" { send -- "1\r" append EmailText $expect_out(0,string)$LineBreak } } # System Backups and Tools expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "System Backups and Tools*Selection:" { send -- "7\r" append EmailText $expect_out(0,string)$LineBreak } } # System Backups and Tools expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "System Backups and Tools*Selection:" { send -- "9\r" append EmailText $expect_out(0,string)$LineBreak } } # SET THE TIMEOUT TO 15 MINUTES set timeout 900 # This will merge the disk mirror expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "Do you wish to continue? (y/n):" { send -- "y\r" append EmailText $expect_out(0,string)$LineBreak } } # Merge completed -- OR -- It is most likely that the mirrors are already merged expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "Error reported unmounting" { send -- "y\r" append EmailNotes $expect_out(0,string)$LineBreak append EmailText $expect_out(0,string)$LineBreak exp_continue } "datab is still mounted" { send -- "\r" append EmailNotes $expect_out(0,string)$LineBreak append EmailText $expect_out(0,string)$LineBreak exp_continue } "rmlv: Logical volume data" { send -- "\r" append EmailText $expect_out(0,string)$LineBreak } "Merge completed " { send -- "\r" append EmailText $expect_out(0,string)$LineBreak } "Press ENTER for Previous Menu" { send -- "\r" append EmailText $expect_out(0,string)$LineBreak } "Press return to exit" { send -- "\r" append EmailText $expect_out(0,string)$LineBreak } } # SET THE TIMEOUT TO 3 MINUTES set timeout 180 # System Backups and Tools expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "System Backups and Tools*Selection:" { send -- "e\r" append EmailText $expect_out(0,string)$LineBreak } } # System Backups and Tools expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "System Backups and Tools*Selection:" { send -- "e\r" append EmailText $expect_out(0,string)$LineBreak } } # Systems Administration Main Menu expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } "Systems Administration Main Menu*Selection:" { send -- "e\r" append EmailText $expect_out(0,string)$LineBreak } } # ENDING SESSION expect { timeout { set EmailCommand "echo 'Subject:Problem with $EmailSubject\\nExpect Statements:$EmailText' | sendmail AlertUECUEmail" system $EmailCommand system "echo 'ERROR, $ScriptName, $FileDate' >> /udadmin/expectlogs/DailyVerify$FileDate.txt" sleep 360000 } eof } # CALCULATE TOTAL TIME OF RUNNING SCRIPT source /udadmin/expectscripts/total_time.exp source /udadmin/expectscripts/server_time.exp if {$EmailNotes == ""} { set DoneCommand "echo 'Subject:Done with $EmailSubject\nManual Merge completed for $SMSDate!\n$EmailNotes\nManual Merge took, $TotalTime\nStart Time:$StartTimeDisplay\nEnd Time:$EndTimeDisplay\n\n$ServerTime\n\n$EmailNotes' | sendmail UECUEmail" } else { set DoneCommand "echo 'Subject:Done with $EmailSubject\nManual Merge completed for $SMSDate!\n\nIssues: $EmailNotes\nManual Merge took, $TotalTime\nStart Time:$StartTimeDisplay\nEnd Time:$EndTimeDisplay\n\n$ServerTime\n\n$EmailNotes' | sendmail AlertUECUEmail" } system $DoneCommand # UPDATE DAILY VERIFY FILE WITH SCRIPT COMPLETED system "echo 'COMPLETED, $ScriptName, $FileDate, $TotalTime' >> /udadmin/expectlogs/DailyVerify$FileDate.txt"