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.
I have set up a backup system where I work using rsnapshot which works great. I use it to back up 4 linux servers and 4 windows servers which are mounted on the server I use to run rsnapshot on. It works great and I am well pleased with it. I have one small problem, I am trying to create a little script which runs the 'rsnapshot du' command and then outputs the data into a file which I can then read anytime. The reason is that the backups in total are almost 500gb and running rsnapshot du command can sometimes take over an hour to give all the results. So my idea was to have a script which runs each morning at 8am, and outputs into a file which I then set up an alias to output the contents of that file using 'cat'. However I cannot seem to get the script to actually put the output of the command into the file. Its quite strange, if I run the script manually, it seems to work fine. But whenever I add it to cron, it just seems to create an empty file. I know the script is executing because the script also uses the date command to put the time and date the script was run at the top. Am I missing something here, I am quite a noob and was wondering if I would perhaps need to append each line output from 'rsnapshot du' into a variable first and then append it into a file. Any suggestions would be gratefully received.
Show us the script.
The usual problem in these situations is that cron has a very minimal env, inc $PATH setting, so the rule is:
always specify complete absolute paths to all programs called & files used when in cron.
You were spot on, I added the full path to rsnapshot and it worked fine. Was confused as it ran fine manually, just didn't run when it was run by cron. Here is the final script:
#!/bin/bash
# script runs 'rsnapshot du' after each twicedaily job completes
# and outputs to 'filename', called from /bin/bkpfinishedemail
# first writes to a tempfile and then copies the contents of the
# tempfile to filename so that filename never holds a half full copy
# of the log if someone tries to read it while it is being written to
tempfilename=/root/logs/rs_du_output_temp.txt
filename=/root/logs/rs_du_output.txt
backup_mount_point=/media/backups
if [ ! -e $tempfilename ]
then
touch $tempfilename
fi
if [ ! -e $filename ]
then
touch $filename
fi
if grep -q $backup_mount_point /etc/mtab
then
date '+DATE: %d/%m/%Y TIME:%H:%M:%S%n%n' > $tempfilename
/usr/local/bin/rsnapshot du >> $tempfilename
cat $tempfilename > $filename
exit 0
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.