LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cron, run at yyyy-mm-dd hh:ii:SS? (https://www.linuxquestions.org/questions/linux-newbie-8/cron-run-at-yyyy-mm-dd-hh-ii-ss-771531/)

pungsnurr 11-25-2009 02:28 PM

cron, run at yyyy-mm-dd hh:ii:SS?
 
Hey, so I've searched these forums, and google, but all I find is how to run a script every 5 seconds, or something like that. But that is not what I'm looking to do.

Say I want to launch a command at 2009-11-30 at 21:04:22 (yes, with seconds). How would I go about to launch this, as cron doesn't take seconds.
I've read about making scripts that loops every 1 second or so, but I'm not sure of how to do that.


What I would like to do is make a php-script that adds dates+times to launch specific command into cron?

Hope you understand what I mean. Any help appreciated.

-p

pungsnurr 11-25-2009 02:51 PM

Maybe this should work, (for 2009-11-30 at 21:04:22 as in OP)

in cron:


Code:

04 21 30 11 sleep 22; /runthis
or

Code:

04 21 30 11 php runthis.php 22
and in runthis.php

PHP Code:

sleep($argv[1]); 


Chirel 11-25-2009 02:52 PM

Maybe you should use at for that.

pungsnurr 11-25-2009 03:04 PM

Quote:

Originally Posted by Chirel (Post 3769607)
Maybe you should use at for that.

Hello, and thanks for your reply.

I didn't know about that command :redface:

I tried this:
Code:

> at 2009-11-25 22:01:05 echo hello
but got:
Code:

syntax error. Last token seen: 22:01
Garbled time

how's the syntax supposed to be?

Chirel 11-25-2009 03:38 PM

Please :)

man at

pungsnurr 11-25-2009 03:49 PM

well it didn't make any sense.

It said i should be able to type something like MMDDYY or HH:MM.

I didn't get it to work cause there was nothing there explaining the syntax. I tried:

at MMDDYY HH:MM
but that didn't work.. but I should have used:

at HH:MM MMDDYY
which seems to work.



But there are still no seconds in At? just like cron :(

chrism01 11-25-2009 05:19 PM

The cron + sleep 22 seconds is prob going to be the easiest. Note that cron is used when you want a process to run repeatedly over time. at is for one shot processes.

As per the man pages
http://linux.die.net/man/1/at
http://linux.die.net/man/5/crontab

you can only specify a starting time to the nearest minute.

michaelk 11-25-2009 08:10 PM

FYI one can not be absolutely sure that a job will start at precisely 00 seconds. In addition jobs are executed in a top down fashion so the order of tasks in the crontab file will be important if you have multiple jobs that run at the same minute.

pungsnurr 11-26-2009 03:25 PM

Thank you all for your replies. I have gotten so far now that I am executing

php /var/www/test.php | at -t 200911262230

the problem with this is that it runs the command when I hit Enter, not when it reaches 2009-11-26 22:30.

What am I doing wrong here?

pungsnurr 11-26-2009 03:30 PM

never mind that last post, i just got

echo "ls -li" | at -t 200911262228

to work.. I will do some more testing.

pungsnurr 11-26-2009 03:57 PM

this is really weird..


first: dummy.php
PHP Code:

<?php 
    
if (isset($argv[1])) sleep($argv[1]);
    print 
"echo \"dummy has been run!\"";
?>

this command:
Code:

php /var/www/auto/dummy.php 10 < /dev/null | at -t 200911262256
when I hit enter after entering the above, it will take 10 seconds before i get back to prompt, which means it does the sleep(10) from the php-script directly? Or am I missing something? Is it supposed to act like this?

pungsnurr 11-26-2009 04:03 PM

Code:

sleep 10; php /var/www/auto/dummy.php < /dev/null | at -t 200911262256
acts in the same manner by the way. Sleeps 10, then showing that the command was added to at.

pungsnurr 11-26-2009 04:39 PM

so, doing it like this:

Code:

x@x:/> at -t 200911262336
at> /usr/bin/php /var/www/dummy.php 10
at> <EOT>
job 55 at Thu Nov 26 23:36:00 2009

is giving me the result I'm expecting. So I guess it's some error in my syntax when I try to do all this in 1 line.

Can someone point me in the right direction here, cause I'm lost.
/usr/bin/php /var/www/dummy.php 10 | at -t 200911262336

is not working.

Tinkster 11-26-2009 05:02 PM

Quote:

Originally Posted by pungsnurr (Post 3770726)
so, doing it like this:

Code:

x@x:/> at -t 200911262336
at> /usr/bin/php /var/www/dummy.php 10
at> <EOT>
job 55 at Thu Nov 26 23:36:00 2009

is giving me the result I'm expecting. So I guess it's some error in my syntax when I try to do all this in 1 line.

Can someone point me in the right direction here, cause I'm lost.
/usr/bin/php /var/www/dummy.php 10 | at -t 200911262336

is not working.


Because you're tying to feed the output of the the command to at.
What you WANT to do is:
Code:

echo "/usr/bin/php /var/www/dummy.php 10"| at -t 200911262336


Cheers,
Tink

pungsnurr 11-26-2009 05:12 PM

Thank you so much Tink, this works.


All times are GMT -5. The time now is 03:34 PM.