crontab question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting crontab question
# 1  
Old 12-24-2011
crontab question

If I want to run a process every 30 mins except for 3-4 where I want to run
every 5 mins I know I can do this with 3 entries.

Code:
 
30 5-23 * * * "echo "Hello"
30 0-3 * * * "echo "Hello"
5,10,15,20,25,30,35,40,45,50,55 3-4, * * * "echo Hello"

Can this be done with less entries
# 2  
Old 12-24-2011
I think that is as simple as that solution gets. I'll keep it in the corner of my mind and come back if anything pops up.
# 3  
Old 12-24-2011
Note: echo hello is NOT something you would crontab - I'm assuming you know that.
crontab processes do not have a terminal, for example.

one way move timing inside the script you evoke in crontab -
Code:
#!/bin/bash
# this file == /path/to/timer.sh
hour=$(date +%H)
minute=$(date +%M)
if [ $hour = "03"  || $hour = "05" || $minute = "30" ] ; then
 #  /path/to/your/script    i.e., put your code here
fi

Code:
0 0,5,10,15,20,25,30,35,40,45,50,55 * * * /path/to/timer.sh

# 4  
Old 12-24-2011
A script to evoke his task from cron is not more elegant, it uses more memory and just isn't simplification but outsourcing to bash.

Last edited by John Tate; 12-24-2011 at 02:41 PM.. Reason: im a fool
# 5  
Old 12-24-2011
Quote:
30 5-23 * * * "echo "Hello"
30 0-3 * * * "echo "Hello"
These crons do not process every 30 mins. They process every hour. All the lines which contain three double-quote characters are syntax errors.
Please clarify.

Quote:
5,10,15,20,25,30,35,40,45,50,55 3-4, * * * "echo Hello"
This cron does not process every 5 mins between 3 and 4. More like 3 and 5 (but missing out exact hours).
The extra comma in "3-4," makes that line a syntax error too.
Please clarify.


Sorry, but you are asking us to simplify something which does not conform to specification at all. Also, all three lines contain syntax errors.


To answer your original question. Yes, it can be done with TWO entries (and no special Shell or whatever).
One cron to run every 30 mins and one cron to fill in the extra 5 mins intervals.
Code:
0,30 0-23 * * * echo "Hello"
5,10,15,20,25,35,40,45,50,55 3 * * * echo "Hello"


Last edited by methyl; 12-25-2011 at 06:02 AM.. Reason: Added a solution
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question on crontab

Hello, I have scheduled the execution of a file (delete_oldv02) every hour with crontab and it works perfectly. See below the instruction written. 0 */1 * * * /home/delete_oldv02 >>/home/delete_oldv02.log My first question is if I can add one more line to crontab. I also would like to... (5 Replies)
Discussion started by: dcaccount
5 Replies

2. Shell Programming and Scripting

Crontab question

I need to run an script every 10th and 25th day in every month at 11pm. the script name is /home/ss/automated.sh I tried to execute the script every day and everytime with the below syntax. its not executing it from crontab. * * * * * /home/ss/automated.sh Any idea why it not... (6 Replies)
Discussion started by: ramkumar15
6 Replies

3. UNIX for Dummies Questions & Answers

Another crontab question

Hey out there This is all I have in my crontab file. I know the crontab works because it was already out there and working. I simply replaced the existing with my line of code below to see if it worked. I uploaded 6 month old pdf files in this directory, stopped/started all the scripts that... (3 Replies)
Discussion started by: vsekvsek
3 Replies

4. Shell Programming and Scripting

crontab question

I have a user (xxx) who is allowed to run cron jobs when a job is launched from cron is the .profile sourced in? I am not sure it is so I setup a cron job as this user to do the following: 35 15 * * 0-5 su - xxx -c "ksh ls -lt /tmp" > /tmp.out and I am seeing the following error (see... (2 Replies)
Discussion started by: BeefStu
2 Replies

5. HP-UX

Crontab question

Please cna you tell me if the following command entered in error would affect the crontab file crontab -e | more Thanks :) (12 Replies)
Discussion started by: blondie2407
12 Replies

6. UNIX for Dummies Questions & Answers

Question about crontab

Hello guys, I have a server with Red Hat Enterprise Linux AS release 4 (Nahant Update 5), there i have a lot of users, im the root. I need to lock the use of crontab to the users, i mean, i dont want to give to the users the option to creat any crontab line, how can i do that? I tried to... (4 Replies)
Discussion started by: lestat_ecuador
4 Replies

7. AIX

How-to crontab question

My question is how to specify the one-time execution of a shell script in crontab? For example: If I wanted to schedule shell "Test.sh" for one-time execution on December 13 at 8:00AM would it be as follows? 00 08 13 12 6 /usr/datatools/dtbackups/Test.sh > /usr/u/sybase_12.5/logs/Test.log &... (3 Replies)
Discussion started by: Alan.AIX
3 Replies

8. UNIX for Dummies Questions & Answers

Crontab Question.

I set up a job to run a script in a certain directory to remove certain files. The script seems to run as my logs indicate but nothing happens. If I run the script manually then it removes the correct files. I'm now wondering if crontab doesnt have access to remove files from the directory I'm... (9 Replies)
Discussion started by: NycUnxer
9 Replies

9. Solaris

Crontab question

HI all, I would want to schedule a job to run every 2 weeks. In the mean time, i'm only able to schedule on every week. Is it possible to schedule 2 weeks on crontab? Thank you. (3 Replies)
Discussion started by: *Jess*
3 Replies

10. UNIX for Dummies Questions & Answers

crontab question

Why does this cron entry do nothing? It works interactively. 58 23 * * * mydate=`date '+%Y%m%d'`;mv /opt/home/user/file /opt/home/user/file_$mydate (5 Replies)
Discussion started by: steelrose
5 Replies
Login or Register to Ask a Question