LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 10-15-2023, 07:41 PM   #1
alex4buba
Member
 
Registered: Jul 2020
Posts: 624

Rep: Reputation: Disabled
Rsync daily backup


I am using a HP Probook and have done a rsync executeb by task scheduler on KDE Neon Plasma.

I am using this script for the past 2 years and it just works, but recently, it works only at times. When it works, it produces one format of log file, when however i execute it manually, the same script produces another outpit format.

So, how do I find out, why it is not working at time - for example, the last 2 lines in the image I am attaching here of the 15th October, is manual execution, why it didn't work? The 2nd question is why the log out is changing format?

Thanks for any ideas
Attached Thumbnails
Click image for larger version

Name:	dailybackup.jpg
Views:	33
Size:	193.1 KB
ID:	41861  
 
Old 10-16-2023, 09:53 AM   #2
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Rep: Reputation: 110Reputation: 110
I guess you have to share the script so maybe someone can spot the bug or suggest you insert some debugging statement.
 
Old 10-16-2023, 10:43 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
To add to pan64's post
As far as I know the default format for the date command is "+%a %b %e %H:%M:%S %Z %Y" which is what you see when you manually run your script. The task scheduler is a front end for cron which uses a different environment then executing from the command line so just a wild guess the locale time format maybe changing between the two. I don't know what version of cron plasma is using which sets some environment variables or if the scheduler sets any environment variables itself.

Last edited by michaelk; 10-16-2023 at 10:46 AM.
 
1 members found this post helpful.
Old 10-16-2023, 07:50 PM   #4
alex4buba
Member
 
Registered: Jul 2020
Posts: 624

Original Poster
Rep: Reputation: Disabled
Hello friends

My main concern ofcourse is why my script is not working regularly, the date format is not a real concern.

Here below is my script

Quote:
GNU nano 6.2 anajob.sh M
#!/bin/bash
#To wake up the external drive
#partprobe /media/alexe/Elements

#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/
astatus=$?
/usr/bin/rsync -a /home/alexe/Desktop /media/alexe/Elements/$ldow/
dstatus=$?


[ $astatus -eq 0 ] && echo "$(date) My_Stuff rsync completed successfully" >> /home/alexe/Desktop/dailyBackup>

[ $dstatus -eq 0 ] && echo "$(date) Desktop rsync completed successfully" >> /home/alexe/Desktop/dailyBackup.>

As you can see, the job is executed to perform two tasks.

Hope someone can give me a hint

Cheers
 
Old 10-16-2023, 08:13 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Save the actual exit status value as well as saving the stderr output if any to a file to see what is happening.
 
Old 10-16-2023, 08:16 PM   #6
alex4buba
Member
 
Registered: Jul 2020
Posts: 624

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Save the actual exit status value as well as saving the stderr output if any to a file to see what is happening.
OK, I have no idea, how do I do that?

Many thanks
 
Old 10-16-2023, 08:33 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Code:
/usr/bin/rsync -a /home/alexe/afolders/ /media/alexe/Elements/$ldow/ 2>/path/to/error.log
...
echo "$(date) My stuff status=$astatus Desktop status=$dstatus" >> /path/to/status.log
Normally when you execute a program from the command line both stderr and stdout are written to the terminal. The stream number for stderr is 2.
 
Old 10-17-2023, 01:37 AM   #8
alex4buba
Member
 
Registered: Jul 2020
Posts: 624

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Code:
/usr/bin/rsync -a /home/alexe/afolders/ /media/alexe/Elements/$ldow/ 2>/path/to/error.log
...
echo "$(date) My stuff status=$astatus Desktop status=$dstatus" >> /path/to/status.log
Normally when you execute a program from the command line both stderr and stdout are written to the terminal. The stream number for stderr is 2.
I never execute this via command line. When I run the script manually, I do it via the GUI interface
System Settings->Startup and Shut Down->Task scheduler->Daily Backup

So, how will I chane the script?

Please note, in the current script i have two jobs, but for this exercise, I can skip the Desktop job.

Thanks again
 
Old 10-17-2023, 10:12 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Code:
#!/bin/bash
#To wake up the external drive
#partprobe /media/alexe/Elements

