LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 05-06-2010, 01:44 PM   #1
smithy2010
Member
 
Registered: May 2010
Location: UK
Distribution: OpenSuse 64 bit
Posts: 45

Rep: Reputation: 15
Smile crontab


Hi all,

I wrote this little script and it runs very well, however when I setup a cronjob it only runs if I am logged in. I would like to have this script running even when I am not logged in. At the moment it runs but only when I am logged in.
I logged as denis and in terminal (su root) and edited crontab as shown below, can anyone tell me what do I need to change or setup to have this script run when no-one is logged in the computer. I run Fedora 12 (64 bit)

Thank you in advance


backup script:

cd /home/denis/Documents

tar -czvPf /home/denis/Backups/docsbackups_$(date +%Y%b%d_%HH%MM).tar.gz /home/denis/Documents


# above line will produce file with name in this format "docsbackups_date&time.tar.gz" in the /home/denis/Backups folder



crontab:

[root@F12 etc]# cat crontab

SHELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/home/denis/Scripts

MAILTO=smith_denis@ymail.com
HOME=/



# For details see man 4 crontabs



# Example of job definition:

# .---------------- minute (0 - 59)

# | .------------- hour (0 - 23)

# | | .---------- day of month (1 - 31)

# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...

# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# | | | | |

# * * * * * command to be executed





20 20 * * * root /home/denis/Scripts/backups.sh
 
Old 05-06-2010, 02:22 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Try redirecting output from the script to a log file in case that a) fixes the problem or b) gives some useful information

Code:
20 20 * * * root /home/denis/Scripts/backups.sh &> /home/denis/Scripts/backups.sh.out
 
Old 05-06-2010, 06:48 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
Also, if cron has a problem, it usually emails the job owner and/or root.
 
Old 05-07-2010, 03:04 AM   #4
geovg
Member
 
Registered: Mar 2010
Posts: 40

Rep: Reputation: 1
can you try sh /home/denis/Scripts/backups.sh in the cron?
 
1 members found this post helpful.
Old 05-07-2010, 04:00 PM   #5
smithy2010
Member
 
Registered: May 2010
Location: UK
Distribution: OpenSuse 64 bit
Posts: 45

Original Poster
Rep: Reputation: 15
Thumbs up

Hi all,

Thank you very much for your suggestions, it is working well now. This is what I've done:

logged in terminal console as root and run crontab -e, then wrote

[root@F12 ~]# crontab -l

HELL=/bin/bash

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/home/denis/Scripts

MAILTO=smith_denis@ymail.com
HOME=/



# For details see man 4 crontabs



# Example of job definition:

# .---------------- minute (0 - 59)

# | .------------- hour (0 - 23)

# | | .---------- day of month (1 - 31)

# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...

# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat

# | | | | |

# * * * * * command to be executed





42 21 * * * sh /home/denis/Scripts/backups.sh


and this worked as I wanted. Error I was making was that I was running following command

vi /etc/crontab

and then edited this crontab, this way I had to be logged in as root for cron to run however after making changes I don't have to be logged in for cron to run.

Once again, Thank you for your suggestions!!

I have few more questions regarding output of events into the log file but I'll create new post for that.

Best wishes

Denis
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux crontab vs unix crontab ytd Linux - General 2 08-09-2009 05:07 AM
replaced crontab, now should get crontab back to what it was raminn Linux - Newbie 2 10-20-2008 07:15 PM
man crontab(5) vs crontab(1) Canis Polaris Linux - Newbie 2 06-04-2008 04:03 PM
new to crontab desbyleo Solaris / OpenSolaris 15 12-16-2004 03:04 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM


All times are GMT -5. The time now is 08:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration