LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-07-2010, 01:55 AM   #1
windstory
Member
 
Registered: Nov 2008
Posts: 486

Rep: Reputation: 36
crontab -e has a problem


"crontab -e" has a problem.

My box is centos 5.4 x86, and I want to add one line of backup command to crontab.

I added this command to crontab.

Quote:
15 10 * * * /root/backup.sh
and I put this command,

Quote:
service crond restart
But nothing happened.

So, I tried "crontab -e", then this screen I attached came.

-- the screen can be found here also. ---
http://img43.imageshack.us/img43/982...07crontabe.png

At "crontab -l", I got this message.
"no crontab for root"

What is wrong?
Attached Thumbnails
Click image for larger version

Name:	2010-03-07 crontab -e.png
Views:	7
Size:	20.3 KB
ID:	2936  

Last edited by windstory; 03-07-2010 at 02:01 AM.
 
Old 03-07-2010, 02:14 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by windstory View Post
At "crontab -l", I got this message.
"no crontab for root"

What is wrong?
Just means root crontab is empty. Nothing wrong.


Quote:
Originally Posted by windstory View Post
"crontab -e" has a problem.
No, that's your editor (as defined by the $EDITOR variable). Now you can type in your line and save your crontab. Alternatively, but only since the crontab is empty, you could type in your line in any empty text file (say "/my/textfile") and type 'crontab /my/textfile' after which the contents of that file will replace the crontab.
 
Old 03-07-2010, 03:16 AM   #3
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by unSpawn View Post
Just means root crontab is empty. Nothing wrong.



No, that's your editor (as defined by the $EDITOR variable). Now you can type in your line and save your crontab. Alternatively, but only since the crontab is empty, you could type in your line in any empty text file (say "/my/textfile") and type 'crontab /my/textfile' after which the contents of that file will replace the crontab.
Thanks for your kind reply.

Your advice soved "crontab -e" problem.
However there are another problem.

At "/var/log/cron", there is this line.

"Mar 7 17:37:01 www crond[7813]: (root) CMD (/root/backup.sh)"

But, I could not find out any backup files from "/root/backup.sh".
 
Old 03-07-2010, 03:36 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by windstory View Post
I could not find out any backup files from "/root/backup.sh".
I can't see what "/root/backup.sh" is supposed to do. Maybe attach it for review?
 
Old 03-07-2010, 03:51 AM   #5
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by unSpawn View Post
I can't see what "/root/backup.sh" is supposed to do. Maybe attach it for review?
After "crontab /root/backup.sh", I can see "/root/backup.sh" at "crontab -e".
 
Old 03-07-2010, 03:55 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
You don't have to 'crontab -e' to see "/root/backup.sh", just 'crontab -l'. Now. What's this backup script supposed to do?
 
Old 03-07-2010, 03:55 AM   #7
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
First make sure the script works from the command prompt.
Then make sure to use the whole path to all commands and files in the script, since cron has a limited path.
 
Old 03-07-2010, 07:57 AM   #8
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by repo View Post
First make sure the script works from the command prompt.
Then make sure to use the whole path to all commands and files in the script, since cron has a limited path.
I tried "/root/backup.sh" at command prompt, then this works fine.
 
Old 03-07-2010, 07:59 AM   #9
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by unSpawn View Post
You don't have to 'crontab -e' to see "/root/backup.sh", just 'crontab -l'. Now. What's this backup script supposed to do?
This is "crontab -l"'s result.

Quote:
[root@www ~]# crontab -l
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
37 17 * * * /root/backup.sh
 
Old 03-07-2010, 08:30 AM   #10
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
If there is a problem with the script, root should receive a mail.
Did you added the path to all the commands and files in the script?
 
Old 03-07-2010, 08:38 AM   #11
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by repo View Post
If there is a problem with the script, root should receive a mail.
Did you added the path to all the commands and files in the script?

I couldn't install senmail, so I couldn't receive a mail.
But there are "log" commands at each functions.

My question is even though crontab has backup script, but I could not find out any logs.
 
Old 03-07-2010, 08:57 AM   #12
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,528

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Did you added the path to all the commands and files in the script?
 
Old 03-07-2010, 09:06 AM   #13
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by repo View Post
Did you added the path to all the commands and files in the script?
This is my "backup.sh"

Quote:
#!/bin/bash
#
# creates backups of essential files
#

checkdate=`LC_TIME=en date | awk '{print $1}'`
BACKUP_DIR=/var/www/_hanswork/_backup
html_SOURCE=/var/www/html/databackup
dmdata_SOURCE=/var/www/html/databackup/data
REMOTEDIR=/cygdrive/l/_databackup_backup
# fullincre_bak.list
DATE=`date +"%Y%m%d"`
#
if [ "$checkdate" = "Sat" ] ; then
tar -g ${BACKUP_DIR}/html_fullincre_bak.list -czvpf ${BACKUP_DIR}/html_full_bak_${DATE}.tgz -C / ${html_SOURCE} --exclude=${html_SOURCE}/data

