Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cronjob issues with 18.04, it's not working, or i'm not.
#11
(09-10-2018, 04:55 AM)deck_luck Wrote: Did you try reply #8 using the simple_out script with the export DISPLAY=":0" inside the script?   You do not have to have every zenity with "env DISPLAY=":0" prefix with your bash script.  Inside the bash script once the export DISPLAY=":0" is set all subsequent command will have access to the environment variable.    Just like the send-notifiy command in the example script.

ya that's where i got it. thanks deck_luck its hard to see that grey text in dark theme. so i didn't see it at first. and misunderstood the original post and tried to put it in the crontab. which didn't work.
its thing like  this that keep a man humble.

i gave you a vote up
Thank you.
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#12
You apparently have two post on the same topic.  The first post was https://www.ezeelinux.com/talk/printthread.php?tid=211. and, it has the backup script content.  Your script runs rsync then has popup message indicating "Rysnc has finished." as well as echo "BACKUP success-$TODAY " to a log file.  What do you consider successful?  Just because the rsync was executed does not indicate it successfully ran.   If the attempted backups are important and they are, you should evaluate the rsync exit code to determine if any failure(s) occurred or if it was indeed successful.   Likewise, you should have a log file capturing the rsync output.   Also, the log file will help with problem determination if rsync does fail.   Does that make sense?
Idea Give a person a fish, and you feed them for a day. Teach a person how to fish, and you feed them for a lifetime. ✝️ Proverbs 4:7 Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding.  (Linux Mint 19 XFCE)
Reply
#13
(09-10-2018, 05:58 AM)deck_luck Wrote: you should evaluate the rsync exit code to determine if any failure(s) occurred or if it was indeed successful.

Just quickly chiming in here:

To those who don't know: The exit status of a program in bash gets automatically stored in the '$?' variable.
Any sane program will have an exit status of '0' if it run succesful.
Anything above zero indicates something went wrong.
Some programs explain their exit status in their manpage.

So all in all, this should be easy to implement.


And to reroute 'stderr' of rsync to a log file, do the following:
Code:
rsync 2> logfile.txt
Reply
#14
I am sorry guys, I really Thought i had removed that script in the post. because it had changed so much. I changed it to grep any errors or issues to that same file in a secondary script with an if then, to tell me if there was a problem, and say so in the zenity popup as well as the log file. that was done the second day. when I was testing the script. I realized it said SUCCESS even if though it was failing. But yeah, you all are right. That was dumb of me.


now the output looks like this.
Code:
#### Starting New MANUAL Rsync Job ####

#### Here Is The Output ####

opening connection using: ssh -p 22 xxx.xxx.x.xx rsync --server -xxxxxxxxxxx.xxxxxx --delete-after --ignore-errors . /home/eli/FLAT-BAK  (11 args)
rsync: opendir "/home/eli/.config/htop" failed: Permission denied (13)
[sender] expand file_list pointer array to 524288 bytes, did move
[Receiver] expand file_list pointer array to 524288 bytes, did move
total: matches=4385  hash_hits=7107  false_alarms=0 data=542551
sent 1,437,436 bytes  received 3,294,151 bytes  411,442.35 bytes/sec
total size is 126,021,499,250  speedup is 26,634.09
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]

MANUAL BACKUP finished successfully but with errors-Mon Sep 10 17:28:59 CDT 2018



#### Starting New MANUAL Rsync Job ####

#### Here Is The Output ####

opening connection using: ssh -p 22 xxx.xxx.x.xx rsync --server -xxxxxxxxxxx.xxxxxx --delete-after --ignore-errors . /home/eli/FLAT-BAK  (11 args)
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]

MANUAL BACKUP FAILED!-Mon Sep 10 19:54:26 CDT 2018
the last entry was from running rsync with the other machine turned off to test the script.

Its good to know that if i had not caught that, That you would have.  And you did. thanks again.