#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"/ 2>/path/to/error.log
astatus=$?
/usr/bin/rsync -a /home/alexe/Desktop /media/alexe/Elements/"$ldow"/ 2>/path/to/error.log
dstatus=$?

if [ $astatus -eq 0 ]; then
   echo "$(date) My_Stuff rsync completed successfully" >> /home/alexe/Desktop/dailyBackup
else
   echo "$(date) My_Stuff rsync error $astatus" >> /home/alexe/Desktop/dailyBackup
fi

if [ $dstatus -eq 0 ]; then
   echo "$(date) Desktop rsync completed successfully" >> /home/alexe/Desktop/dailyBackup
else
   echo "$(date) Desktop rsync error $dstatus" >> /home/alexe/Desktop/dailyBackup
 
Old 10-18-2023, 05:10 PM   #10
alex4buba
Member
 
Registered: Jul 2020
Posts: 624

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Code:
#!/bin/bash
#To wake up the external drive
#partprobe /media/alexe/Elements

#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"/ 2>/path/to/error.log
astatus=$?
/usr/bin/rsync -a /home/alexe/Desktop /media/alexe/Elements/"$ldow"/ 2>/path/to/error.log
dstatus=$?

if [ $astatus -eq 0 ]; then
   echo "$(date) My_Stuff rsync completed successfully" >> /home/alexe/Desktop/dailyBackup
else
   echo "$(date) My_Stuff rsync error $astatus" >> /home/alexe/Desktop/dailyBackup
fi

if [ $dstatus -eq 0 ]; then
   echo "$(date) Desktop rsync completed successfully" >> /home/alexe/Desktop/dailyBackup
else
   echo "$(date) Desktop rsync error $dstatus" >> /home/alexe/Desktop/dailyBackup
The problem is, that when the script does not run, there is NO output, just nothing happens.
This in my mind, means that something is wrong in my KDE setup, noothing wrong with the script itself.

Any suggestions?
Thanks again
 
Old 10-18-2023, 05:41 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Can you post a screenshot of your task scheduler?
 
Old 10-18-2023, 07:06 PM   #12
alex4buba
Member
 
Registered: Jul 2020
Posts: 624

Original Poster
Rep: Reputation: Disabled
Tasks image

Quote:
Originally Posted by michaelk View Post
Can you post a screenshot of your task scheduler?
Please see attached
Thank you
Attached Thumbnails
Click image for larger version

Name:	task_scheduler.jpg
Views:	9
Size:	130.1 KB
ID:	41873  
 
Old 10-18-2023, 07:25 PM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Not much help there. Is your computer on 24/7 or is it on by 8:30 in the morning? cron jobs do not run if the computer is not running at the scheduled time. Otherwise you might want to consider using anacron instead. You can not select that exact runtime but it is guaranteed to run regardless of when the computer is turned on.
 
Old 10-18-2023, 07:42 PM   #14
alex4buba
Member
 
Registered: Jul 2020
Posts: 624

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Not much help there. Is your computer on 24/7 or is it on by 8:30 in the morning? cron jobs do not run if the computer is not running at the scheduled time. Otherwise you might want to consider using anacron instead. You can not select that exact runtime but it is guaranteed to run regardless of when the computer is turned on.
The computer is ON 24/7 otherwise, how will any job run on it?

Thanks
 
Old 10-18-2023, 07:48 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,783

Rep: Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936Reputation: 5936
Have you checked the cron logs to see if the script is actually started. The only time you will see output from your script is if status is zero.

You can run jobs using anacron.

Last edited by michaelk; 10-18-2023 at 07:50 PM.
 
  


Reply

Tags
rsync, task



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup (rsync) -> [E] Error: rsync: [sender] write error: Broken pipe (32) JZL240I-U Linux - Software 10 09-21-2021 11:49 AM
Scripts in cron.daily are not running daily abefroman Linux - Server 1 12-23-2014 12:11 PM
how can backup a remote server(only folder needed) with ftp ,daily backup? ahjafari Linux - Newbie 1 10-26-2011 04:04 PM
LXer: Backup with rsync and rsync.net LXer Syndicated Linux News 0 09-14-2010 04:20 PM
Advice? Best way to move files daily to a daily "date" named directory ziphem Linux - Newbie 2 04-15-2007 08:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration