use strict; use Expect; use POSIX; use Time::ParseDate; use Getopt::Std; my $command = 'connexid'; my $password = 'passwd'; my $login = 'loginid'; my $job = $ARGV[1]; my $queue = $ARGV[2]; my $date = $ARGV[3]; my $time = $ARGV[4]; my $exp; my $when; my %options=(); getopts("hvnlrt", \%options); if ($date) { date(); } if ($options{t}) { if ($job && $queue && $date && $time) { print "At $time on $when, this will run $job in queue $queue. \n"; } elsif ($job && $queue && $date) { print "Please enter a time for the job to run. \n"; } elsif ($job && $queue) { print "This will run $job in queue $queue immediately with the -n flag \n"; } elsif ($job eq "install") { print "OK\n"; } else { print "Please specify a Job Name and Queue \n"; } } if ($options{h}) { help(); } if ($options{r}) { if ($date && $time) { repgen(); } elsif ($date) { die "Please specify a time for the job to run. \n"; } else { die "Please specify a date and time for the job to run. \n"; } } if ($options{l}) { if ($date && $time) { later(); } elsif ($date) { die "Please specify a time for the job to run. \n"; } else { die "Please specify a date and time for the job to run. \n"; } } if ($options{n}) { if ($job && $queue) { now(); } else { die "Please specify a job name and a queue. \n"; } } if ($options{v}) { print "autoepisys version 1.3\n"; } sub login{ if ($command eq "local") { $exp = Expect->spawn("sym") or die "Cannot spawn sym $!\n"; $exp->expect(10, '-re', 'UserId'); $exp->send("$login\r"); $exp->expect(10, '-re', 'Dedicate this console to this user?'); $exp->send("y\r"); } else { $exp = Expect->spawn($command) or die "Cannot spawn $command $!\n"; $exp->expect(10, '-re', 'password:'); $exp->send("$password\r"); $exp->expect(10, '-re', '(#|\$) '); $exp->send("sym\r"); $exp->expect(10, '-re', 'UserId'); $exp->send("$login\r"); $exp->expect(10, '-re', 'Dedicate this console to this user?'); $exp->send("y\r"); } } sub logoff { if ($command eq "local") { $exp->expect(10, '-re', "Do you wish to log off the system?"); $exp->send("y\r"); $exp->soft_close(); } else { $exp->expect(10, '-re', "Do you wish to log off the system?"); $exp->send("y\r"); $exp->expect(10, '-re', '(#|\$) '); $exp->send("exit\r"); $exp->soft_close(); } } sub now { login(); $exp->expect(10, '-re', 'Menu Selection'); $exp->send("8\r"); $exp->expect(10, '-re', 'Menu Selection'); $exp->send("0\r"); $exp->expect(10, '-re', 'Selection'); $exp->send("0\r\r"); $exp->expect(10, '-re', 'Job File Name'); $exp->send("$job\r"); $exp->expect(10, '-re', 'Batch Options?'); $exp->send("Y\r"); $exp->expect(10, '-re', 'Display Batch Queues'); $exp->send("\r"); $exp->expect(10, '-re', 'Notify Upon Completion?'); $exp->send("\r"); $exp->expect(10, '-re', 'Queue Priority'); $exp->send("\r"); $exp->expect(10, '-re', 'Scheduled Start Date'); $exp->send("\r"); $exp->expect(10, '-re', 'Scheduled Start Time'); $exp->send("\r"); $exp->expect(10, '-re', 'Batch Queue'); $exp->send("$queue\r"); $exp->after(10, '-re', 'Exception Item Batch ID'); $exp->send("\r"); $exp->expect(10, '-re', 'Okay?'); $exp->send("Y\r"); $exp->expect(10, '-re', "Batch Job $job Is Done"); $exp->send("\e"); $exp->send("\e"); $exp->send("\e"); logoff(); } sub later { login(); $exp->expect(10, '-re', 'Menu Selection'); $exp->send("8\r"); $exp->expect(10, '-re', 'Menu Selection'); $exp->send("0\r"); $exp->expect(10, '-re', 'Selection'); $exp->send("0\r\r"); $exp->expect(10, '-re', 'Job File Name'); $exp->send("$job\r"); $exp->expect(10, '-re', 'Batch Options?'); $exp->send("Y\r"); $exp->expect(10, '-re', 'Display Batch Queues'); $exp->send("\r"); $exp->expect(10, '-re', 'Notify Upon Completion?'); $exp->send("\r"); $exp->expect(10, '-re', 'Queue Priority'); $exp->send("\r"); $exp->expect(10, '-re', 'Scheduled Start Date'); $exp->send("$when\r"); $exp->expect(10, '-re', 'Scheduled Start Time'); $exp->send("$time\r"); $exp->expect(10, '-re', 'Batch Queue'); $exp->send("$queue\r"); $exp->expect(10, '-re', 'Expected System Date'); $exp->send("$when\r"); $exp->expect(10, '-re', 'Expected Previous System Date'); $exp->send("\r"); $exp->after(10, '-re', 'Exception Item Batch ID'); $exp->send("$when\r"); $exp->expect(10, '-re', 'Okay?'); $exp->send("Y\r"); $exp->send("\e"); $exp->send("\e"); $exp->send("\e"); logoff(); } sub repgen { login(); $exp->expect(10, '-re', 'Menu Selection'); $exp->send("8\r"); $exp->expect(10, '-re', 'Menu Selection'); $exp->send("0\r"); $exp->expect(10, '-re', 'Selection'); $exp->send("1\r\r"); $exp->expect(10, '-re', 'Selection'); $exp->send("11\r"); $exp->expect(10, '-re', 'Specification File'); $exp->send("$job\r"); $exp->expect(10, '-re', 'Selected Run Date'); $exp->send("$when\r"); $exp->expect(10, '-re', "Specification File"); $exp->send("\r"); $exp->expect(10, '-re', "Batch Options?"); $exp->send("Y\r"); $exp->expect(10, '-re', 'Display Batch Queues'); $exp->send("\r"); $exp->expect(10, '-re', 'Notify Upon Completion?'); $exp->send("\r"); $exp->expect(10, '-re', 'Queue Priority'); $exp->send("\r"); $exp->expect(10, '-re', 'Scheduled Start Date'); $exp->send("\r"); $exp->expect(10, '-re', 'Scheduled Start Time'); $exp->send("$time\r"); $exp->expect(10, '-re', 'Batch Queue'); $exp->send("$queue\r"); $exp->expect(10, '-re', 'Okay?'); $exp->send("Y\r"); $exp->send("\e"); $exp->send("\e"); $exp->send("\e"); logoff(); } sub help { print "usage: \[-l\] \[-n\] \[-r\] \[-v\] \[-t\] JOB.NAME queue when time\n"; print " The -l option sets the batch job to run later\n"; print " The -n option runs the batch job now (for script automation)\n"; print " The -r option runs a report generator specification file\n"; print " The -v option shows version information\n"; print " The -t option will show you what will happen with a query\n"; print "Examples:\n"; print " auto -l NETTELLER 3 2days 0130\n"; print " auto -l ACH.MIDNIGHT.POST 2 tomorrow 0030\n"; print " auto -n DRAFT.POST 1\n"; print " auto -r DAILY.REFERENCE.FILE 1 today 1801\n"; print " auto -t SOME.COMMAND 2 3days 1801\n"; exit; } sub date { my $dt = parsedate($date); $when = strftime("%m%d%y", localtime($dt)); chomp($when); }