currently i am using 3 scripts back to back to achieve that. the first one i run with
/path/to/./backup-my-stuff.sh > /save/output/here/file.log.  && (/path/to/grep-script/grep-this.sh) or (grep 'the things\|i want\|searched' /save/output/here/file.log >> /save/the/grep/info/here/file2.log)
that first script sets the niceness and checks to see if it is on a battery, then calls the actual rsync.sh and then when that is closed it opens the grep script.  i would like to combine them all into one script. that does it all in one bang.
so that i just have to run ./backup-my-stuff.sh and it does it all.


also this is an old script for the actual system files, i have used it many years. but i haven't tested it in a long time.
Code:
#!/bin/bash

set -e
# run  daily in sudo crontab
sudo su && touch /home/eli/Scripts/Restore/Repo.keys && cp -R /etc/apt/sources.list* /home/eli/Scripts/Restore/ && apt-key exportall > /home/eli/Scripts/Restore/Repo.keys
exit




and to restore
Code:
#!/bin/bash

#run as root
apt-key add ~/Scripts/Restore/Repo.keys
cp -R ~/Scripts/Restore/sources.list* /etc/apt/
apt-get update
apt-get install dselect
dselect update
dpkg --set-selections < ~/Scrips/Restore/Package.list
apt-get dselect-upgrade -y


very simple script. but like i said, i have not tested it in a while and unless dselect has changed it should still work, right?

(09-10-2018, 11:04 AM)leon.p Wrote:
(09-10-2018, 05:58 AM)deck_luck Wrote: you should evaluate the rsync exit code to determine if any failure(s) occurred or if it was indeed successful.

Just quickly chiming in here:

To those who don't know: The exit status of a program in bash gets automatically stored in the '$?' variable.
Any sane program will have an exit status of '0' if it run succesful.
Anything above zero indicates something went wrong.
Some programs explain their exit status in their manpage.

So all in all, this should be easy to implement.


And to reroute 'stderr' of rsync to a log file, do the following:
Code:
rsync 2> logfile.txt
yeah, I have an  "alias" for my rsync so its easy to run manually. I have it as this,

Code:
alias cbk="clear ; cd /home/eli/Scripts ; ./cron-rsync-4-bkup-sh-m > /home/eli/Scripts/cron-rsync-4-bkupsh.log 2>&1 && grep 'sent \|total size\|connection\|sender] expand\|Receiver] expand\|total: \|failed: \|Permission\|rsync error\|error ' /home/eli/Scripts/cron-rsync-4-bkupsh.log >> /home/eli/Scripts/cron-rsync-4-bkup-sh.log"
And the scripts have been updated as well. this is messy, but it gets the job done. And It gives me the FULL output (30,000+ lines of text), which is overwritten every day. and a short version which is appended to an existing log file. Which I show in a post above.

this is all really great info. thank you

(09-10-2018, 05:58 AM)deck_luck Wrote: You apparently have two post on the same topic.  The first post was https://www.ezeelinux.com/talk/printthread.php?tid=211. and, it has the backup script content.  Your script runs rsync then has popup message indicating "Rysnc has finished." as well as echo "BACKUP success-$TODAY " to a log file.  What do you consider successful?  Just because the rsync was executed does not indicate it successfully ran.   If the attempted backups are important and they are, you should evaluate the rsync exit code to determine if any failure(s) occurred or if it was indeed successful.   Likewise, you should have a log file capturing the rsync output.   Also, the log file will help with problem determination if rsync does fail.   Does that make sense?
how strange. i only posted it here. i don't know why it would be echoed there. but i didn't post it twice.
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#15
I thought i would give an update.

I have condensed the three scripts into two. the script that launches the rsync script also logs and greps it after it is done.
here are the scripts.

this is the one that is actually launched
Code:
#!/bin/bash
exec > >(tee -i /home/eli/Scripts/rsync-long.log)

echo ""
echo "##### start of new job #####"
echo ""
# Put the path/script you want it to call here.
BKup1="/home/eli/Scripts/bkup-a.sh"

