
Sys::Manage::Schedule - Scriptic schedule trunk

use Sys::Manage::Schedule;
my $s =Sys::Manage::Schedule->new([@ARGV], -option=>value,..);
if ($s->at('-a')) { # at any other item execution
...
}
if ($s->at('-' # at system scheduler arguments given
,'17:20','/interactive','/every:M,T,W,Th,F,S,Su') {
...
}
if ($s->at('-' # ... automatically filling arguments repeating
,['17:23','/interactive','/every:M,T,W,Th,F,S,Su']
,['17:24'])) {
...
}
if ($s->at('-s',0)) { # at operating system startup, if automatic win32 service
...
}
if ($s->at('-d0')) { # at the beginning of the day
...
}
if ($s->at('-d2s')) { # at the end of the day, switching user
...
}
perl atSched.pl -runmod atarg
-set (default) add/replace scriptic schedule into system schedule
-setdel clear scriptic schedule from system schedule
-run atarg running 'atarg' entry from system scheduler
-surun atarg running 'atarg' entry switching user
-svcinst install scriptic schedule as win32 service to switch user
-svcinst user password
-svcdel remove scriptic schedule win32 sevice
-logask filter and display log file
-run name arg... running as named command line,
-surun name arg... user may be switched
-a run at any '-run'/'-runsu'
-s run switching user
-w redirect stdout and stderr into log file
-d0 -d1 -d2 at day begin, middle, end
-n0 -n1 -n2 at night begin, middle, end

The purpose of this module is to implement a scriptic schedules or scripts for scheduling and executing Perl codes inside.
A benefit of this module is preliminary for Win32 platform with 'at' commands and impersonations, then for UNIX where 'crontab':
* Keeping persistent or significant scheduled commands in a file (at, -set).
* Automatically filling repeating scheduler arguments (at).
* Running impersonated (switched user, -s).
* Logging of execution (-dirv, -w, runlog, vfname).
* Scheduling relative at day or night begin/middle/end (-d0,-d1,-d2,-n0,-n1,-n2).
* Scheduling cyclic tasks (soon)
* Scheduling at operating system startup (-s,0).
This module is implemented and tested with Perl 5.6.0 on Windows 2000.

Usually no options need to be mentioned in a scriptic schedule.
=>8
=>12
=19
Day begin, middle, end hour. See also AT OPTIONS, -n0, -n1, -n2.
=> base directory
Base directory of script execution, filled automatically using $0.
=> directory marker sign
Directory marker, '/' or '\', filled automatically using $0 or $^O.
=> variables directory
Directory for log and flag files. Default is existing '-dirb/var' subdirectory, or -prgcn will be created. Log file automatic truncation implemented, see -logmax.
=> about 1024*1024 | false
Maximum size of log file, bytes. Used for automatic truncation.
=>22
=>0
=5
Night begin, middle, end hour. See also AT OPTIONS, -d0, -d1, -d2.
=> f($0)
Common name of script, used also in -dirv subdirectory, filled automatically using $0.
=> f($0)
Full file name of script, filled automatically using $0.
=> f($0)
Short file name of script, used also as win32 service name (-svcinst), filled automatically using $0.
=> run mode
Run mode of script. To be obtained from command line.
See also RUN MODES.
=> schedule arguments escaped
Schedule entry to be executed while some -runmod (-run, -runsu). To be obtained from command line.
=> time()
=> localtime()
Time and localtime when script started

The main methods are new and at.
Header of scriptic schedule entry. Or scriptic schedule entry itself, if sub{} given. Allows execution of entry if -run or -runsu. Or sets corresponding system scheduler entries if -set.
Special entryName '0' is intended for operating system startup event (may be implemented, i.e., as a result of -svcinst).
See also AT OPTIONS, soon.
Changes Windows user and service password. Service name estimated is -prgsn. Default user is -prgcn. Default password is autogenerated. Additional computers and/or services will be processed after local, treating empty computer as local and empty service as -prgsn.
Implemented for Windows only, Windows Resource Kit used.
This is an utility methods from Sys::Manage::CmdFile may be useful sometimes.
cmdfile proceeds text file interpreting rows as commands for script or sub{} and moving rows proceeded to history file if given.
cmdfck checks commands file for command rows present. If commands found, executes script or sub{} given once, for file names.
Examples with Sys::Manage::Cmd script:
$s->runlog('perl', './bin/smcmv.pl', '-vct', '-gx', 'cmdfile'
, './var-cmd/cmd-night-do.txt', 'cmd-night-done.txt','cmd-log.txt');
$s->cmdfile(sub{$s->runlcl("perl ./bin/smcmv.pl -vt $_") ||die $?>>8}
, './var-cmd/cmd-night-do.txt', 'cmd-night-done.txt','cmd-log.txt');
$s->cmdfck(sub{$s->runlcl("perl ./bin/smcmv.pl -vct -gx cmdfile $_")}
, './var-cmd/cmd-night-do.txt', 'cmd-night-done.txt','cmd-log.txt');
$s->cmdfck(sub{$s->runlog("perl ./bin/smcmv.pl -vct -gx cmdfile", @_)}
, './var-cmd/cmd-night-do.txt', 'cmd-night-done.txt','cmd-log.txt');
$s->runlog('perl', './bin/smcmv.pl', '-vct', '-gx', 'cmdfile'
, './var-cmd/cmd-night-assign.txt', '""', 'cmd-log.txt');
$s->runlog('perl', './bin/smcmv.pl', '-vct', '-gx', 'cmdfile'
, './var-cmd/cmd-night-sched.txt', '""', 'cmd-log.txt');
Suppresses STDIN, STDOUT, STDERR and calls setsid. See perlipc.
Truncates file to -logmax, if greater then.
Reads file and returns content as a string.
Writes file or appends to it.
DNS domain, host, node name of this computer.
Filter log file. Options: 'v'erbose output (default), 's'tring return (for function call); '>=' or '<=' start and end conditions (default), '>' or '<' conditions. Start and End: 'yyyy-dd-mm...' row sample; /[\d]+[dhm]/ - days, hours, minutes ago. Query: 'all' (default), 'pid's running, 'err'ors, expression.
Creates new Sys::Manage::Schedule object. See also set syntax.
Prints STDOUT with $|=1. May be useful where output redirections.
Executes operating system command alike system(). Using runlcl, only command line and exit code will be logged. For runlog redirection, IPC::Open3 used, instead of immediate STDOUT/STDERR redirection in -w.
Retrieves and sets values of the SLOTS. $s->{-option} direct access may be used also, but set smartly processes some options.
Cyclic entry in scriptic schedule. Sub{} will be executed after seconds given since its previous execution. The first sub{} execution depends on the script executions.
Implemented for Windows only.
See also at, -i, -s, -w.
Schedules command line given with delay, -i option is available. Alike 'soon' utility in Windows Resource Kit.
File name, based on -dirv, -dirm, -prgcn. Log file name is vfname('log.txt'); lock file name is vfname('lck.txt'); Additional lock file name is vfname('lcs.txt'); -d0 flag file name is vfname('d0.txt'). This method may be useful forming names of additional log files.

at call options considered as a first argument beginning with '-' sign. Several options may be catenated into options string without additional '-' signs.
Execute at any -run ('-a') or -runsu ('-as').
Execute daily at the beginning/middle/end of the day, or nightly at the beginning/middle/end of the night. Only one of this options may be included in each at.
Execute interactivelly, Only for soon and -d0 etc.
-s,0)Execute switching user (-runsu).
On Win32 user may be switched using impersonated service (installed via -svcinst), or via WMI (-susr and -spsw required).
On other platforms 'su' is called by 'root', 'sudo' otherwise.
Special at('-s',0) form means automatic win32 service startup at operating system startup.
Write (redirect) STDOUT/STDERR into log file. See better runlog, instead of -w, which may not work sometimes.

