|
|
Question : ouput when starting perl-script with at-command
|
|
Hi!
I start my script with: "echo NOHUP myscript | at now"
I want the script to write to STDOUT from time to time, and this output should be sent to the user by the at-daemon. The only way I managed to do this, was "`echo echo OUTPUT | at now 2>/dev/null`;" - but I can't believe that this is the best way!!!
Any idea? thx michi
Here my test-script: 4 mails are generated: at-child, at-parent, END and general STDOUT.
use POSIX; our $goon=1; my $parent=$$;
sub finish{ print "Finish\n"; if ($pid=fork()){wait;} else{ `echo echo END | at now 2>/dev/null`; exit(0); } $goon=0; }; $SIG{TERM}=\&finish; $SIG{INT}=\&finish; $SIG{HUP}=\&finish;
if ($pid=fork){ wait; }else{ print "print-child START PID: ${parent}${/}"; `echo echo at-child START PID: ${parent} | at now 2>/dev/null`; exit(0); } `echo echo at-parent START PID: ${parent} | at now 2>/dev/null`; while ($goon){ print "JobOutput: MyPID: $$ $/"; sleep 3; } print "OUT OF LOOP$/";
|
Answer : ouput when starting perl-script with at-command
|
|
I'm beginning to get a glimmer. You want the stdout to be delivered by email piecemeal, while the script is still running?
This leads to a couple of requirements:
1) the STDOUT for the script must be set up to be line-buffered, if you can't otherwise set up a periodic flush in the program that is to be running. One way to do this is to run under the control of 'Expect', either the tcl program or perhaps via the Perl Expect module.
2) You can have the STDOUT written to a file that gradually grows. Its growth would be monitored by another script or program that kept track of the previous length and simply sent off, via email, whatever new output had accumulated in the interval since the last report. - OR -
2) You can do the periodic monitoring in the script that fired things off, without creating a cumulative log file. Either way, you can still fire off periodic emails with the new output.
3) Perl scripts (and the programs executed from them) can be set up to be "detached" or "background" just as well as commands run under 'at'. Since you have one long-running process involved, I'm a little unclear on how robust the solution has to be around it. Must the reporting apparatus recover from a system restart? Will it need to be in charge of restarting the long-running process from its last reported position?
While none of this is particularly complex, it is more, I think, than cobbling together a couple of lines of shell or perl to have it do what you have asked. The 'at' command might or might not play a role in the solution. The Perl module File::Tail might contain part of a solution or you might find that the POE component FollowTail
http://search.cpan.org/~rcaputo/POE-0.2802/lib/POE/Wheel/FollowTail.pm
does a lot of what you want -- if you can just put together the POE pieces needed to make it work.
|
|
|
|
|