egrep -q '(envID|VxID):.*[1-9]' /proc/self/status || IONICE=/usr/bin/ionice

# Checks if your on the battery
if which on_ac_power >/dev/null 2>&1; then
   on_ac_power >/dev/null 2>&1
   ON_BATTERY=$?

# Before you ask,,, the answer is "because it works this way".
   [ "$ON_BATTERY" -eq 1 ] && echo "It is not safe to run rsync when on the laptop battery. this script is now closed"&&echo "" && exit 0
fi

# Rebuild the index
if [ -x "$BKup1" ]
then
    if [ -x "$IONICE" ]
    then
        nice -n 19 $IONICE -c 3 $BKup1 --quiet
    else
        nice -n 19 $BKup1 --quiet
    fi
fi
###
#output
echo ""
echo "##### END OF OUTPUT #####"
echo ""


exec 2>&1
###
#Grepit


grep -i --color 'sent \|total size\|connection\|sender] expand\|deleting eli\|total: \|Receiver] expand\|total: \|failed: \|Permission\|rsync error\|error ' /home/eli/Scripts/rsync-long.log >> /home/eli/Scripts/rsync-bkup.log

echo ""  >> /home/eli/Scripts/rsync-bkup.log
echo "##################################################################################################"  >> /home/eli/Scripts/rsync-bkup.log
echo "########################################### END OF OUTPUT ########################################"  >> /home/eli/Scripts/rsync-bkup.log
echo "##################################################################################################"  >> /home/eli/Scripts/rsync-bkup.log
echo "" >&2


this allows me to just use ./launch-rsync.sh
it does all the rest.

then the rsync.sh

Code:
#!/bin/bash
#
# This is a simple zenity script to backup your files with rsync

## Remote User Name Here
USR1='my-user-name'

## Remote IP here
IP1='XXX.XXX.X.XX'
export DISPLAY=:0
# Save it remotely
MYHOME="/home/$USER"
DEST="/home/$USER/FLAT-BAK"
HMdoc='/home/$USER/Documents'
HMscr='/home/$USER/Scripts'
RsYnC="$MYHOME $IP1:$DEST"
TODAY="$(date)"
#LOG2="$HMdoc/BACKUP_success.log"
LOG="$HMscr/rsync-bkup.log"

### option to quit
#env DISPLAY=:0 \
zenity \
--question \
--width=200 \
--title="Rsync Backup" \
--timeout=15 \
--cancel-label="cancel" \
--ok-label="continue" \
--text="Cronjob Rsync has Started\nYou Have 10 Seconds To cancel."
     if [ "$?" = "1" ]
        then exit 0
     fi
echo -e "\n\n#### Starting New Auto Rsync Job ####" >> $LOG
### The actual rsync
### With The delete-after Option Added and exclude option
### deletes files on remote that are no longer on source.
rsync -avvzp -e 'ssh -p 22' \
--exclude='VirtualBox VMs/' \
--exclude=".local/" \
--exclude="Git-Stuff/" \
--exclude=".bash_history" \
--exclude=".zhistory" \
--exclude=".ssh/" \
--exclude='BOX/' \
--exclude="htop/" \
--exclude=".mozilla/" \
--exclude=".cache/" \
--ignore-errors \
$RsYnC \
--delete-after
touch $LOG
#env DISPLAY=:0
#echo "the exit code was ($?)"
# fail popup doesn't go away until clicked.
  if [ "$?" = "0" ]
    then  echo "" >> "$LOG"
          echo -e "AUTO BACKUP Success! -$TODAY \n\n#### Here Is The Output ####\n" >> "$LOG"
          zenity --info --width=200 --title="AUTO Rsync Backup" --text "          AUTO Rsync \nHas finnshed Successfully." --timeout=60
     else echo "" >> "$LOG"
          echo -e "AUTO BACKUP FAILED! -$TODAY \n\n#### Here Is The Output ####\n" >> "$LOG"
          zenity --info --width=300 --title="Rsync Backup" --text "Rsync Backup Has Failed! \nA Log File Was Made Here. \n$HMscr/rsync-bkup.log \n\nOr The Full File Here\n$HMscr/rsync-long.log"

  fi

