Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Here is a puzzle I hope you can help me with. A client wants to send a welcome letter exactly 47 minutes after a document is uploaded via cgi script. I wrote a routine to send the letter, and then I attempted to use the Linux "at" command to execute it.

When this didn't work, I set up the following test in the /cgi-bin directory.


**** The bottom line is: The "at" command will not work when called by apache. Is there any way around this?


Thanks,

Rob Young


TEST FILES
---------------------------------------------------------------------------

$> cat test1.pl
#!/usr/bin/perl
#THIS IS A TEST OF THE "at" LINUX COMMAND WHEN CALLED FROM WITHIN APACHE
print "Content-type: text/html\n\n";
my @lt=localtime(time()+60);
my $cmd="echo '/path/to/test2.pl' | at $lt[2]:$lt[1]";
print $cmd;
system($cmd);

$> cat test2.pl
#!/usr/bin/perl
my $cmd="echo 'it ran!'>it_ran.txt";
system($cmd);




COMMAND LINE DEMONSTRATION
------------------------------------------------------------------
$> rm it_ran.txt
rm: cannot remove `it_ran.txt': No such file or directory
$> ./test1.pl
Content-type: text/html

echo '/path/to/test2.pl' | at 20:28job 55 at 2011-08-15 20:28
$> atq
55      2011-08-15 20:28 a ryoung
$> date
Mon Aug 15 20:27:11 CDT 2011
$> cat it_rat.txt
cat: it_rat.txt: No such file or directory
$> date
Mon Aug 15 20:28:01 CDT 2011
$> cat it_ran.txt
it ran!


APACHE DEMONSTRATION
------------------------------------------------------------------------------------------
Then I call the same script by browsing to http://www.MYSERVER.com/cgi-bin/test1.pl
[browser output:
                  echo '/path/to/test2.pl' | at 20:30
]

$> date
Mon Aug 15 20:30:40 CDT 2011
$> cat it_ran.txt
cat: it_ran.txt: No such file or directory
share|improve this question

1 Answer 1

Specify the full path to at in the script. Not to mention your it_ran.txt file. How do have any idea whatsoever where that file is supposed to be deposited? It's probably trying to get written to the root directory and failing.

You should use error checking. Check the result code of the system command or at itself.

Programs and calls return errors to help you handle exceptions appropriately.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.