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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-25-2009, 03:28 PM
|
#1
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Rep:
|
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
|
|
|
11-25-2009, 03:51 PM
|
#2
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
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]);
|
|
|
11-25-2009, 03:52 PM
|
#3
|
Member
Registered: Nov 2009
Posts: 55
Rep:
|
Maybe you should use at for that.
|
|
|
11-25-2009, 04:04 PM
|
#4
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
Quote:
Originally Posted by Chirel
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?
|
|
|
11-25-2009, 04:38 PM
|
#5
|
Member
Registered: Nov 2009
Posts: 55
Rep:
|
Please
man at
|
|
|
11-25-2009, 04:49 PM
|
#6
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
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
|
|
|
11-25-2009, 06:19 PM
|
#7
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,404
|
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.
|
|
|
11-25-2009, 09:10 PM
|
#8
|
Moderator
Registered: Aug 2002
Posts: 26,265
|
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.
|
|
|
11-26-2009, 04:25 PM
|
#9
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
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?
|
|
|
11-26-2009, 04:30 PM
|
#10
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
never mind that last post, i just got
echo "ls -li" | at -t 200911262228
to work.. I will do some more testing.
|
|
|
11-26-2009, 04:57 PM
|
#11
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
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 05:02 PM.
|
|
|
11-26-2009, 05:03 PM
|
#12
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
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.
|
|
|
11-26-2009, 05:39 PM
|
#13
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
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.
|
|
|
11-26-2009, 06:02 PM
|
#14
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Quote:
Originally Posted by pungsnurr
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
|
|
|
11-26-2009, 06:12 PM
|
#15
|
LQ Newbie
Registered: Nov 2009
Posts: 10
Original Poster
Rep:
|
Thank you so much Tink, this works.
|
|
|
All times are GMT -5. The time now is 07:47 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|