exit

that backs up my personal files, sends a 30,000* line text log to rsync-long.log
and the first script then greps it and sends thatinfo it to a file called rsync.log

and this is the basic output of that
Code:
##################################################################################################


#### Starting New MANUAL Rsync Job ####

MANUAL BACKUP Success! -Wed Sep 12 00:12:32 CDT 2018

#### Here Is The Output ####

opening connection using: ssh -p 22 192.168.1.75 rsync --server -vvlogDtprze.iLsfxC --delete-after --ignore-errors . /home/eli/FLAT-BAK  (11 args)
[sender] expand file_list pointer array to 524288 bytes, did move
[Receiver] expand file_list pointer array to 524288 bytes, did move
total: matches=9337  hash_hits=9965  false_alarms=0 data=26246
sent 1,088,874 bytes  received 3,333,743 bytes  196,560.76 bytes/sec
total size is 126,040,026,217  speedup is 28,498.97

##################################################################################################
########################################### END OF OUTPUT ########################################
##################################################################################################


#### Starting New MANUAL Rsync Job ####                     ## This was testing its response to
                                                           ## being disconnected.
MANUAL BACKUP FAILED! -Wed Sep 12 00:41:22 CDT 2018         ## everything passed except
                                                            ## the output. Basically, test failed
B#### Here Is The Output ####

opening connection using: ssh -p 22 192.168.1.75 rsync --server -vvlogDtprze.iLsfxC --delete-after --ignore-errors . /home/eli/FLAT-BAK  (11 args)

##################################################################################################
########################################### END OF OUTPUT ########################################
##################################################################################################


AUTO BACKUP Success! -Wed Sep 12 01:09:01 CDT 2018

#### Here Is The Output ####

opening connection using: ssh -p 22 xxx.xxx.xxx.xxx rsync --server -vvlogDtprze.iLsfxC --delete-after --ignore-errors . /home/eli/FLAT-BAK  (11 args)
[sender] expand file_list pointer array to 524288 bytes, did move
[Receiver] expand file_list pointer array to 524288 bytes, did move
total: matches=6678  hash_hits=18255  false_alarms=5 data=205161
sent 1,093,769 bytes  received 3,317,648 bytes  238,454.97 bytes/sec
total size is 126,040,276,500  speedup is 28,571.38

##################################################################################################
########################################### END OF OUTPUT ########################################
##################################################################################################


And there you have it. its not pretty. but it works.

Thank you all so much for your help, and advice. it really did help.

Now i am looking at the system backup settings. what is the best way to do that. i posted earlier my method. is this still solid? or is there a better way now?
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#16
Excerpts from "this is the one that is actually launched"
Code:

###  What does the cronjob entry look like?  I thought you were redirecting standard out/erro to a file.  I am confused about the following line:


exec > >(tee -i /home/eli/Scripts/rsync-long.log)


###  The tee will send output to the specific file as well as to the standard out.  What is the logic here.


...

BKup1="/home/eli/Scripts/bkup-a.sh"


### You have backup-a.sh but, you later list code for rsync.sh



Excerpts from "rsync.sh"
Code:



You need to evaluate the code checking the rsync exit code.  The excerpts from the script are as follows:

...

$RsYnC \
--delete-after
touch $LOG
#env DISPLAY=:0 
#echo "the exit code was ($?)"
# fail popup doesn't go away until clicked.
  if [ "$?" = "0" ]
    then  echo "" >> "$LOG"
...


### As long as the touch command is successful you will be indicating the backup success popup.   I am not sure why you are even using the touch in the first place and, I would suggest removing it. 
Idea Give a person a fish, and you feed them for a day. Teach a person how to fish, and you feed them for a lifetime. ✝️ Proverbs 4:7 Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding.  (Linux Mint 19 XFCE)
Reply
#17
(09-13-2018, 01:39 AM)deck_luck Wrote: Excerpts from "this is the one that is actually launched"
Code:

###  What does the cronjob entry look like?  I thought you were redirecting standard out/erro to a file.  I am confused about the following line:


exec > >(tee -i /home/eli/Scripts/rsync-long.log)


###  The tee will send output to the specific file as well as to the standard out.  What is the logic here.


...

BKup1="/home/eli/Scripts/bkup-a.sh"


### You have backup-a.sh but, you later list code for rsync.sh



Excerpts from "rsync.sh"
Code:



You need to evaluate the code checking the rsync exit code.  The excerpts from the script are as follows:

...

$RsYnC \
--delete-after
touch $LOG
#env DISPLAY=:0 
#echo "the exit code was ($?)"
# fail popup doesn't go away until clicked.
  if [ "$?" = "0" ]
    then  echo "" >> "$LOG"
...


### As long as the touch command is successful you will be indicating the backup success popup.   I am not sure why you are even using the touch in the first place and, I would suggest removing it. 

You need to evaluate the code checking the rsync exit code.  The excerpts from the script are as follows:

...

$RsYnC \
--delete-after
touch $LOG
#env DISPLAY=:0 
#echo "the exit code was ($?)"
# fail popup doesn't go away until clicked.
  if [ "$?" = "0" ]
    then  echo "" >> "$LOG"
. . .
that is interesting, i ran a fail test and it came back code 0 and i was trying to find out why. i had just found that error in the code. not 2 minutes before reading this.(it was a remnant from the beginning stages ) yeah, another dumb entry. touch has been removed.

the tee line is (if memory serves me right) so i can see the output in the terminal, and in the out put log. because i use the same template for the auto launcher as i do for the manual one. and it has little ill affect (that i can see) on the log file. it also allows for a MUCH shorter, cleaner command in crontab

Before,
30 07,22 * * * /home/eli/Scripts/cron-rsync-4-bkup-sh > /home/eli/Scripts/cron-rsync-4-bkupsh.log 2>&1 && grep 'sent \|total size\|opening connection\|sender] \|Receiver] \|rsync error' /home/eli/Scripts/cron-rsync-4-bkupsh.log >> /home/eli/Scripts/cron-rsync-4-bkup-sh.log

Now,
30 07,22 * * * /home/eli/Scripts/cron-rsync-4-bkup-sh
# and/or
@reboot /home/eli/Scripts/cron-rsync-4-bkup-sh

# those are the actual commands in my crontab

unfortunately, i know of no better way to, see the output in a terminal when launching manually, and getting decent output into a log file when launched in auto mode. all while keeping the command short ans sweet. all the information 30,000+ lines are still sent to log, but i am looking for a replacement for tee none the less. i think i can still do better. your opinions and ideas are most welcome.



### You have backup-a.sh but, you later list code for rsync.sh

Yeah, sorry about that. i was pretty tired when i posted it. i had changed its name for a short time to rsync.sh. but later changed it back to bkup-a.sh..  my bad. it is bkup-a.sh 

a couple more things to note. in bkup-a.sh (the Auto version) i have commented out the zenity popup for a successful completion. so that it only pops up on a failure.
this seems to work well.

i don't remember if i put this in a post, but i have set an alias in bash/zshrc to:
$ alias cbk="home/eli/Scripts/cron-rsync-4-bkup-m-sh"
this sets niceness and calls
bkup-m.sh script that does all the same things but is intended to be ran manually in a terminal and so has a little more terminal output. it also sends to log, in case i miss something. this also works very well.

the bkup-m.sh

Code:
#!/bin/bash
#
# This is a simple zenity script to backup your files with rsync
## Remote User Name Here
USR1='eli'
## Remote IP here
IP1='XXX.XXX.X.XX'
# Save it locally
MYHOME="/home/eli"
DEST="/home/eli/FLAT-BAK"
HMdesk='/home/eli/Desktop'
HMdoc='/home/eli/Documents'
HMscr='/home/eli/Scripts'
HMpic='/home/eli/Pictures'
HMvid='/home/eli/Videos'
HMicon='/home/eli/icons'
RsYnC="$MYHOME $IP1:$DEST"
TODAY="$(date)"
YESTERDAY=`date -d "1 day ago" +"%Y%m%d"`
LOG="$HMscr/rsync-bkup.log"

zenity \
--question \
--width=200 \
--title="MANUAL Rsync Backup" \
--timeout=15 \
--cancel-label="cancel" \
--ok-label="continue" \
--text="MANUAL Rsync has Started\nYou Have 10 Seconds To cancel."
     if [ "$?" = "1" ]
        then echo "exit 186" >>  && exit 186
         ## 186 in my country means kill, death, murder, or canceled.
         ## my terminal is set to show the actual exit code each time.
         ## this lets me know that I personally canceled it
     fi
touch "$LOG"
echo -e "\n\n#### Starting New MANUAL Rsync Job ####" >> $LOG

### The Real One
### With The delete-after Option Added and exclude option
### deletes files on remote that are no longer on source.
rsync -avvzp -e 'ssh -p 22' \
--exclude='VirtualBox VMs/' \
--exclude=".local/" \
--exclude="Git-Stuff/" \
--exclude=".bash_history" \
--exclude=".zhistory" \
--exclude=".ssh/" \
--exclude='BOX/' \
--exclude="htop/" \
--exclude=".mozilla/" \
--exclude=".cache/" \
--ignore-errors \
$RsYnC \
--delete-after


# fail popup doesn't go away until clicked.
  if [ "$?" = "0" ]
    then  echo "" >> "$LOG"
          echo -e "MANUAL BACKUP Success! -$TODAY \n\n#### Here Is The Output ####\n" >> "$LOG"
          zenity --info --width=200 --title="Rsync Backup" --text "          Manual Rsync \nHas finnshed Successfully." --timeout=60
     else echo "" >> "$LOG"
          echo -e "MANUAL BACKUP FAILED! -$TODAY \n\n#### Here Is The Output ####\n" >> "$LOG"
          zenity --info --width=300 --title="Rsync Backup" --text "Rsync Backup Has Failed! \nA Log File Was Made Here. \n$HMscr/rsync-bkup.log \n\nOr The Full File Here\n$HMscr/rsync-long.log"

  fi


echo ""
echo ""
echo ""
echo ""
echo "Rsync is finished"
echo "  Rsync is finished"
echo "    Rsync is finished"
echo "      Rsync is finished"
echo "        Rsync is finished"
echo "          Rsync is finished"
echo "        Rsync is finished"
echo "      Rsync is finished"
echo "    Rsync is finished"
echo "  Rsync is finished"
echo "Rsync is finished"
echo "  Rsync is finished"
echo "    Rsync is finished"
echo "      Rsync is finished"
echo "        Rsync is finished"
echo "          Rsync is finished"
echo "        Rsync is finished"
echo "      Rsync is finished"
echo "    Rsync is finished"
echo "  Rsync is finished"
echo "Rsync is finished"
echo ""
echo ""
echo -e "\nBACKUP $opt1s-$TODAY "
echo ""
echo ""
exit

the only real difference is that it is a little bit more visually engaging
and to launch it i just simply type "cbk"

i have changed the name of
cron-rsync-4-bkup-sh.log
to
rsync-bkup.log

and
cron-rsync-4-bkupsh.log
to
cron-rsync-4-bkup-long.log
then finally to
bkup-long.log      # this is the current name.

in case i post an older name in a future post. my brain does hiccup from time to time lol

as stated above, if you know of a good replacement for that tee command, i could use some advice about it.

thanks again
kudos
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#18
Concerning the tee usage I prefer to simply run the non-interactive cron script in the background and do a tail -f on the log file to monitor the progress.  

