Koozali.org: home of the SME Server

Idiot can't get cron jobs to run

Offline JJSH

  • 18
  • +0/-0
Idiot can't get cron jobs to run
« on: March 17, 2009, 04:32:44 PM »
I've installed the Crontab Manager contrib. I am trying to get it to run the following command;

 mysql -u myusername -pmypassword mydatabase < /home/e-smith/files/ibays/system/html/systemscripts/export.sql

The export.sql script generates a csv file. I know the above command works, as I can ssh in as root and copy / paste it from Crontab Manager, and hey presto, the required csv file is created in the required place, with no errors.

Try as I might, however, I can't get it to run from Crontab Manager. In desperation, I've set it to run every min, thus;

Minutes   Every minute   Hours   Every hour   Day   Every day   Month       Day of the week   User Command       
*               *               *                     Every month   Every day of week   root   (the above command)

By my thinking, it should run every min, but doesn't ~ in fact, whatever I try, I can't get it to run at all using Crontab Manager. I missing something obvious here, as the command is OK ~ can anyone help ~ I can't see anything obvious in the logs or system emails.

Offline JJSH

  • 18
  • +0/-0
Re: Idiot can't get cron jobs to run
« Reply #1 on: March 17, 2009, 05:02:54 PM »
mmmmm, crontab -e -u root is empty. Is that correct?

Offline axessit

  • ****
  • 211
  • +0/-0
Re: Idiot can't get cron jobs to run
« Reply #2 on: March 18, 2009, 12:47:21 AM »
The crontab for root probably is empty as the crontab manager doesn't run as root, it runs as admin, which is a psydenom... psyudenom...psyduenom... @#$% !!... alias for root.

Check the system log files - select the cron files and you should see it kicking off. I had trouble getting one to work and when I looked in there I found it wasn't quite doing what i expected, so i just created a manual crontab by running /usr/bin/crontab -e and entering the job that way. It now executes as I want.

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: Idiot can't get cron jobs to run
« Reply #3 on: March 18, 2009, 08:31:41 AM »
JJSH.. IMO you are wasting your time :)

try to:
- create (if it does not exist) /etc/e-smith/templates-custom/etc/crontab dir
- then create a fragment into that dir like this:

Code: [Select]
*/5 * * * *   root path_to_a_executable_shell_script_that_does_what_I_want

change the rule of execution as you like

into your script (in /etc or your /home or wherever you prefer) you put the command
then do
Code: [Select]
chmod +x your_script

- then expand the template
Code: [Select]
expand-template /etc/crontab

- and restart cron
Code: [Select]
service cron restart

it should work (at least works for me)

HTH
Ciao
Stefano

Offline JJSH

  • 18
  • +0/-0
Re: Idiot can't get cron jobs to run
« Reply #4 on: March 19, 2009, 01:30:54 PM »
I'll give this a try. I have created and tested a script that does what I want, created the directory, but am a little lost at how I create a 'fragment'. Is this something I need to use 'touch' for? As you can see, I'm a bit of a command line newb.  :grin:

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: Idiot can't get cron jobs to run
« Reply #5 on: March 19, 2009, 02:19:07 PM »
I'll give this a try. I have created and tested a script that does what I want, created the directory, but am a little lost at how I create a 'fragment'. Is this something I need to use 'touch' for? As you can see, I'm a bit of a command line newb.  :grin:

create a fragment = create a new file with pico, fill it with the desired content, save & close :-)
nothing more, nothing less

fragments are evaluated in alphabetical order.. ;-)

ciao
Stefano

Offline JJSH

  • 18
  • +0/-0
Re: Idiot can't get cron jobs to run
« Reply #6 on: March 19, 2009, 02:57:57 PM »
Fantastic, I've got that working. Cheers for that. If I want to add other cron jobs, do I just add additional lines to that file, and the restart the crond service?

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: Idiot can't get cron jobs to run
« Reply #7 on: March 19, 2009, 03:51:13 PM »
Fantastic, I've got that working. Cheers for that. If I want to add other cron jobs, do I just add additional lines to that file, and the restart the crond service?

add another fragment if it is for a different task, a line in the same fragment otherwise

Ciao
Stefano

Offline steve288

  • *
  • 336
  • +0/-0
Re: Idiot can't get cron jobs to run
« Reply #8 on: May 29, 2009, 05:31:28 PM »
Stefano has outlined a nice little simple way of setting up cron job. However he mentions using;

"service cron restart"

To restart the cron service.

I could not get this to work. I would not want to step on anyones fingers cause I might be wrong but the command that worked for me is

/sbin/service crond restart
(please note the d added to the end of the word cron)

Because you are restarting the daeman eg cronD . I'm not sure there is a service technically anyway, called cron, at least on my system.

I could be wrong.
Regards

Offline Stefano

  • *
  • 10,839
  • +2/-0
Re: Idiot can't get cron jobs to run
« Reply #9 on: May 29, 2009, 05:46:26 PM »
/sbin/service crond restart
(please note the d added to the end of the word cron)
I could be wrong.
Regards

you are right.. my bad, was a typo :-)