Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
From your post it does not look like the posted code is all on one line.
Code:
#get day of week
dow=$(/usr/bin/date "+%a")
# convert DOW to lower case i.e. Mon to mon
ldow=${dow,,}
/usr/bin/rsync -a /home/alexe/afolders/ /media/alexe/Elements/$ldow/
status=$?
[ $status -eq 0 ] && echo "$(date) rsync completed successfully" >> /home/alexe/Desktop/afolders.txt \
|| echo "$(date) rsync failed" >> /home/alexe/Desktop/afolders.txt
You can add a \ at the end of the line to continue to the next. I forgot to post writing date timestmap at the end of your rsync command should be removed since it is being handled by the test code now.
From your post it does not look like the posted code is all on one line.
Code:
#get day of week
dow=$(/usr/bin/date "+%a")
# convert DOW to lower case i.e. Mon to mon
ldow=${dow,,}
/usr/bin/rsync -a /home/alexe/afolders/ /media/alexe/Elements/$ldow/
status=$?
[ $status -eq 0 ] && echo "$(date) rsync completed successfully" >> /home/alexe/Desktop/afolders.txt \
|| echo "$(date) rsync failed" >> /home/alexe/Desktop/afolders.txt
You can add a \ at the end of the line to continue to the next. I forgot to posted writing date timestmap at the end of your rsync command should be removed since it is being handled by the test code now.
This variant will include an eventual output from rsync:
Code:
if
/usr/bin/rsync -a /home/alexe/afolders/ /media/alexe/Elements/$ldow/ 2>&1
then
echo "$(date) rsync completed successfully"
else
echo "$(date) rsync failed"
fi >> /home/alexe/Desktop/afolders.txt
The above command is producing the following output:
But, there is no indication if the backup worked or not. Is there a way to show this on the same line?
Many thanks
Sure.
add the following after the rsync command on the same line, before the redirect.
Code:
; if [ $? -eq 0 ] ; then echo "backup complete $(date)" ; else echo "backup failed $(date)" ; fi
The redirect would now echo your message to the log file.
This way it will always write the line echoed when the backup completes, indicating complete or failure. You can then peruse the log file and see the days when it completed or failed.
There are many other options depending upon why rsync failed and using the messages in $? when it completes you can easily tailor the message written to the actual status.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.