LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   crontab -e has a problem (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-e-has-a-problem-793737/)

windstory 03-07-2010 01:55 AM

crontab -e has a problem
 
1 Attachment(s)
"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?

unSpawn 03-07-2010 02:14 AM

Quote:

Originally Posted by windstory (Post 3888936)
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 (Post 3888936)
"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.

windstory 03-07-2010 03:16 AM

Quote:

Originally Posted by unSpawn (Post 3888946)
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".

unSpawn 03-07-2010 03:36 AM

Quote:

Originally Posted by windstory (Post 3888984)
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?

windstory 03-07-2010 03:51 AM

Quote:

Originally Posted by unSpawn (Post 3888993)
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".

unSpawn 03-07-2010 03:55 AM

You don't have to 'crontab -e' to see "/root/backup.sh", just 'crontab -l'. Now. What's this backup script supposed to do?

repo 03-07-2010 03:55 AM

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.

windstory 03-07-2010 07:57 AM

Quote:

Originally Posted by repo (Post 3889006)
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.

windstory 03-07-2010 07:59 AM

Quote:

Originally Posted by unSpawn (Post 3889005)
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

repo 03-07-2010 08:30 AM

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?

windstory 03-07-2010 08:38 AM

Quote:

Originally Posted by repo (Post 3889170)
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.

repo 03-07-2010 08:57 AM

Did you added the path to all the commands and files in the script?

windstory 03-07-2010 09:06 AM

Quote:

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


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