I do not like mixing non-interactive cron and interactive script usage.   It can lead to runaway interactive commands when using the script in non-interactive cron mode.    If you must you can always use the [[ -t 0 ]] to test for an interactive tty then run the interactive command.    

Also, what are you doing with the standard error?  I do not see it being re-directed to a file.
Idea Give a person a fish, and you feed them for a day. Teach a person how to fish, and you feed them for a lifetime. ✝️ Proverbs 4:7 Wisdom is the principal thing; therefore get wisdom: and with all thy getting get understanding.  (Linux Mint 19 XFCE)
Reply
#19
A quick update

I changed how grep searches. instead of telling it what to search for, i now tell it what to leave out.
Code:
# from
#grep -i --color 'sent \|total size\|connection\|sender] expand\|deleting eli\|total: \|Receiver] expand\|total: \|failed: \|Permission\|rsync error\|error ' /home/eli/Scripts/rsync-long.log >> /home/eli/Scripts/rsync-bkup.log

# to
grep -v "uptodate\|sender\|Rsync is finished\|END OF OUTPUT\|generator" /home/eli/Scripts/rsync-long.log >> /home/eli/Scripts/rsync-bkup.log

## In the script I add "END OF OUTPUT", then leave it out in the grep.
## this is because it is only needed in the terminal output.
## it is repeated in the log, and so therefore excluded.
This lists the important info, and all changes, errors, and warnings. ( i think)
MUCH better output. far more useful information.

(09-14-2018, 02:00 AM)deck_luck Wrote: Concerning the tee usage I prefer to simply run the non-interactive cron script in the background and do a tail -f on the log file to monitor the progress.  

I do not like mixing non-interactive cron and interactive script usage.   It can lead to runaway interactive commands when using the script in non-interactive cron mode.    If you must you can always use the [[ -t 0 ]] to test for an interactive tty then run the interactive command.    

Also, what are you doing with the standard error?  I do not see it being re-directed to a file.

I totally missed that. you are right, i don't remember telling it where to go. hold on let me check

You were right.

i added &> to
exec &>  >(tee -i /home/eli/Scripts/rsync-long.log)

and turning off my router and running the script now gives this output.

Code:
#### Starting New MANUAL Rsync Job ####

MANUAL BACKUP FAILED! -Fri Sep 14 01:31:37 CDT 2018

#### Here Is The Output ####



Gtk-Message: 01:31:38.093: GtkDialog mapped without a transient parent. This is discouraged.
opening connection using: ssh -p XXXX XXX.XXX.X.XX rsync --server -XXXXXXXXXXXXXXXXXXX --delete-after --ignore-errors . /home/eli/FLAT-BAK  (11 args)
ssh: connect to host XXX.XXX.X.XX port XXXX: Network is unreachable  <----- This is New. after adding &>




Gtk-Message: 01:31:40.217: GtkDialog mapped without a transient parent. This is discouraged.





##################################################################################################
########################################### END OF OUTPUT ########################################
##################################################################################################

that is such a small thing. But it fixed my no error issue. i don't know why i didn't catch that. Thanks.
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply
#20
last night i was going threw some very old files from 2000 - 2005 and found a script template for my old cron settup. though mostly useless it had some interesting consepts in it. it tried them and now have a single self contained script that sets niceness, checks for battery, gives one chance to cancel, runs the backup, gives a brief notification upon compleation, send the full log to temp, greps for all the usful info, sends that back to my scripts folder. then quietly goes away intill the next run. and with very minor changes can be switch from manual to auto, as well as user, path, and IP


i still need to do some cleanup,  but this is basically done. from here the only changes should be cosmetic. unless  I... well, we find another dumb entry of mine. lol
but here it is.
Code:
#!/bin/bash
#
### MAKE SURE this is the SAME as $LONG_OUTPUT ! ! line #30
exec &>  >(tee -i /tmp/rsync-long.log)
echo ""
echo "##### start of log #####"
echo ""
### setts niceness
renice -n 10 $$
### the next line is for when ran by crontab. it allows zenity to work
export DISPLAY=":0"
# Checks if your on the battery
if which on_ac_power >/dev/null 2>&1; then
   on_ac_power >/dev/null 2>&1
   ON_BATTERY=$?
   [ "$ON_BATTERY" -eq 1 ] && echo "It is not safe to run rsync when on the laptop battery. this script is now closed"&&echo "" && exit 0