Usually operator need not deal with any run mode, because -set is default, when empty arguments.
The mainly used run modes are -set, -setdel, -run, -surun/-runsu.
Supplemental run modes are -logask, -svcinst, -svcdel.
Filter and display log file, see logask.
Run -runarg entry.
Run -runarg entry after user switched (-surun, -s option of at).
Remove existing scriptic schedule entries (recognized using -prgfn) from the system schedule ('at' or 'crontab'). Add actual scriptic schedule using at method calls resulting in 'at' or 'crontab' calls.
Remove existing scriptic schedule entries (recognized using -prgfn) from the system schedule ('at' or 'crontab').
Remove -prgsn win32 service.
See also -svcinst.
Create -prgsn win32 service using 'instsrv' and 'srvany' from Windows Resource Kit. Additional command line arguments are user name and password.
Service may be needed to switch user (-s, -runsu).
Service may be deleted using -svcdel.
Settings of service created should be checked.
Switch user and execute -runsu -runarg (-s option of at).

Named command lines implemented: perl atSched.pl -run|-surun name arg...
soon extended to accept program arguments as list.
So, schedule script may be used also to log some unforeseen commands.
Changed format of log file and messages.
-logpid removed - use logask command instead.
New fread, hostdomain, hostname, hostnode methods.
Behaviour of -logpid files improved, content changed, cleanup implemented.
$ENV{SMSECS} may be used for cmdfile and cmdfck.
New -logpid to create runtime pid file for monitoring and diagnostics during runtime.
New cmdfck method.
Published 0.50 version.
Started

This is free software; you can use redistribute it and/or modify it under the same terms as Perl itself.

Andrew V Makarow <makarow at mail.com>, for tav