# scp to remote backup server
scp ${BACKUP_DIR}/html_full_bak_${DATE}.tgz winbackup:$REMOTEDIR
if [ $? -eq 0 ]
then
rm -rf ${BACKUP_DIR}/html_full_bak_${DATE}.tgz
# backup log.
echo "${DATE}_backup Successfully Done." > ${BACKUP_DIR}/${DATE}_html_fullincre_backup_ok.log;
else
echo "${DATE}_backup Has Error!." > ${BACKUP_DIR}/${DATE}_html_fullincre_backup_error.log;
fi

#
tar -g ${BACKUP_DIR}/data_fullincre_bak.list -czvpf ${BACKUP_DIR}/dmdata_full_bak_${DATE}.tgz -C / ${dmdata_SOURCE} --exclude=${dmdata_SOURCE}/session

# scp to remote backup server
scp ${BACKUP_DIR}/dmdata_full_bak_${DATE}.tgz winbackup:$REMOTEDIR
if [ $? -eq 0 ]
then
rm -rf ${BACKUP_DIR}/dmdata_full_bak_${DATE}.tgz
# backup log.
echo "${DATE}_backup Successfully Done." > ${BACKUP_DIR}/${DATE}_dmdata_fullincre_backup_ok.log;
else
echo "${DATE}_backup Has Error!." > ${BACKUP_DIR}/${DATE}_dmdata_fullincre_backup_error.log;
fi

else
# incremental backup:
#
tar -g ${BACKUP_DIR}/html_fullincre_bak.list -czvpf ${BACKUP_DIR}/html_incre_bak_${DATE}.tgz -C / ${html_SOURCE} --exclude=${html_SOURCE}/data

# scp to remote backup server
scp ${BACKUP_DIR}/html_incre_bak_${DATE}.tgz winbackup:$REMOTEDIR
if [ $? -eq 0 ]
then
rm -rf ${BACKUP_DIR}/html_incre_bak_${DATE}.tgz
# backup log.
echo "${DATE}_backup Successfully Done." > ${BACKUP_DIR}/${DATE}_html_fullincre_backup_ok.log;
else
echo "${DATE}_backup Has Error!." > ${BACKUP_DIR}/${DATE}_html_fullincre_backup_error.log;
fi

#
tar -g ${BACKUP_DIR}/data_fullincre_bak.list -czvpf ${BACKUP_DIR}/dmdata_incre_bak_${DATE}.tgz -C / ${dmdata_SOURCE} --exclude=${dmdata_SOURCE}/session

# scp to remote backup server
scp ${BACKUP_DIR}/dmdata_incre_bak_${DATE}.tgz winbackup:$REMOTEDIR
if [ $? -eq 0 ]
then
rm -rf ${BACKUP_DIR}/dmdata_incre_bak_${DATE}.tgz
# backup log.
echo "${DATE}_backup Successfully Done." > ${BACKUP_DIR}/${DATE}_dmdata_fullincre_backup_ok.log;
else
echo "${DATE}_backup Has Error!." > ${BACKUP_DIR}/${DATE}_dmdata_fullincre_backup_error.log;
fi
fi


/opt/lampp/bin/mysqldump -uroot -pmaestro dmdata | gzip > ${BACKUP_DIR}/mysql_db_bak_$(date +%Y%m%d).gz

scp ${BACKUP_DIR}/mysql_db_bak_$(date +%Y%m%d).gz winbackup:$REMOTEDIR
if [ $? -eq 0 ]
then
rm -rf ${BACKUP_DIR}/mysql_db_bak_$(date +%Y%m%d).gz
# backup log.
echo "${DATE}_dfdata_db_backup Successfully Done." > ${BACKUP_DIR}/${DATE}_dfdata_db_backup_ok.log;
else
echo "${DATE}_dfdata_db_backup Has Error!." > ${BACKUP_DIR}/${DATE}_dfdata_db_backup_error.log;
fi
 
  


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
Crontab Problem dieduster Linux - Software 1 11-16-2006 05:49 AM
crontab problem sunnyanthony Linux - Software 1 01-07-2006 04:48 AM
crontab problem pdrobe Red Hat 1 02-05-2005 03:19 PM
crontab problem BlackRabbit Linux - General 9 06-17-2004 07:38 AM
crontab problem TomTheNewbie Slackware 1 07-09-2003 07:12 AM


All times are GMT -5. The time now is 02:43 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