View Full Version : crontab help
M|Inferno
8-14-02, 03:50 PM
Sorry to post about crontab again, but I've read everything I can find in the forums here, in the FAQ's, etc, and my cron job is still not running.
I am 99.9% sure I've setup everything correctly, but I'll describe it here:
I have my crontab file uploaded to /www/<siteletter>/<mysite>/etc/crontab. It has the following permissions: -rw-r--r--
It was uploaded as ascii, is confirmed to be "crontab" and not "crontab.txt" and contains this:
# run job daily at 4:00am PT
00 4 * * * /www/<siteletter>/<mysite>/dbdump/dbbackup.sh 1> /www/<siteletter>/<mysite>/dbdump/cron.log 2> /www/<siteletter>/<mysite>/dbdump/cronerr.log
I have the dbbackup.sh script uploaded to /www/<siteletter>/<mysite>/dbdump/dbbackup.sh. It has the following permissions: -rwxr-xr-x
It was uploaded as ascii, and confirmed to be named "dbbackup.sh" and contains this:
#!/bin/sh
rm -f /www/<siteletter>/<mysite>/dbdump/db.tar.gz
/usr/local/bin/mysqldump -u <myuser> --password=<mypassword> <mydatabase> | gzip > /www/<siteletter>/<mysite>/dbdump/db.tar.gz
The script DOES successfully run outside of cron!
I've had this all set up for the past several days, and still nothing. No database export or log files.
Any help would be greatly appreciated!! I will supply any more additional information if required.
Thanks much.
HalfaBee
8-14-02, 08:10 PM
I can't image the problem being 00 as the minutes but it might be.
And I assume you mean
/www/u/username/
not sitename.
You could put
MAILTO=me@mysite.com
and cron will email you when it runs.
Hope you get it working
HalfaBee
You’re trying to write to a file in another user’s directory. This will not work. You can only specify files w/in the account the crontab is set up in unless you’re root. :)
M|Inferno
8-15-02, 02:51 AM
HalfaBee - I changed the 00 to 0 as you suggested, but I highly doubt that is the problem as well. And I do have a MAILTO line in my crontab, but have not received any mail messages at all. Also, I do mean /www/u/username, just not caught up on the lingo around here. :D
Starr - Every file I am referring to IS in my tree. Please elaborate?!?
M|Inferno
8-16-02, 01:57 PM
*bump*
Can someone please help?!? I'm still getting no results from my cron backup job. I would REALLY REALLY like to automate my backup procedures for my database...
HalfaBee
8-19-02, 01:45 AM
If you are desperate you can PM me your FTP details and I will see if I can make it work for you.
HalfaBee
M|Inferno
8-20-02, 12:21 AM
I changed my crontab to the following:
0 4 * * * echo "Testing..." 1> /www/u/username/dbdump/cron.log 2> /www/u/username/dbdump/cronerr.log
We'll see if it creates anything. :confused:
M|Inferno
8-20-02, 07:56 PM
Still nothing. Can someone from powweb check to see my crontab is even being processed?!?!? Should I email support, or do they read these forums as well?
Cron works flawelssly as long as you know what you are doing.
M|Inferno
8-21-02, 12:44 AM
I KNOW what I am doing. I admin several Red Hat boxes at work and home. I have successfully set up MANY cron jobs.
I have followed EVERY instruction on setting up crontab here at powweb. Nothing is happening. I may be missing something, but who knows.
My crontab is located here: /www/t/themachine/etc/crontab, if you care to have a look. And the backup script I am trying to run is in /www/t/themachine/dbdump/dbbackup.sh
No comment.
su-2.05a# perl -cw /www/t/themachine/dbdump/dbbackup.sh
Unquoted string "rm" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 2.
syntax error at /www/t/themachine/dbdump/dbbackup.sh line 2, near "rm -f "
Warning: Use of "-f" without parens is ambiguous at /www/t/themachine/dbdump/dbbackup.sh line 2.
Bareword found where operator expected at /www/t/themachine/dbdump/dbbackup.sh line 2, near "/www/t"
(Missing operator before t?)
Unquoted string "t" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 2.
Unquoted string "themachine" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 2.
Unquoted string "dbdump" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 2.
Unquoted string "db" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 2.
Unquoted string "tar" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 2.
Unquoted string "gz" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Unquoted string "usr" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Bareword found where operator expected at /www/t/themachine/dbdump/dbbackup.sh line 3, near "/bin/mysqldump"
(Missing operator before ysqldump?)
Unquoted string "ysqldump" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Unquoted string "machine" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Bareword found where operator expected at /www/t/themachine/dbdump/dbbackup.sh line 3, near "--password"
(Missing operator before password?)
Bareword found where operator expected at /www/t/themachine/dbdump/dbbackup.sh line 3, near "XXXXX"
(Missing operator before XXXXX?)
Unquoted string "gzip" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Bareword found where operator expected at /www/t/themachine/dbdump/dbbackup.sh line 3, near "/www/t"
(Missing operator before t?)
Unquoted string "t" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Unquoted string "themachine" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Unquoted string "dbdump" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Unquoted string "db" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Unquoted string "tar" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
Unquoted string "gz" may clash with future reserved word at /www/t/themachine/dbdump/dbbackup.sh line 3.
/www/t/themachine/dbdump/dbbackup.sh had compilation errors.
M|Inferno
8-21-02, 12:24 PM
Why are you trying to run my "#!/bin/sh" script with perl?!?!?!?
The script works, as I can run it perfectly fine from a php shell.
whoops, lemme try that again.....
Ok, try # 2 ;)
Only problem I was able to identify (doesn’t say much ;) is that shell scripts like it when you specify paths for any and all commands you run (especially web users).
Try adding "/bin/rm" and "/usr/bin/gzip" in place of when you just have “rm” and “gzip” specified.
you were getting mixed up with the uses of | vs >
I fixed your script and it now works as two steps
#!/bin/sh
rm -f /www/t/themachine/dbdump/db.tar.gz
/usr/local/bin/mysqldump -u machine --password= machine > db.backup
/usr/bin/gzip /www/t/themachine/dbdump/db.backup
you were calling it db.tar and weren't taring it either. this didn't break anything it just didn't make any sense. it looked like you were confusing pipes and greater thens in your crontab too. i will take a look at this as well. yea the cron job is all messed up as well.
M|Inferno
8-21-02, 02:59 PM
Originally posted by Starr
Ok, try # 2 ;)
Only problem I was able to identify (doesn’t say much ;) is that shell scripts like it when you specify paths for any and all commands you run (especially web users).
Try adding "/bin/rm" and "/usr/bin/gzip" in place of when you just have “rm” and “gzip” specified.
Hrm....yeah, I don't believe the /usr/bin is in the path for cronjobs, but I can't see the /etc/crontab to verify that. That is probably the issue though.
Regardless, I thought I would get SOME kind of output in either of my log files for the cron job.
M|Inferno
8-21-02, 03:03 PM
Originally posted by Sgeine
you were getting mixed up with the uses of | vs >
I fixed your script and it now works as two steps
#!/bin/sh
rm -f /www/t/themachine/dbdump/db.tar.gz
/usr/local/bin/mysqldump -u machine --password=<password> machine > db.backup
/usr/bin/gzip /www/t/themachine/dbdump/db.backup
you were calling it db.tar and weren't taring it either. this didn't break anything it just didn't make any sense. it looked like you were confusing pipes and greater thens in your crontab too. i will take a look at this as well. yea the cron job is all messed up as well.
Yes, you are correct about the file name including "tar". That what done out of habit ;)
However, I am NOT confused on the use of > and |. My original script worked, as I mentioned above.
The original script:
rm -f /www/t/themachine/dbdump/db.tar.gz
/usr/local/bin/mysqldump -u themachine --password=<password> machine | gzip > /www/t/themachine/dbdump/db.tar.gz
This command takes the output of mysqldump, pipes it to gzip (which is correct), and sends the output of gzip to a file. Exactly what I want. Avoids creating a 56+mb mysql dump file that I then would have to delete after compression.
Anyway, I'll try fixing the script to include the full path to gzip.
BTW, thanks for posting my password. Sigh.
sorry, it didn't work and it didn't work until i rewrote it. you're cron tab is messed up too and i'll fix that for you as well when i get a chance.
I lost the errors your script was generating in the scroll as i am working on a number of things at the moment but rest assured if it had been working would you not have had a db.tar.gz in yuor directory? you didn't and your script was failing and it wasn't a path problem. Like i said you're getting confused between pipe and <. this isn't arguable because it wasn't working when i ran it and it is working now.
I see you're changing stuff around again...when you're ready to have it work let me know, otherwise you're on your own.
M|Inferno
8-21-02, 03:27 PM
I can run my original script just fine from phpshell. It works. It creates my database backup gzip file. I, of course, have since deleted it, as I was confident the script worked.
However, the script did NOT work from cron. I believe Starr has found the problem. That problem being the use of gzip without it being fully qualified (gzip vs /usr/bin/gzip). I have changed my script to do this, and will assume this will fix it. We'll have to wait and see.
Also, a quote from the gzip man page:
ADVANCED USAGE
...
cat file1 file2 | gzip > foo.gz
...
Thanks for removing my password from your post too. :) Could you remove it from Starr's post above where he tried to run my script through perl?
M|Inferno
8-21-02, 04:55 PM
Both my crontab and dbbackup script should be in their final state. If only I could tell the cron daemon to re-read my crontab so I could test it. :D
M|Inferno
8-21-02, 06:29 PM
Looks like someone restarted the cron daemon and my cron job is actually working! Thanks much.
Thanks to Starr for the "fully qualifying paths" tip for commands in cron jobs.
Thanks to any and all involved.
Changes to cronjobs are added every 2 hours.
Glad it's working now. :)
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.