LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 08-19-2014, 11:33 PM   #1
mdesh
LQ Newbie
 
Registered: Aug 2014
Posts: 4

Rep: Reputation: Disabled
Submit a job or command at fix interval in hh:mm:ss


Hi,

I want to submit few jobs at fixed interval which is in hh:mm:ss format.

I created a script and able to submit the job by setting the crontabs. The number of crontabs will be equal to the number of jobs. But while submitting a job using crontab, the job is getting submitted in mm:hh:date:month:week format. Its not taking complete submit time format in hh:mm:ss format.

So is there any way that I can submit the jobs exactly using hh:mm:ss format.

Thanks

Mdesh
 
Old 08-19-2014, 11:58 PM   #2
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
I do not know of a tool that literally takes hh:mm:ss as its argument, but there is 'sleep', which takes seconds or minutes or hours. You could write a simple wrapper script to convert your input from hh:mm:ss to just seconds:

Code:
#!/bin/bash

H=$(echo $1 | cut -f1 -d":" )
M=$(echo $1 | cut -f2 -d":" )
S=$(echo $1 | cut -f3 -d":" )

HM=$(echo "$H * 60" | bc)
TM=$(echo "$HM + $M" | bc)
TS=$(echo "$TM * 60" | bc)
TOTAL=$(echo "$TS + $S" | bc)
echo $TOTAL

sleep $TOTAL && $2
That's pretty basic but it does the trick, ie, if I enter

./myscript.sh 00:01:14 'echo "hello world"'

then the shell waits for 74 seconds and then runs 'echo "hello world"' as expected.

If I run
(./myscript.sh 00:01:14 'echo "hello world"')
then it all happens in a subshell so I don't have to watch it sit there and wait. Not sure what your use case is.
 
Old 08-20-2014, 03:06 PM   #3
pwalden
Member
 
Registered: Jun 2003
Location: Washington
Distribution: Raspbian, Ubuntu, Chrome/Crouton
Posts: 374

Rep: Reputation: 50
Try the "at" command.

at 4:23:33 PM <<EOF
my-command
next-command
EOF

at 16:22:01 <<EOF
another-command
EOF
 
1 members found this post helpful.
Old 08-21-2014, 06:49 AM   #4
bulrush15
LQ Newbie
 
Registered: Jul 2014
Location: West Michigan
Posts: 29

Rep: Reputation: Disabled
The 'at' command runs a job once at the time you specify. You can even run the job on a later day. If the time has passed, it will run the job the next day.

Using cron, you can run jobs every ten minutes, once a day, once an hour, etc. Do 'man crontab' for info and 'man 5 crontab' for the file format.

Make sure the user 'root' is in the /etc/cron.allow file! No documents I found mentioned this part.

Last edited by bulrush15; 08-21-2014 at 06:50 AM.
 
Old 08-21-2014, 08:28 AM   #5
pwalden
Member
 
Registered: Jun 2003
Location: Washington
Distribution: Raspbian, Ubuntu, Chrome/Crouton
Posts: 374

Rep: Reputation: 50
Quote:
Originally Posted by bulrush15 View Post
The 'at' command runs a job once at the time you specify. You can even run the job on a later day. If the time has passed, it will run the job the next day.
Sounded like the hh:mm:ss format was the most important thing, which crontab files do not use. The requirements are not very clear.
 
  


Reply



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
submit job in cluster hoi Linux - Newbie 4 10-03-2013 11:32 AM
Submit LSF (bsub) job with SSH X11 forwarding ZvikaZ Linux - Enterprise 0 09-15-2011 08:13 AM
submit job to queue Jerry Mcguire Programming 2 05-16-2011 09:12 PM
Cron job that needs to run at kind of an odd interval Norwood Linux - Software 3 05-09-2010 10:18 AM
submit job 2 processors Patricia Linux - Newbie 1 06-30-2004 02:21 PM

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

All times are GMT -5. The time now is 11:05 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