LinuxQuestions.org
Visit Jeremy's Blog.
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 11-04-2010, 04:34 PM   #1
jtadeo
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Rep: Reputation: 0
Cron job not working - Ubuntu


Good afternoon,

I manage a vbulletin forum board and I would like to schedule a weekly backup using cron. I was following a guide that allowed me to do so, but the cron job will not run.

Guide followed:

http://www.backuphowto.info/how-back...ly-linux-users

I made a txt file on my pc with the following info:
Code:
02 16 * * 4 mysqldump --opt -Q -uUSERNAME -pPASSWORD thetz | gzip > /home/usr/public_html/backups/database2_`date '+%m-%d-%Y'`.sql.gz
I then transferred the txt file to my web space and ran this command

crontab weeklybackup.txt

I then restarted cron
service cron restart

I type contab -l (to show any jobs listed) and the command did show up

Code:
root@thetz:/var/log# crontab -l
02 16 * * 4 mysqldump --opt -Q -uUSERNAME -pPASSWORD thetz | gzip > /home/usr/public_html/backups/database2_`date '+%m-%d-%Y'`.sql.gz
I did verify that the time of the job and the server time matched up... so not sure what's going on. It just doesn't make the backup in the directory.

If I type the command on its own
Code:
mysqldump --opt -Q -uUSERNAME -pPASSWORD thetz | gzip > /home/usr/public_html/backups/database2_`date '+%m-%d-%Y'`.sql.gz
that works perfectly

Can anyone help me out as to why the job did not run? Please let me know if you need more info. I'm very new to linux but I do have some basic DOS experience so typing commands is not that scare :P.

Thanks in advanced.
 
Old 11-04-2010, 04:37 PM   #2
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Welcome to LQ

Since cron uses a limited path, you need to use the whole path to the commands and files.

Kind regards
 
Old 11-04-2010, 04:41 PM   #3
jtadeo
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by repo View Post
Welcome to LQ

Since cron uses a limited path, you need to use the whole path to the commands and files.

Kind regards
you lost me here.. would you please be able to provide me with an example of what you're talking about?
 
Old 11-04-2010, 04:45 PM   #4
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
instead of
Code:
gzip
use
Code:
/bin/gzip
same for
Code:
mysqldump
To find the path use
Code:
whereis mysqldump
Kind regards
 
Old 11-04-2010, 04:53 PM   #5
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
Cron log is named /var/log/cron.log. You should browse through it, check messages timed with a moment your command should run.
 
Old 11-04-2010, 04:59 PM   #6
jtadeo
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Samotnik View Post
Cron log is named /var/log/cron.log. You should browse through it, check messages timed with a moment your command should run.
there isn't any cron.log file, I was looking for that before I posted here. I will try using the full path to gzip and my sql database and report back.

Code:
root@thetz:/var/log# dir
ConsoleKit       daemon.log.3.gz  dpkg.log.1     messages.1      syslog
apache2          daemon.log.4.gz  faillog        messages.2.gz   syslog.1
apt              dbconfig-common  fsck           messages.3.gz   syslog.2.gz
auth.log         debug            kern.log       messages.4.gz   syslog.3.gz
auth.log.1       debug.1          kern.log.1     mysql           syslog.4.gz
auth.log.2.gz    debug.2.gz       kern.log.2.gz  mysql.err       syslog.5.gz
auth.log.3.gz    debug.3.gz       kern.log.3.gz  mysql.log       syslog.6.gz
auth.log.4.gz    debug.4.gz       kern.log.4.gz  mysql.log.1.gz  syslog.7.gz
boot             dmesg            lastlog        mysql.log.2.gz  udev
boot.log         dmesg.0          lpr.log        mysql.log.3.gz  user.log
btmp             dmesg.1.gz       mail.err       mysql.log.4.gz  wtmp
btmp.1           dmesg.2.gz       mail.info      mysql.log.5.gz  wtmp.1
daemon.log       dmesg.3.gz       mail.log       mysql.log.6.gz
daemon.log.1     dmesg.4.gz       mail.warn      mysql.log.7.gz
daemon.log.2.gz  dpkg.log         messages       news
 
