LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-25-2009, 02:28 PM   #1
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Rep: Reputation: 0
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
 
Old 11-25-2009, 02:51 PM   #2
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
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]); 
 
Old 11-25-2009, 02:52 PM   #3
Chirel
Member
 
Registered: Nov 2009
Posts: 55

Rep: Reputation: 19
Maybe you should use at for that.
 
Old 11-25-2009, 03:04 PM   #4
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Chirel View Post
Maybe you should use at for that.
Hello, and thanks for your reply.

I didn't know about that command

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?
 
Old 11-25-2009, 03:38 PM   #5
Chirel
Member
 
Registered: Nov 2009
Posts: 55

Rep: Reputation: 19
Please

man at
 
Old 11-25-2009, 03:49 PM   #6
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
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
 
Old 11-25-2009, 05:19 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
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.
 
Old 11-25-2009, 08:10 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
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.
 
Old 11-26-2009, 03:25 PM   #9
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
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?
 
Old 11-26-2009, 03:30 PM   #10
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
never mind that last post, i just got

echo "ls -li" | at -t 200911262228

to work.. I will do some more testing.
 
Old 11-26-2009, 03:57 PM   #11
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
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?

Last edited by pungsnurr; 11-26-2009 at 04:02 PM.
 
Old 11-26-2009, 04:03 PM   #12
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 11-26-2009, 04:39 PM   #13
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 11-26-2009, 05:02 PM   #14
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by pungsnurr View Post
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
 
Old 11-26-2009, 05:12 PM   #15
pungsnurr
LQ Newbie
 
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thank you so much Tink, this works.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Format dd/mm/yyyy in Suse 10.0 via Webmin collabcomp Linux - Newbie 2 09-15-2007 11:34 PM
What does the [xxx:yyyy] part of the iptables script mean? trewsfan Linux - Networking 1 09-29-2006 06:01 PM
logrotate mishandles files with YYYY-MM-DD extension dthacker Linux - General 0 08-20-2004 09:53 AM
trying to get cron to run naijaguy Linux - General 12 08-18-2004 05:32 PM
Open Office Sorting by HH:MM:SS DD MMMM YYYY toddydog Linux - Software 2 08-10-2003 06:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration