Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

Bash Script To Clean 2+ Days Old Autobackup

mv ~/full_backup/daily/* ~/full_backup/archive/ &>/dev/null
mkdir ~/AutobackupLogs &>/dev/null
ls -ltr ~/full_backup/archive/ | awk '{print $9}' > ~/AutobackupLogs/dirnames

for i in `cat ~/AutobackupLogs/dirnames`; do
        Ptime=$(date +%s -d"$i 00:00:00")
        Ctime=$(date +%s)
        echo $((Ctime-Ptime)) | awk '{print int($i/86400)}' > ~/AutobackupLogs/timecalc

        Cvalue=`cat ~/AutobackupLogs/timecalc`
        if [ $Cvalue -gt 2 ]; then
                echo "Directory: '$i' removed, $Cvalue days old." >> ~/AutobackupLogs/rmjob
                rm -rf ~/full_backup/archive/$i &>/dev/null
        fi
        done

rm -f ~/AutobackupLogs/timecalc
rm -f ~/AutobackupLogs/dirnames
vim ~/AutobackupLogs/rmjob
Comment

PREVIOUS NEXT
Code Example
Shell :: create multiple files on Linux in sequence through the terminal 
Shell :: git rename branch and force push 
Shell :: virtual machine linux error several modules to compile 
Shell :: cherry pick multiple commits 
Shell :: commit specific file in git 
Shell :: git pull recursive 
Shell :: docker run name container 
Shell :: "grep -a" example 
Shell :: ionice 
Shell :: create a new repo 
Shell :: composer install twig 
Shell :: npm install sass-loader error 
Shell :: add existing project on github 
Shell :: mac finder quick preview for markdown 
Shell :: sudo bash 
Shell :: openssl PKCS vrom crt 
Shell :: install h5py in jupyter notebook 
Shell :: What is the login id in putty for ubuntu 
Shell :: usermod basic syntax 
Shell :: locobucci installation 
Shell :: javascript-typescript-Deno CLI 
Shell :: Git pull is ahead by x commit 
Shell :: How to check if your unix computer is 32-bit or 64-bit 
Shell :: debian install libssl_conf.so 
Shell :: run task in background ec2 
Shell :: Continuous bash script to do tasks 
Shell :: how to find inode of a file in linux 
Shell :: powershell get-aduser global catalog 
Shell :: rebuild all apps dokku 
Shell :: run image docker ubunt with port 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =