#!/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 AlertUECUEmail "bputtkammer@uecu.coop" set EmailCommand "echo 'Subject:Problem with CU49-VCH\nCU49 did not complete' | sendmail AlertUECUEmail" set DoneCommand "echo 'Subject:Done with CU49-VCH\nCU49 completed!' | sendmail UECUEmail" # DATEADD FUNCTIONS AND VARIABLES INCLUDED BELOW source /udadmin/expectscripts/DateFormats.exp source /udadmin/expectscripts/ExpectConfig.exp # TURN ON LOGGING - SET LOG VARIABLE NAME set LogFileName "/udadmin/expectlogs/INITIATE-VCH-$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 10 MINUTES set timeout 600 set EmailText "\n" set LineBreak "" set AccountDirectory "$DefaultLiveAccountPath" set ScriptName "initiate-vch.exp" if {$AccountDirectory == "/eom/MEA.EOM"} { set EmailSubject "CU49-Voucher - TEST" set SubjectNotes "Done with CU49-Voucher" set LoginScript "/udadmin/expectscripts/TrainUsers.exp" } else { set EmailSubject "CU49-Voucher - LIVE" set SubjectNotes "Done with CU49-Voucher" set LoginScript "/udadmin/expectscripts/LiveUsers.exp" } # SET THE VOUCHER PRINTER TERMINAL NUMBERS UP IN THE LIST # ADD NEW TERMINALS OR CHANGE THEM HERE - YOU MUST UPDATE THE NEXT PART WITH THE VOUCHER NUMBERS TOO, SEPARATE EACH ENTRY WITH A SPACE set Terminals {26 43 81 88 93 90 94 96 97 98 134 135 136 137 41 78 79 123} # SET THE VOUCHER PRINTER NUMBERS TO BE USED IN ADMIN22 WHEN SWITCHING BETWEEN THEM, SEPARATE EACH ENTRY WITH A SPACE set Printers {23 24 25 26 27 14 15 16 17 18 19 21 20 22 28 29 30 31} set PrinterNames {AV-CORP-THERM-PRINTER AV-THRM1 AV-THRM2 AV-THRM3 AV-THRM-DRV CR-DRIVE-VCH WBY-THERM-PRINT1 WBY-THRM-VCH2 WBY-THRM-VCH3 WBY-THRM-DRV EP-THRM-VCH1 EP-THRM-VCH2 CR-THRM-VCH1 CR-THRM-VCH2 SLP-THRM1 SLP-THRM2 SLP-THRM3 EP-THRM-DRV} set PrinterStringEnabled "\n" set PrinterStringSkipped "" # ESTABLISH THE ACCOUNT YOU WANT TO LOGIN TO source $LoginScript # RUN LOGIN SCRIPT, BASED ON THE ACCOUNT YOU WISH TO ACCESS source /udadmin/expectscripts/login.exp # RUN LPSTAT ONCE LOGGED ON 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 } ":" { send -- "LPSTAT\r" append EmailText $expect_out(0,string)$LineBreak } } for {set counter [expr [llength $Printers]-1]} {$counter>=0} {incr counter -1} { # GET THE CURRENT TERMINAL NUMBER FROM LIST ABOVE set TerminalNumber [lindex $Terminals $counter] # GET THE CURRENT VOUCHER PRINTER NUMBER FROM LIST ABOVE set PrinterNumber [lindex $Printers $counter] # GET THE CURRENT VOUCHER PRINTER NAME FROM LIST ABOVE set PrinterName [lindex $PrinterNames $counter] # SET OUR TERMINAL TO THE CORRECT VOUCHER PRINTER NUMBER IN ADMIN22 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 } ":" { send -- "ADMIN22\r" append EmailText $expect_out(0,string)$LineBreak } } # ENTER THROUGH FIRST ADMIN22 QUESTION FOR OUR TERMINAL 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 } "Enter Terminal" { send -- "\r" append EmailText $expect_out(0,string)$LineBreak } } # NOW GO TO THE VOUCHER PRINTER FIELD # ENTER THE VOUCHER PRINTER NUMBER IN THE VOUCHER PRINTER FIELD # SAVE THE SETTINGS IN ADMIN22 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 } "Enter Field Number" { send -- "4\r" send -- "$PrinterNumber\r" send -- "S\r" append EmailText $expect_out(0,string)$LineBreak } } # NOW END OUT OF ADMIN22 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 } "Enter Terminal" { send -- "END\rEND\rDATE\r" append EmailText $expect_out(0,string)$LineBreak } } # RUN THE NEXT VOUCHER NUMBER PROGRAM 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 } ":" { send -- "CU44\r" append EmailText $expect_out(0,string)$LineBreak } } # TERMINATE OR SUSPEND A PRINTER 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 } "Which Printer function" { send -- "2\r" append EmailText $expect_out(0,string)$LineBreak } } # Select (by number) the required VOUCHER Printer 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 } "Enter Printer Number to Terminate" { send -- "$PrinterNumber\r" append EmailText $expect_out(0,string)$LineBreak } } # Enter the LAST VOUCHER number SATISFACTORILY printed 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 } "Enter the LAST VOUCHER number" { send -- "1\r" append EmailText $expect_out(0,string)$LineBreak } } # MATCH THE NEXT VOUCHER NUMBER TEXT SO WE CAN CAPTURE IT TO A VARIABLE # IMPOSSIBLE ! - I HAVEN'T PRINTED THAT NUMBER YET ! 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 } "IMPOSSIBLE" { send -- "\r\rEND\rEND\r" set NextVoucherNumber 1 append EmailText $expect_out(0,string)$LineBreak } -re "Are you sure that you want to reprint (\[0-9]+) VOUCHERS" { set NextVoucherNumber $expect_out(1,string) set NextVoucherNumber [expr $NextVoucherNumber+2] send -- "NO\rEND\r" append EmailText $expect_out(0,string)$LineBreak } -re "THE LAST VOUCHER THAT I HAVE PRINTED WAS NO. (\[0-9]+) !" { set NextVoucherNumber $expect_out(1,string) set NextVoucherNumber [expr $NextVoucherNumber+1] send -- "NO\rEND\r" append EmailText $expect_out(0,string)$LineBreak } } # DO WE NEED TO RESET VOUCHER NUMBERS AT ANY POINT, MONTHLY, OR CAN THEY JUST KEEP INCREASING set LastVoucherNumber [expr $NextVoucherNumber+50000] # INITIATE THE VOUCHER PRINTER 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 } ":" { send -- "CU49\r" append EmailText $expect_out(0,string)$LineBreak } } # Enter FIRST usable VOUCHER 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 } "This printer is currently running" { # WHAT DO YOU WANT TO DO IF THE PRINTER IS ALREADY ENABLED? send -- "END\rEXP.ME\r" append PrinterStringSkipped "Printer Currently Running: Printer Name=$PrinterName, Printer Number=$PrinterNumber\n" append EmailText $expect_out(0,string)$LineBreak } "Enter FIRST usable VOUCHER" { send -- "$NextVoucherNumber\r" append EmailText $expect_out(0,string)$LineBreak } } # VERIFY THAT THIS IS THE FIRST VOUCHER NUMBER 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 } "YOUR EXPECT SCRIPT HAS ESCAPED" { send -- "END\rEXP.ME\r" append EmailText $expect_out(0,string)$LineBreak } "Number OUT OF SEQUENCE" { send -- "N\rEND\rEXP.ME\r" append EmailText $expect_out(0,string)$LineBreak } "Verify $NextVoucherNumber is FIRST Number" { send -- "Y\r" append EmailText $expect_out(0,string)$LineBreak } } # ENTER LAST USABLE VOUCHER NUMBER 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 } "YOUR EXPECT SCRIPT HAS ESCAPED" { send -- "END\rEXP.ME\r" append EmailText $expect_out(0,string)$LineBreak } "Enter LAST usable VOUCHER " { send -- "$LastVoucherNumber\r" append EmailText $expect_out(0,string)$LineBreak } } # VERIFY THAT THIS IS THE LAST VOUCHER NUMBER 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 } "YOUR EXPECT SCRIPT HAS ESCAPED" { send -- "END\rEXP.ME\r" append EmailText $expect_out(0,string)$LineBreak } "Verify $LastVoucherNumber is LAST Number" { send -- "Y\r" append EmailText $expect_out(0,string)$LineBreak } } # RETURN WHEN READY TO PROCEED 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 } "YOUR EXPECT SCRIPT HAS ESCAPED" { send -- "\rEND\rEXP.ME\rDATE\r" append PrinterStringSkipped "Printer Name=$PrinterName, Printer Number=$PrinterNumber\n" append EmailText $expect_out(0,string)$LineBreak } "ready to proceed" { append PrinterStringEnabled "Printer Name=$PrinterName, Printer Number=$PrinterNumber, First Voucher=$NextVoucherNumber, Last Voucher=$LastVoucherNumber\n" send -- "\rEND\rEND\rDATE\r" append EmailText $expect_out(0,string)$LineBreak } "to continue" { # append PrinterStringEnabled "Printer Name=$PrinterName, Printer Number=$PrinterNumber, First Voucher=$NextVoucherNumber, Last Voucher=$LastVoucherNumber\n" send -- "\rEND\rEND\rDATE\r" append EmailText $expect_out(0,string)$LineBreak } } } # LOG OFF 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 } ":" { send -- "OFF\r" append EmailText $expect_out(0,string)$LineBreak } } # FINISHED 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 } "Logging OFF" {append EmailText $expect_out(0,string)$LineBreak} "Thank you, " {append EmailText $expect_out(0,string)$LineBreak} } # ENDING SESSION expect { timeout { exit } eof } # CALCULATE TOTAL TIME OF RUNNING SCRIPT source /udadmin/expectscripts/total_time.exp source /udadmin/expectscripts/server_time.exp if {$PrinterStringSkipped != ""} { set PrinterStringSkipped "\nThe following printers were skipped,\n$PrinterStringSkipped\n\n" set SubjectNotes "Done with CU49-Voucher: ATTN" } else { set SubjectNotes "Done with CU49-Voucher" } set InitiateEmail "UECUEmail,MSRGroup" set DoneCommand "echo 'Subject:$SubjectNotes\nCU49 completed (voucher initiation)!\n\nThe following printers were enabled:\n$PrinterStringEnabled\n$PrinterStringSkipped\nCU49 took, $TotalTime\nStart Time:$StartTimeDisplay\nEnd Time:$EndTimeDisplay\n\n$ServerTime\n\n$EmailNotes' | sendmail $InitiateEmail" system $DoneCommand # UPDATE DAILY VERIFY FILE WITH SCRIPT COMPLETED system "echo 'COMPLETED, $ScriptName, $FileDate, $TotalTime' >> /udadmin/expectlogs/DailyVerify$FileDate.txt"