fi
## Remote User Name Here
USR1='remote_user'
## Remote IP here
IP1='123.456.7.89'
# other useful variables
MnAt='AUTO'     # is it ran automatically or manually?
mnat='Auto'
MYHOME="/home/$USR1"
DEST="/home/$USR1/FLAT-BAK"
HMdesk="/home/$USR1/Desktop"
HMscr="/home/$USR1/Scripts"
GREP_OUTPUT="/home/$USR1/Scripts/rsync-bkup.log"
LONG_OUTPUT="/tmp/rsync-long.log"
RsYnC="$MYHOME $IP1:$DEST"
TODAY="$(date)"

## one chance to cancel.
zenity \
--question \
--width=200 \
--title="$MnAt Rsync Backup" \
--timeout=15 \
--cancel-label="cancel" \
--ok-label="continue" \
--text="$MnAt Rsync has Started\nYou Have 10 Seconds To cancel."
     if [ "$?" = "1" ]
        then echo "" ; echo "You canceled the rcync backup" ; echo "" ; exit 86
     fi

echo -e "\n#### Starting New $MnAt Rsync Job ####" >> $GREP_OUTPUT

### With The delete-after Option Added and exclude option
### deletes files on remote that are no longer on source.
rsync -avvzp -e 'ssh -p 22' \
--exclude='VirtualBox VMs/' \
--exclude=".local/" \
--exclude="Git-Stuff/" \
--exclude=".bash_history" \
--exclude=".zhistory" \
--exclude=".ssh/" \
--exclude=".git/" \
--exclude="Code/" \
--exclude='BOX/' \
--exclude="htop/" \
--exclude=".mozilla/" \
--exclude=".cache/" \
--ignore-errors \
${RsYnC} \
--delete-after

# fail popup doesn't go away until clicked.
  if [ "$?" = "0" ]
    then  echo "" >> "$GREP_OUTPUT"
          echo -e "${MnAt} BACKUP Success! -${TODAY} \n\n#### Here Is The Output ####" >> "${GREP_OUTPUT}"
#           zenity --notification --width=200 --title="Rsync Backup" --text "          $mnat Rsync \nHas finnshed Successfully."
#           zenity --info --width=200 --title="Rsync Backup" --text "          $mnat Rsync \nHas finnshed Successfully." --timeout=10
     else echo "" >> "${GREP_OUTPUT}"
          echo -e "${MnAt} BACKUP FAILED! -${TODAY} \n\n#### Here Is The Output ####" >> "${GREP_OUTPUT}"
          zenity --info --width=300 --title="Rsync Backup" --text "Rsync Backup Has Failed! \nA Log File Was Made Here. \n$GREP_OUTPUT \n\nOr The Full File Here\n$LONG_OUTPUT"
  fi
  exec 2>&1
###
# Grepit
grep -v "uptodate\|sender\|Rsync is finished\|END OF OUTPUT\|generator\|mapped without a transient parent\|Gtk-WARNING" $LONG_OUTPUT >> $GREP_OUTPUT

echo "##################################################################################################"  >> $GREP_OUTPUT
echo "########################################### END OF OUTPUT ########################################"  >> $GREP_OUTPUT
echo "##################################################################################################"  >> $GREP_OUTPUT
echo "" >&2

exit
This was actually a lot of fun for me. This is why I like Linux, and the Linux community.

I have another script project I am working on for unknown IP addresses. but I will post that under its own thread. Probably tomorrow.

leon.p, and deck_luck, you guys are great. thanks for hanging in there with me.

kudos
A computer without Microsoft is like a piece of chocolate cake without ketchup and mustard.


Telegram @eliasw4u
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)