0

Hello everybody!

What I want to do:

I want to set an at exactly 24 hours after a given $timestamp from a Perl Script.

My problem is:

Every time I look the manual or a tutorial, the command redirect us to a shell which will record te command we want to executeSince the data I want to insert in ($link to file, $timestamp ...) are dynamic how can I set up at command directly from script? It would be great if it was with system("at -obscure -guru -options -t $dateline command");

EDIT: From CRON we are talking now about at which seems more appropriate to the problem thanks inna

torr
  • 1,256
  • 3
  • 11
  • 20
  • Try `at` instead of cron. Or step back and tell is why you need this. – innaM Jul 07 '13 at 12:02
  • That looks pretty good. Now try `man at`. – innaM Jul 07 '13 at 16:28
  • Try to read the question. I have dynamic data in argument, if I use the -f option how will I transmit these data? – torr Jul 07 '13 at 22:06
  • How are the files or "links" accessed? If the files should not be accessible 24 hours after creation then you method of access control should be checking the age of the file when access is requested. Then a `cron` job executing less frequently can sweep the files periodically. – G. Cito Jul 08 '13 at 00:33
  • Actually I'm not sure I understand the question - generally you use `at` to handle the timed execution of a script that handles locating the "dynamic data" and executing whatever commands you want to use to process it (deletion, etc). – G. Cito Jul 08 '13 at 00:33
  • I would do this `system("at 'rm -vf $link'"); – torr Jul 08 '13 at 10:11

1 Answers1

2

Whenever possible, use a CPAN module to solve your task. Just use https://metacpan.org/ to search the list of modules. In this case, searching for "at" return (among others) Schedule::At. It can be used like this:

use strict;
use warnings;

use Schedule::At;
use Date::Format;

my $file_to_delete = '/tmp/some_file';
my $at_time        = time2str( '%Y%m%d%H%M%S', time + 24 * 60 * 60 );
my $at_command     = sprintf 'rm %s', $file_to_delete;
Schedule::At::add(TIME => $at_time, COMMAND => $at_command );
innaM
  • 47,505
  • 4
  • 67
  • 87