I am trying to create a script and I am stuck on the final part I want to add.
The script syncs some paths on my server to my google drive. If there are any deleted or modified files on my server it is moved to /old/date/
path on gdrive.
oldlog="/boot/logs/old-log.txt"
del=""
date=$(date +"%Y-%m-%d-%H%M")
--backup-dir "${dest}/old/${date}"
This works really well, but I have to delete files in /old/
manually and that is what I want to change.
So what I need is for $date
to be written to $oldlog
and always at line 1 in the log and move all other lines in the log one line down. The $date
written to log has to match the $date
in --backup-dir "${dest}/old/${date}"
so they are identical.
So the log needs to work like this after xx day 1 day
2019-07-01-1800
2 day
2019-07-02-1800
2019-07-01-1800
3 day
2019-07-03-1800
2019-07-02-1800
2019-07-01-1800
So for the next part. After the log is updated like in the example above I need to grab line 21 from oldlog.txt
, delete the line and add it to the script as $del
.
oldlog="/boot/logs/old-log.txt"
del=
rclone purge "${dest}/old/${del}"
Now, if the line is empty I need it to be just a random text so it wont purge everything inside /old/
or maybe I more advanced approach is possible for it?
Something like if del=empty then show message nothing to purge. If del=value from oldlog.txt then run rclone purge "${dest}/old/${del}"
oldlog="/boot/logs/old-log.txt"
del=
delempty=echo "nothing to purge today"
delvalue=rclone purge "${dest}/old/${del}"
Is any of this possible to make in a script without it being to complex?
sed
script and just using afind
command, e.g. https://unix.stackexchange.com/q/218545/135943 – Wildcard Jul 29 '19 at 20:01find /old -ctime +21 -delete
or similar. (Warning: test and read documentation before using deletion commands from the internet!) – Wildcard Jul 30 '19 at 22:58