Old 11-04-2010, 05:12 PM   #7
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
ps -e | grep cron to check if cron is running.
 
Old 11-04-2010, 05:14 PM   #8
jtadeo
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Samotnik View Post
ps -e | grep cron to check if cron is running.
Code:
root@thetz:/etc# ps -e | grep cron
17104 ?        00:00:00 cron
does that indicate that it's running?
 
Old 11-04-2010, 05:32 PM   #9
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
It is. So run crontab -r, then add * * * * * echo `date` >> ~/out to your crontab.
This should add a date string to ~/out file once a minute. It's fairly errorproof command, simply to check, if cron runs jobs at all.
 
Old 11-04-2010, 05:35 PM   #10
jtadeo
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Samotnik View Post
It is. So run crontab -r, then add * * * * * echo `date` >> ~/out to your crontab.
This should add a date string to ~/out file once a minute. It's fairly errorproof command, simply to check, if cron runs jobs at all.
GUI= graphical user interface?

I'm doing this all through putty on my windows 7 pc.

please forgive my noobiness
 
Old 11-04-2010, 05:53 PM   #11
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
Don't mind. Just add date to cron to see if it works.As you do it, wait some minutes, then do cat ~/out to see, if there are date strings. If it is, then cron is ok, it's something with your command.
 
Old 11-04-2010, 06:10 PM   #12
jtadeo
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Samotnik View Post
Don't mind. Just add date to cron to see if it works.As you do it, wait some minutes, then do cat ~/out to see, if there are date strings. If it is, then cron is ok, it's something with your command.
don't think it's working
just tried what you asked me to do and it didn't output any dates

Code:
root@thetz:/etc# crontab -l
* * * * * echo `date` >> ~/outroot@thetz:/etc#
root@thetz:/etc# cat ~/out
root@thetz:/etc#
 
Old 11-04-2010, 06:47 PM   #13
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
It's interesting.
Can you add same string to global crontab /etc/crontab. Modify it slightly
* * * * * root echo `date` >> ~/out
Then as usual, wait for some minutes, then check cat ~/out.
 
Old 11-04-2010, 06:59 PM   #14
jtadeo
LQ Newbie
 
Registered: Nov 2010
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Samotnik View Post
It's interesting.
Can you add same string to global crontab /etc/crontab. Modify it slightly
* * * * * root echo `date` >> ~/out
Then as usual, wait for some minutes, then check cat ~/out.
same thing

Code:
root@thetz:/etc# crontab -r
root@thetz:/etc# crontab -l
no crontab for root
root@thetz:/etc# crontab testcron.txt
root@thetz:/etc# service cron restart
cron start/running, process 20879
root@thetz:/etc# crontab -l
* * * * * root echo `date` >> ~/outroot@thetz:/etc#
root@thetz:/etc# cat ~/out
root@thetz:/etc# cd /~
bash: cd: /~: No such file or directory
root@thetz:/etc# cd ~
root@thetz:~# dir
out
root@thetz:~# cat out
root@thetz:~# cat out
root@thetz:~#
I really appreciate the follow up
 
Old 11-04-2010, 07:07 PM   #15
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
No. This string * * * * * root echo `date` >> ~/out add to /etc/crontab file.
 
  


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
Job in /etc/cron.d not working BrianK Linux - General 6 11-03-2011 09:03 AM
cron job not working bittus Linux - Software 7 04-27-2009 07:39 PM
cron job is not working moagalbm Linux - Newbie 7 02-29-2008 05:16 PM
Cron Job Not Working... ALInux Linux - Software 2 07-24-2007 04:15 AM
Cron job not quite working... simba_cubs Linux - General 10 11-08-2006 06:27 AM


All times are GMT -5. The time now is 07:20 PM.

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