LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-07-2012, 08:12 AM   #1
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Rep: Reputation: 47
hourly cronjob not working


I have used 'sudo crontab -e' to put following line:

0 * * * * for((i=0;i<4;i++)) do aplay up.wav; sleep 5s; done


I want it to play this wave file 4 times at every hour. But it is not working. Please help.
 
Old 03-07-2012, 08:22 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
ouch, nasty. Put the commands into a script, make sure that script works and then run the script from cron. For hourly jobs you should have a directory /etc/cron.hourly which you can just drop files in and they will then be executed hourly automatically.
 
Old 03-07-2012, 09:47 AM   #3
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
Anything I need to do if the script file has to be with an argument, eg: 'myscript.sh 15'. Do I enclose the full command in quotes or double quotes?
 
Old 03-07-2012, 09:51 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no, you don't or it will take the entire string as an executable name and choke.

0 * * * * /bin/bash /full/path/to/my/script.sh 12345

or for /etc/crontab:

0 * * * * root /bin/bash /full/path/to/my/script.sh 12345
 
Old 03-07-2012, 10:03 AM   #5
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
Thanks. But why did you find the the small script on command line so "ouch, nasty"? Also what is difference between modifying cron using 'sudo crontab -e' and through /etc/crontab ?
 
Old 03-07-2012, 10:07 AM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
I find running stuff in crontab can be confusing, and it's easy to be unclear where you are starting from. Your code is bash / sh but cron doesn't execute code within a shell, it's just directly run without a fully formed environment to utilize. So by saying "run this script with bash" as the cron instruction you can quickly get back to a common point that you can also get to from a normal login shell. Just much simpler that way.

as root, crontab -e will edit the root users crontab file in /var/spool/cron (or similar). this is different to the system crontab file in /etc/crontab. Personally I don't ever use roots crontab file, as it's so easy to forget about, and isn't anything root wants to do actually being done for the system as a whole, not him (or her) self?
 
Old 03-07-2012, 10:37 AM   #7
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
Following crontab entry is also not working:

Code:
0 *  *   *   *    /bin/bash  ~/chimer.sh 4
where chimer.sh is as follows:
Code:
#! /bin/bash
for((i=0;i<$1;i++)) 
do 
	aplay up.wav
done

Last edited by rng; 03-07-2012 at 10:53 AM.
 
Old 03-07-2012, 10:42 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
what user is this? what crontab is it in? I wouldn't think it relevant, but I would replace ~ with the real path, for clarity if nothing else.
 
Old 03-07-2012, 10:53 AM   #9
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
I have replaced ~ with full pathname which is /home/home/ here.

I am not sure about "what crontab". I am using command 'sudo crontab -e' and modifying the commands. I am using ubuntu 10.04LTS. And I find the changes are incorporated in /var/spool/cron/crontabs/root file.

Thanks for helping me.

Last edited by rng; 03-07-2012 at 11:03 AM.
 
Old 03-07-2012, 11:03 AM   #10
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Ahh, I meant /etc/crontab vs crontab -e as the files are a different format. Does the script itself work if you manually execute the exact same cron command (including the bash bit) ?
 
Old 03-07-2012, 11:16 AM   #11
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
The script itself works very well. I have not tried /etc/crontab but my problem is solved after I used the command 'crontab -e' (without sudo). Now it is working well. Earlier it must have been going to the root's crontab and I am not working as root most of the time.


@acid_kewpie: Thanks for your help. I realize that you have great experience in linux with almost 39000 posts here. I see that gentoo is your top distribution. How difficult is gentoo for an ubuntu user to migrate to. Is software installation and dependency resolution major problems there? If you want I will put this question as a separate thread.

Last edited by rng; 03-07-2012 at 11:31 AM.
 
Old 03-07-2012, 11:27 AM   #12
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
it shoudl be a different thread really, but Gentoo is pretty easy really. I've not used it for a while, but the installation guide was always pretty simply, as long as you follow the right steps. It works differently low down to ubuntu, or any other distro I've used, but it's certainly worth a go.
 
Old 03-07-2012, 11:32 AM   #13
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
Just one last question:
The /etc/crontab files looks very similar, only I would need to enter the user name also:
Quote:
0 * * * * home /bin/bash /home/home/chimer.sh 3
Please confirm.
 
Old 03-07-2012, 04:10 PM   #14
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
yes, but who calls a user "home"??
 
Old 03-07-2012, 07:26 PM   #15
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
Haha! I created the user home for my home computer, without realizing that all users are in /home directory in linux. So my home directory is /home/home. However, I have not had any problems with any programs, except one which refused to save data in 'home' directory!
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cronjob is not working loveulinux Linux - Newbie 3 11-13-2011 05:02 AM
cron.hourly not working etika Linux - Newbie 4 04-26-2011 06:03 AM
cron.hourly Not Working lapidarynewbie Linux - Newbie 4 08-14-2009 08:01 AM
cronjob not working.. vivendi Linux - Newbie 6 08-12-2009 04:40 PM
script in cron.hourly not running hourly unholy Linux - Software 2 09-19-2006 08:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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