WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [SOLVED] I think my crond syntax is not right...  (Read 3516 times)

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
[SOLVED] I think my crond syntax is not right...
« on: April 06, 2017, 07:46:25 PM »
Now that everything else works I want to use crond to run a script that will reboot the TCL box.

So I used crontab -e to edit a crontab entry that looks like this:

30 7 * * * root /home/tc/test

- Where test is a script that I made to copy some files, run the backup, and then reboot the box.
- I go back to the terminal window and type:

sudo /etc/init.d/services/crond start

I wait until the time in the crontab expires and nothing happened.
So, I did a crond stop and edited the crontab again to be:

35 7 * * * tc ./test

Restarted the crond service, waited for the time to pass again and nothing happened.

I have tried many combinations, but I am not getting anywhere. The documentation for this is very slim as it pertains to TCL but was able to track down where the service lived so I could start it, and where the crontabs are supposed to be stored for use:

/var/spool/cron/crontabs/your-crontab-file


BTW, the test script works just fine is I use the command line in the terminal window and type:

./test

The script runs fine from the terminal but I can't seem to get it to run from crond

Can someone point me in the right direction? The linux man page on crond was not very helpful either.

Thanks,
BKM
« Last Edit: April 10, 2017, 12:31:23 PM by Rich »

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 713
Re: I think my crond syntax is not right...
« Reply #1 on: April 07, 2017, 03:32:07 AM »
Take a look at this tips, to specify path and so on.
http://krisjordan.com/essays/timesaving-crontab-tips

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: I think my crond syntax is not right...
« Reply #2 on: April 07, 2017, 07:28:57 AM »
No user name required.
Code: [Select]
30 7 * * * root /home/tc/test
Code: [Select]
30 7 * * * /home/tc/test
Download a copy and keep it handy: Core book ;)

Offline polikuo

  • Hero Member
  • *****
  • Posts: 723
Re: I think my crond syntax is not right...
« Reply #3 on: April 07, 2017, 08:59:49 AM »
From a tutorial some where on the internet:
settingminutehourday-of- month   month   day-of-weekusercommand
crontab -e0 - 590 - 23   1 - 311 - 12 OR jan,feb,mar ...0 - 6 (Sunday=0 or 7)*absent*/full/path
/etc/crontab0 - 590 - 23   1 - 311 - 12 OR jan,feb,mar ...0 - 6 (Sunday=0 or 7)user/full/path
Don't specify user for "crontab -e"
« Last Edit: April 07, 2017, 09:16:48 AM by polikuo »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: I think my crond syntax is not right...
« Reply #4 on: April 07, 2017, 09:06:19 AM »
There are two cron daemons.
The one for system process has a user field.
The one for scheduled user process does NOT have a user field as each user has its own crontab.

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: I think my crond syntax is not right...
« Reply #5 on: April 08, 2017, 09:57:45 AM »
Ok, so this is what I figured out through confusing reading and eventually a lot of trial and error.

For TCL ver 7x:

- Use a TCL box with monitor, mouse and keyboard, you are automatically logged in as "tc" (trying this as another user or through SSH from another PC on the network never worked for me no matter what I tried)

- As "tc" run the command:   crontab -e

- In the editor window that pops up create your single line crontab entry. Mine looked like this: 30 8 * * * /home/tc/rebootme
It will run the rebootme script at 8:30 every morning.

- Then click file and save to save your crontab entry.
If you alter the filename to something other than the default - it will not run
If you place it in the /var/spool/cron/crontabs directory - it will not run (it only seemed to work in /var/spool/cron)
If you do anything other than the default actions of the crontab editor - it will not run.

I tried naming the crontab file something meaningful to me so I would easily recognize but it would never work. So i was stuck with the funny name of crontabs.3251 as my filename. The wiki was not very specific on how to use cron, and the rest of the internet sources all create confusion because this implementation of cron does not strictly follow the conventions.

However if you are willing to follow the outline above it seems to work just fine for most tasks. Just remember to put the directory where the crontab files are stored in the list for backups.

Hope this helps someone else that might be trying to get cron to work for them.

BKM

Offline Misalf

  • Hero Member
  • *****
  • Posts: 1702
Re: I think my crond syntax is not right...
« Reply #6 on: April 08, 2017, 04:34:12 PM »
The cron file to be backed up should be  /var/spool/cron/crontabs/tc   if the user is "tc".
Since  crontab -e  is not the same as editing the file directly via any text editor, I think it's obvious that the filename shouldn't be altered because crontab takes care of it.
Download a copy and keep it handy: Core book ;)

Offline bkm

  • Jr. Member
  • **
  • Posts: 72
Re: I think my crond syntax is not right...
« Reply #7 on: April 10, 2017, 10:53:03 AM »
Thanks Misalf,

The TCL implementation of cron is different from other linux distros. In all of the distros I have worked before you could create your own cron files and drop them in the correct directory and they would work. In many cases I would have 10 to 12 different tasks operating on cron schedules and they were easy to identify because I could name them to be easily recognized. Coming into TCL with a history of using cron and then trying to apply it here was where I went of track.

There was nothing in the documentation (forum, wiki) that I could find to tell me not to alter the automatic naming of the file. In fact the crontab editor gives you easy access to the file naming and saving. So, with no detectable reason not to name them myself, I was doomed before I ever really got started. Also, the crontab editor makes it look like the crontab 'files' you create are in fact being saved in the /var/spool/cron directory when you look at the file save option. This was also confusing because most documentation tells you it must go in the /var/spool/cronm/crontabs directory. If you do save a file with the funny default filename you would be further confused by the fact that it never shows up in any directory. After reading your explanation I was able to run cat on the tc file in the crontabs directory and see my work, but up until that point it was still looking like smoke and mirrors to me.

At least this gave me the opportunity to document the process I went through so the next new comer to TCL has a chance to get cron working without going through the same headache.

Thank again,

BKM                  (Moderator... please mark as SOLVED. Thanks)