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 -runsu 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
-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).
at
-set
* Automatically filling repeating scheduler arguments (at).
* Running impersonated (switched user, -s).
-s
* Logging of execution (-dirv, -w, runlog, vfname).
-dirv
-w
runlog
vfname
* Scheduling relative at day or night begin/middle/end (-d0,-d1,-d2,-n0,-n1,-n2).
-d0
-d1
-d2
-n0
-n1
-n2
* Scheduling cyclic tasks (soon)
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.
AT OPTIONS
=> 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.
-dirb
-prgcn
-logmax
=> about 1024*1024 | false
Maximum size of log file, bytes. Used for automatic truncation.
=> true | false | pid file name
Create runtime pid file for monitoring and diagnostics during runtime.
=>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.
Full file name of script, filled automatically using $0.
Short file name of script, used also as win32 service name (-svcinst), filled automatically using $0.
-svcinst
=> run mode
Run mode of script. To be obtained from command line.
See also RUN MODES.
RUN MODES
=> schedule arguments escaped
Schedule entry to be executed while some -runmod (-run, -runsu). To be obtained from command line.
-runmod
-run
-runsu
=> time()
=> localtime()
Time and localtime when script started
The main methods are new and at.
new
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.
-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.
cmdfile
cmdfck checks commands file for command rows present. If commands found, executes script or sub{} given once, for file names.
cmdfck
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.
Creates new Sys::Manage::Schedule object. See also set syntax.
set
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.
runlcl
Retrieves and sets values of the SLOTS. $s->{-option} direct access may be used also, but set smartly processes some options.
SLOTS
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.
-i
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.
-dirm
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 or -runsu.
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, soon only.
Execute switching user (-runsu).
On Win32 user may be switched using impersonated service (installed via -svcinst), or via WMI (-susr and -spsw required).
-susr
-spsw
On other platforms 'su' is called by 'root', 'sudo' otherwise.
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, -runsu.
-setdel
Supplemental run modes are -svcinst, -svcdel.
-svcdel
Internal run mode is -surun
-surun
Run -runarg entry.
-runarg
Run -runarg entry switching user (-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.
-prgfn
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. Used internally for transition from system scheduler.
New fread, hostdomain, hostname, hostnode methods.
fread
hostdomain
hostname
hostnode
Behaviour of -logpid files improved, content changed, cleanup implemented.
-logpid
$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
To install Sys::Manage::Cmd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sys::Manage::Cmd
CPAN shell
perl -MCPAN -e shell install Sys::Manage::Cmd
For more information on module installation, please visit the detailed CPAN module installation guide.