Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hi i have a script in my crontab it was working and all of a sudden it stopped working and i have run the script from the CLI and it works fine does anyone have any idea what can cause this.
# set smb server and auth vars
sharepoint="//10.0.5.5/share"
username="user"
password="passdw"
#Set sbm point for second share on NAS
sharepoint2="//10.0.5.5/share2"
username2="user2"
password2="passwd2"
#set mysql details
mysqlhost="localhost"
mysqlusername="root"
#mysqlpasswd="mysqlpasswordhere"
#set which folder locations we want to backup, inc trailing slashes
#add more here and append to the appropriate tar line further down the script if needed
# make sure our working folders are present and accounted for
if [ ! -d "${backuptemp}" ] >> /tmp/serverbk.log
then
mkdir $backuptemp >> /tmp/serverbk.log
fi
if [ ! -d "${savepath}" ] >> /tmp/serverbk.log
then
mkdir $savepath >> /tmp/serverbk.log
fi
# tar up the files we want into the backup temp
tar -zcf ${backuptemp}files.tar.gz $location1 $location2 $location3 $location4 >> /tmp/serverbk.log
#dump the local mysql db into the backup temp
mysqldump --host=${mysqlhost} --user=${mysqluser} --all-databases --lock-tables --complete-insert --verbose --no-create-info --result-file=${backuptemp}mysqldumpdb$(date +%F).sql >> /tmp/serverbk.log
mysqldump --host=${mysqlhost} --user=${mysqluser} --all-databases --lock-tables --complete-insert --verbose --no-data --result-file=${backuptemp}mysqldumpnodata$(date +%F).sql >> /tmp/serverbk.log
#tar up the backup temp folder
echo "Creating tar ball"
tar -cvzf $savepath$filename $backuptemp >> /tmp/serverbk.log
echo "tar ball created"
#connect the smb share to our mount point
if umount $mountpoint >> /tmp/serverbk.log
then
echo "NAS Share Unmounted" >> /tmp/serverbk.log
fi
if mount -t cifs -o username=$username,password=$password $sharepoint $mountpoint >> /tmp/serverbk.log
then
echo "NAS Share mounted" >> /tmp/serverbk.log
fi
# copy the tar (could also move it but whatever you like)
echo "Moving Backup to NAS" >> /tmp/serverbk.log
if rsync -avz $savepath$filename $mountpoint >> /tmp/serverbk.log
then
echo "Backup of First Server Complete" >> /tmp/serverbk.log
else
echo "Backup of First Server Incomplete" >> /tmp/serverbk.log
fi
# disconnect the share
umount $mountpoint >> /tmp/serverbk.log
if umount $mountpoint2 >> /tmp/serverbk.log
then
echo "NAS Second Share Unmounted" >> /tmp/serverbk.log
fi
if mount -t cifs -o username=$username2,password=$password2 $sharepoint2 $mountpoint2 >> /tmp/serverbk.log
then
echo "NAS Second Share mounted" >> /tmp/serverbk.log
fi
if rsync -avz $savepath2 $mountpoint2 >> /tmp/serverbk.log
then
echo "Backup of Second Server Complete" >> /tmp/serverbk.log
else
echo "Backup of Second Server Incomplete" >> /tmp/serverbk.log
fi
mv /web_backup/* /web_server/
umount $mountpoint2 >> /tmp/serverbk.log
echo "Backup Finished at $(date +%c)" >> /tmp/serverbk.log
Do you get any email notifications of errors for the user whose crontab the script is called from? If so, what?
You should check where the programs which are used in the script are located (do a "which" for each one). If any of them are outside the PATH specified in the /etc/crontab, then you will need to adjust your script to add the proper directories to the PATH.
As far as I can tell, this is all the external programs which the script calls:
mkdir
hostname
tar
mysqldump
mount
umount
rsync
Last edited by matthewg42; 07-09-2008 at 09:30 AM.
no i dont get any errors or emails from cron or that the script has finished or there was an error while running the script
also i have a similar script running on my other server and that works fine and they both have the same OS installed
also im running the script as root and all the paths are in the /etc/crontab/
MAILTO=support@example.net
5 1 * * Mon-Fri /root/working
what is really funny is the script runs when i do it manually
is it possible that the rysnc is taking so long over 8 hours to rsync 9G of data
Hmm strange. There should be no space between the "-" and the "v" or "x". Perhaps you made a typo when editing the script? The first line of the script should look like this:
Code:
#!/bin/sh -v -x
If that is how you have it, then it must be some weird shell which doesn't support the -v and -x options (I thought these were part of the POSIX standard... Maybe not).
So then the question becomes "what shell is it?" Some shells like (bash) support the --version option, which you can use like this (just do this in a terminal):
Code:
/bin/sh --version
Hopefully you will get some output like this which itentifies the shell:
Code:
GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
Some shells don't support the --version option. For these, maybe the /bin/sh is a symlink to a different binary. For example, on my Ubuntu system:
# set smb server and auth vars
sharepoint="//10.0.5.5/share"
+ sharepoint=//10.0.5.5/share
username="share"
+ username=user
password="passwd"
+ password=passwd
#Set sbm point for second share on NAS
sharepoint2="//10.0.5.5/share2"
+ sharepoint2=//10.0.5.5/
username2="user1"
+ username2=user1
password2="passwd"
+ password2=passwd
#set mysql details
mysqlhost="localhost"
+ mysqlhost=localhost
mysqlusername="root"
+ mysqlusername=root
#mysqlpasswd="mysqlpasswordhere"
#set which folder locations we want to backup, inc trailing slashes
#add more here and append to the appropriate tar line further down the script if needed
#dump the local mysql db into the backup temp
mysqldump --host=${mysqlhost} --user=${mysqluser} --all-databases --lock-tables --complete-insert --verbose --no-create-info --result-file=${backuptemp}mysqldumpdb$(date +%F).sql >> /tmp/serverbk.log
date +%F
++ date +%F
+ mysqldump --host=localhost --user= --all-databases --lock-tables --complete-insert --verbose --no-create-info --result-file=/backuptmp/mysqldumpdb2008-07-10.sql
-- Connecting to localhost...
-- Retrieving table structure for table columns_priv...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table db...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table func...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table help_category...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table help_keyword...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table help_relation...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table help_topic...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table host...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table proc...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table procs_priv...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table tables_priv...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table time_zone...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table time_zone_leap_second...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table time_zone_name...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table time_zone_transition...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table time_zone_transition_type...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table user...
-- Sending SELECT query...
-- Retrieving rows...
-- Disconnecting from localhost...
mysqldump --host=${mysqlhost} --user=${mysqluser} --all-databases --lock-tables --complete-insert --verbose --no-data --result-file=${backuptemp}mysqldumpnodata$(date +%F).sql >> /tmp/serverbk.log
date +%F
++ date +%F
+ mysqldump --host=localhost --user= --all-databases --lock-tables --complete-insert --verbose --no-data --result-file=/backuptmp/mysqldumpnodata2008-07-10.sql
-- Connecting to localhost...
-- Retrieving table structure for table columns_priv...
-- Skipping dump data for table 'columns_priv', --no-data was used
-- Retrieving table structure for table db...
-- Skipping dump data for table 'db', --no-data was used
-- Retrieving table structure for table func...
-- Skipping dump data for table 'func', --no-data was used
-- Retrieving table structure for table help_category...
-- Skipping dump data for table 'help_category', --no-data was used
-- Retrieving table structure for table help_keyword...
-- Skipping dump data for table 'help_keyword', --no-data was used
-- Retrieving table structure for table help_relation...
-- Skipping dump data for table 'help_relation', --no-data was used
-- Retrieving table structure for table help_topic...
-- Skipping dump data for table 'help_topic', --no-data was used
-- Retrieving table structure for table host...
-- Skipping dump data for table 'host', --no-data was used
-- Retrieving table structure for table proc...
-- Skipping dump data for table 'proc', --no-data was used
-- Retrieving table structure for table procs_priv...
-- Skipping dump data for table 'procs_priv', --no-data was used
-- Retrieving table structure for table tables_priv...
-- Skipping dump data for table 'tables_priv', --no-data was used
-- Retrieving table structure for table time_zone...
-- Skipping dump data for table 'time_zone', --no-data was used
-- Retrieving table structure for table time_zone_leap_second...
-- Skipping dump data for table 'time_zone_leap_second', --no-data was used
-- Retrieving table structure for table time_zone_name...
-- Skipping dump data for table 'time_zone_name', --no-data was used
-- Retrieving table structure for table time_zone_transition...
-- Skipping dump data for table 'time_zone_transition', --no-data was used
-- Retrieving table structure for table time_zone_transition_type...
-- Skipping dump data for table 'time_zone_transition_type', --no-data was used
-- Retrieving table structure for table user...
-- Skipping dump data for table 'user', --no-data was used
-- Disconnecting from localhost...
#tar up the backup temp folder
echo "Creating tar ball"
+ echo 'Creating tar ball'
Creating tar ball
tar -cvzf $savepath$filename $backuptemp >> /tmp/serverbk.log
+ tar -cvzf /backup/server.backup.2008-07-10.tar.gz /backuptmp/
tar: Removing leading `/' from member names
echo "tar ball created"
+ echo 'tar ball created'
tar ball created
#connect the smb share to our mount point
if umount $mountpoint >> /tmp/serverbk.log
then
echo "NAS Share Unmounted" >> /tmp/serverbk.log
fi
+ umount /mnt/nas/
umount: /mnt/nas/: not mounted
if mount -t cifs -o username=$username,password=$password $sharepoint $mountpoint >> /tmp/serverbk.log
then
echo "NAS Share mounted" >> /tmp/serverbk.log
fi
+ mount -t cifs -o username=user,password=passwd //10.0.5.5/share /mnt/nas/
+ echo 'NAS Share mounted'
# copy the tar (could also move it but whatever you like)
echo "Moving Backup to NAS" >> /tmp/serverbk.log
+ echo 'Moving Backup to NAS'
if rsync -avz $savepath$filename $mountpoint >> /tmp/serverbk.log
then
echo "Backup of First Server Complete" >> /tmp/serverbk.log
else
echo "Backup of First Server Incomplete" >> /tmp/serverbk.log
fi
+ rsync -avz /backup/server.backup.2008-07-10.tar.gz /mnt/nas/
+ echo 'Backup of First Server Complete'
if umount $mountpoint2 >> /tmp/serverbk.log
then
echo "NAS Second Share Unmounted" >> /tmp/serverbk.log
fi
+ umount /mnt/nas2/
umount: /mnt/nas2/: not mounted
if mount -t cifs -o username=$username2,password=$password2 $sharepoint2 $mountpoint2 >> /tmp/serverbk.log
then
echo "NAS Second Share mounted" >> /tmp/serverbk.log
fi
+ mount -t cifs -o username=user1,password=passwd1 //10.0.5.5/share1 /mnt/nas2/
+ echo 'NAS Second Share mounted'
if rsync -avz $savepath2 $mountpoint2 >> /tmp/serverbk.log
then
echo "Backup of Second Server Complete" >> /tmp/serverbk.log
else
echo "Backup of Second Server Incomplete" >> /tmp/serverbk.log
fi
+ rsync -avz /web_backup/ /mnt/nas2/
+ echo 'Backup of Second Server Complete'
mv /web_backup/* /web_server/
+ mv '/web_backup/*' /web_server/
mv: cannot stat `/web_backup/*': No such file or directory
umount $mountpoint2 >> /tmp/serverbk.log
+ umount /mnt/nas2/
echo "Backup Finished at $(date +%c)" >> /tmp/serverbk.log
date +%c
++ date +%c
+ echo 'Backup Finished at Thu 10 Jul 2008 16:00:45 BST'
#all done
That's a lot of output. It did something. Perhaps you can look through it line by line to see if there are any problems.
As an aside, this is a bit dangerous:
rm -rf /backup*
if you accidentally place a space between the p and the *, you will lose your entire system. While this is very unlikely, it is just too catastrophic if it does happen. In general:
1) don't place working stuff in /
2) be very careful with wildcards, esp with rm -rf.
the out put happened when i ran the script in the CLI
nothing happens when the crontab runs it
the serverbk.log file will be empty nothing in it its really confusing me as well
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.