LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Cron job not working - Ubuntu (https://www.linuxquestions.org/questions/linux-newbie-8/cron-job-not-working-ubuntu-842421/)

jtadeo 11-04-2010 04:34 PM

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.

repo 11-04-2010 04:37 PM

Welcome to LQ

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

Kind regards

jtadeo 11-04-2010 04:41 PM

Quote:

Originally Posted by repo (Post 4149513)
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?

repo 11-04-2010 04:45 PM

instead of
Code:

gzip
use
Code:

/bin/gzip
same for
Code:

mysqldump
To find the path use
Code:

whereis mysqldump
Kind regards

Samotnik 11-04-2010 04:53 PM

Cron log is named /var/log/cron.log. You should browse through it, check messages timed with a moment your command should run.

jtadeo 11-04-2010 04:59 PM

Quote:

Originally Posted by Samotnik (Post 4149525)
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


Samotnik 11-04-2010 05:12 PM

ps -e | grep cron to check if cron is running.

jtadeo 11-04-2010 05:14 PM

Quote:

Originally Posted by Samotnik (Post 4149540)
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?

Samotnik 11-04-2010 05:32 PM

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.

jtadeo 11-04-2010 05:35 PM

Quote:

Originally Posted by Samotnik (Post 4149563)
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

Samotnik 11-04-2010 05:53 PM

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.

jtadeo 11-04-2010 06:10 PM

Quote:

Originally Posted by Samotnik (Post 4149576)
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#


Samotnik 11-04-2010 06:47 PM

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.

jtadeo 11-04-2010 06:59 PM

Quote:

Originally Posted by Samotnik (Post 4149614)
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

Samotnik 11-04-2010 07:07 PM

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


All times are GMT -5. The time now is 04:29 PM.