Kamis, 22 Desember 2016

Else IF pada Linux Server

#!/bin/bash

date1=`date -d"8 day ago" +'%Y%m%d'`
date2=`date +'%Y%m%d %H:%M:%d'`
command="rm -rf"
message="data < atau = 7"

dir1=/var/backups/mbs-online
dir2=/var/backups/mysql
dir3=/var/backups/tks-online
dir4=/var/backups/switch-mbs
dir5=/var/backups/eximbi

count1=`ls -l /var/backups/mbs-online |grep .gz | wc -l`
count2=`ls -l /var/backups/mysql |grep .gz | wc -l`
count3=`ls -l /var/backups/tks-online |grep .gz | wc -l`
count4=`ls -l /var/backups/switch-mbs |grep .gz | wc -l`
count5=`ls -l /var/backups/eximbi |grep .gz | wc -l`

file1="banjar-$date1.dump.gz"
file2="mysql-$date1.dump.gz"
file3="tks-$date1.dump.gz"
file4="smbs-$date1.dump.gz"
file5="eximbi-$date1.dump.gz"

cmd1="$command $dir1/$file1"
cmd2="$command $dir2/$file2"
cmd3="$command $dir3/$file3"
cmd4="$command $dir4/$file4"
cmd5="$command $dir5/$file5"

        if (($count1 > 7))
        then
                $cmd1
                echo "$date2 data = $file1 telah dihapus" >> /root/pesan1
        else
                echo "$date2 $dir1 $count1 $message" > /root/pesan
        fi;

        if (($count2 > 7))
        then
                $cmd2
                echo "$date2 data = $file2 telah dihapus" >> /root/pesan2
        else
                echo "$date2 $dir2 $count2 $message" > /root/pesan
        fi;

        if (($count3 > 7))
        then
                $cmd3
                echo "$date2 data = $file3 telah dihapus" >> /root/pesan3
        else
                echo "$date2 $dir3 $count3 $message" > /root/pesan
        fi;

        if (($count4 > 7))
        then
                $cmd4
                echo "$date2 data = $file4 telah dihapus" >> /root/pesan4
        else
                echo "$date2 $dir4 $count4 $message" > /root/pesan
        fi;
        if (($count5 > 7))
        then
                $cmd5
                echo "$date2 data = $file5 telah dihapus" >> /root/pesan5
        else
                echo "$date2 $dir5 $count5 $message" > /root/pesan
        fi;

Tidak ada komentar:

Posting Komentar