Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
ok...I made this simple shell script to backup some folders to a zip disk.
well, it works fine when I execute it [as root] manually.
everything works as it should. Makes some tarballs for Data, evolution, and FTP...then it backs up data.tar.gz and emails.tar.gz to my zip disk. Again, it does the job if executed manually.
However, when I schedule it via cron [for root #crontab -l reads 55 22 * * * /backup.sh] it executes only part of it. It just creates the tarball for the Data folder then it stops.
any ideas why is not running the whole thing via cron?
#!/bin/bash
#/backup.sh
#script to backup some tarballed folders on to a zip disk
# it shows what I am backing up
tar -cvzpf $DATA /home/sphinx/Data
tar -cvzpf $EMAIL /home/sphinx/evolution
echo "Now working on FTP folder..."
tar -cvzpf $FTP /home/sphinx/FTP
mount /mnt/zip #mounts the zip disk
rm -rf /mnt/zip/* #it erases the zip disk before dumping tarballs
cp $DATA /mnt/zip
cp $EMAIL /mnt/zip
umount /mnt/zip #unmounts zip drive
eject /mnt/zip #ejects zip disk
My guess is its an access permissions problem. Have you checked for differences in the permissions on those directories? I'm not sure what permissions the script has when executed by cron.
I even set it up chmod 777 [it was just for testing on made up test directories anyway ] backup.sh, the data, the email, and the FTP.... to make sure.
and still...when I run the backup.sh script manually, it does the job. When cron runs it....it tarballs the Data directory leaving out emails and FTP directories. In fact, cron doesn't even get to the part where it tarballs emails, FTP...
Well, start doing some diagnostics.
Have your script append stuff to a file:
tar ....
echo "return from tar=$?" >> diagnostic.txt
tar ....
echo "return from second tar=$?" >> diagnostic.txt
and so on. See how far it gets and maybe it will become obvious.
You might also have it right out the values of environment variables, like $USER, etc.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.