WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] Learning Cron  (Read 13903 times)

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
[Solved] Learning Cron
« on: March 08, 2012, 10:40:40 PM »
Hi all :)

I've remastered tinycore to always fire up cron for me, so I can schedule some backups to another machine on our network.

I did a search for cron related files on tinycore 3.8.4 and found the following

Code: [Select]
$ sudo find / -name "*cron*"
/etc/init.d/services/crond
/usr/bin/crontab
/usr/sbin/crond
/sys/bus/pci/drivers/JMicron IDE
/var/spool/cron
/var/spool/cron/crontabs
/var/run/crond.pid

I'm guessing that I should use /var/spool/cron/crontabs ?
Its recommended here as well : http://www.pathname.com/fhs/pub/fhs-2.3.html#VARSPOOLCRONCRONANDATJOBS

Thanks in advance for your comments.

Once I setup this regular backup management will put some important files onto the test samba server for a few weeks and then review the outcome :)
« Last Edit: March 12, 2012, 07:14:18 PM by remus »
Live long and prosper.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: location of crontabs
« Reply #1 on: March 08, 2012, 11:05:19 PM »
Use the crontab command.

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
Re: location of crontabs
« Reply #2 on: March 08, 2012, 11:44:06 PM »
Thanks for the input gerald_clark

Code: [Select]
tc@box:~$ crontab -e
Can't open display:

Code: [Select]
tc@box:~$ crontab -l
tc@box:~$

I'm a bit stuck.
Live long and prosper.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: location of crontabs
« Reply #3 on: March 08, 2012, 11:51:59 PM »
Looks like your remaster is broken.
You should not be getting htat error.

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
Re: location of crontabs
« Reply #4 on: March 08, 2012, 11:57:22 PM »
I guessed that the problem had something to do with the system not having an editor set to open the crontab file for editing.

So googled a bit and found the following page
http://www.adminschoice.com/crontab-quick-reference
With the following bit of help
Quote
export EDITOR=vi ;to specify a editor to open crontab file.

Running that command gets things working when I run
Code: [Select]
crontab -eNow a blank file is opened with the following at the bottom
Code: [Select]
- /var/spool/cron/crontabs.2224 0/0 100%
Sooo..... I'll try booting up a stock tinycore 3.8.4 disc with bootcode cron and see if it behaves the same.
Live long and prosper.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: location of crontabs
« Reply #5 on: March 09, 2012, 12:07:33 AM »
I have "export EDITOR=vi" in my .ashrc, so you may be on to something.

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
Re: location of crontabs
« Reply #6 on: March 09, 2012, 12:08:37 AM »
Booting up with another computer using a stock tinycore 3.8.4 cd with bootcodes syslog cron

- Boot up is fine.

- running
Code: [Select]
crontab -e from CLI fires up the GUI editor

------------------

The system I was actually testing is running tinycore 3.8.4 (NOT microcore), and is a headless server with no keyboard or mouse either.

I'm accessing it with putty and getting that error when i run "crontab -e" So I guess that its trying to edit crontab files with the gui editor, but is failing as I'm in a CLI via putty.

So I would guess that if i was using a microcore boot disc it would use vi and not the GUI editor. What do you think ?
Live long and prosper.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: location of crontabs
« Reply #7 on: March 09, 2012, 12:13:34 AM »
I think you are correct.

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
Re: location of crontabs
« Reply #8 on: March 12, 2012, 06:59:37 AM »
I've been reading up about using cron, and think I may need some help.

I've created a basic sh script
Code: [Select]
#!/bin/sh

echo "The date/time is : $(date)" >> timelog ;

When I run the file from the cli it appends the current date/time to the file timelog

Now in order to test that i am learning how to use cron correctly, I want to make sure this happens every minute.
So I ran "crontab -e"
And created the following file
Code: [Select]
SHELL=/bin/sh
PATH=/usr/sbin:/usr/bin

# Jobs
* * * * * sh /home/tc/update.log.sh

I used nano to create "/etc/cron.allow" with the following contents
Code: [Select]
root
tc

And I monitor the contents of  timelog with
Code: [Select]
tail -f timelog
However, the expected date/time info is not being appended to the file.
I have looked around on a few websites, and i'm pretty sure that I've got he correct cron format for a job every 1 minutes.

Your comments and suggestions are welcome.
Live long and prosper.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: location of crontabs
« Reply #9 on: March 12, 2012, 11:34:38 AM »
And just where do you think "timelog" will be located?
Use an absolute path.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11618
Re: location of crontabs
« Reply #10 on: March 12, 2012, 02:47:23 PM »
Hi remus
If you run crontab -l does it list your job?

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
Re: location of crontabs
« Reply #11 on: March 12, 2012, 06:50:55 PM »
Thanks for your tip gerald_clark,
I've updated the update.log.sh file
from
Code: [Select]
#!/bin/sh

echo "The date/time is : $(date)" >> timelog ;
to
Code: [Select]
#!/bin/sh

echo "The date/time is : $(date)" >> /home/tc/timelog ;
to include absolute path's
both files are in my tc home dir

I added the following to /opt/.filetool.sh
var/spool/cron
etc/cron.allow
I made a backup with "filetool.sh -b"
and rebooted, just in case that would help, but its still not working.

Hi Rich,
Heres my output from "crontab -l"
Code: [Select]
$ crontab -l
SHELL=/bin/sh
PATH=/usr/sbin:/usr/bin

# Jobs
* * * * * sh /home/tc/update.log.sh
Live long and prosper.

Offline remus

  • Sr. Member
  • ****
  • Posts: 371
Re: location of crontabs
« Reply #12 on: March 12, 2012, 07:13:23 PM »
I did a google search for
cron troubleshooting 
And found some useful tips at this website.
http://kb.mediatemple.net/questions/1588/Troubleshooting+common+issues+with+cron+jobs#gs

After making sure I used ONLY "absolute paths" and making a few changes to file permissions, it started working just fine.

Thanks guys :)
Live long and prosper.