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.
|
 |
07-19-2012, 11:11 AM
|
#1
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Rep: 
|
Crontab not working
[root@trixbox127772 ~]# crontab -l
# Update time daily
0 2 * * * /usr/sbin/ntpdate tick.ucla.edu > /dev/null 2>&1
# Ping systems every 15 mins
*/15 * * * * /bin/nice /usr/bin/perl /var/adm/bin/ping_main.pl -randsleep
# Rotate asterisk logs daily
0 0 * * * /usr/sbin/asterisk -r -x 'logger rotate'
# Generate 5-min charts
*/5 * * * * /bin/nice -n 19 /usr/bin/perl /var/adm/bin/rrd_graph.pl
0 0 * * * /var/adm/bin/validation_check.pl &> /dev/null 2>&1
24 5 * * * perl /var/adm/bin/registry.pl &> /dev/null
30 * * * * /bin/nice -n 5 /etc/init.d/FONmon start >> /dev/null 2>> /dev/null
30 * * * * /bin/nice -n 7 /var/adm/bin/sync_linked_greet.pl >> /dev/null 2>> /dev/null
9 4 * * * /etc/webmin/cron/tempdelete.pl
1 * * * * if [ -n "$(/bin/grep Spitfire /etc/asterisk/sip.conf)" ]; then /usr/bin/perl -i.bak -pe 's/Brent Silversmith <235>//g' /etc/asterisk/sip.conf; asterisk -rx 'sip reload'; echo "[$(date)] cronjob: Removed Spitfire from callerid field in sip.conf." >> /var/log/asterisk/messages; fi
That is the result of crontab -l
The last cron tab is not working.. I cant even see any evidence of it trying to run. Can someone help me with trying to get this thing working? And I want this to run every 30 seconds
|
|
|
07-19-2012, 11:34 AM
|
#2
|
Member
Registered: Aug 2004
Location: UK
Distribution: Gentoo, OpenBSD, Debian, FreeBSD, RHEL, CentOS
Posts: 65
Rep:
|
This would run at 1 minute past the hour every hour ( although sometimes it needs to be 01, for example ). Perhaps it was meant to be */1 * * * * ?
I think the best granularity for cron is every minute. I am not aware of anything less.
Looks like a potential job for configuration management like puppet, cfengine etc. but, again, 30s response time is not going to be practical, AFAIK.
Maybe there's a solution to be had with inotify[1] (to check for modifications to sip.conf) so that you only execute your script when a change to the file occurs.
[1] if your system/kernel supports it.
https://github.com/rvoicilas/inotify-tools/wiki/
http://linux.die.net/man/1/inotifywatch
|
|
|
07-19-2012, 11:45 AM
|
#3
|
LQ Newbie
Registered: Jul 2012
Posts: 5
Original Poster
Rep: 
|
After updating it to run once a minute I am still not seeing any evidence of it running 
|
|
|
07-19-2012, 11:49 AM
|
#4
|
Member
Registered: Aug 2004
Location: UK
Distribution: Gentoo, OpenBSD, Debian, FreeBSD, RHEL, CentOS
Posts: 65
Rep:
|
Try creating a new file containing those shell commands and add the script name to the crontab instead. It's going to be more reliable and probably easier to debug.
|
|
1 members found this post helpful.
|
07-19-2012, 05:00 PM
|
#5
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,206
|
for what it is worth
A big "I second that" to placing the commands in a script.
Use the #! line to specify what shell you want it to run under, otherwise it runs in the POSIX mode of the shell presented as /bin/sh.
cron does a great job of scheduling scripts and programs, not so well at acting as a shell or command processor.
|
|
|
07-19-2012, 05:48 PM
|
#6
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,441
|
1. do put that lot in a script eg do it all in Perl instead of calling different external cmds.
2. make the new Perl script a daemon and just have it wait 30s at the bottom of the main loop.
I'd also point out that although you can specify crontab jobs start time to the nearest minute, this entails creating a new process env every call/job and old jobs may overlap with new ones if they don't complete fast enough.
Just put a watchdog process in cron if you are paranoid, set to check every eg 5 mins to see if the daemon is running and restart it if not.
|
|
|
All times are GMT -5. The time now is 04:04 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
|
|