Thursday, April 17, 2014

Unix scripts for DBA's

Remove files in a directory older than certain number of days
The below script takes 2 arguments 
  1. first argument specifies the location where the files will be removed & also the location where the log of files being removed is created
  2. second argument takes a number value & specifies files older than this number of days will be removed
[techie@lnx133 ~]$ cat del2.sh
#!/bin/ksh
dt=`date +%Y%m%d_%H%M%S`
path=$1
daysback=$2
file=logofdeletedfiles_$dt.txt
log=$path/$file
echo "Beginning to remove files at $path " >> $log
find $path -name "*.tx" -type f -mtime +$daysback -print -delete >>$log

echo "files removal past $daysback  days complete">> $log


Sometimes you need to do house keeping & clean up files of "0" byte size
Script below takes only one argument which specifies a location where the 0 byte size files have to be looked/removed & the logfile listing those files is to be created.


[oracle@lnx133 ~]$ cat zerodel.sh
#!/bin/ksh
dt=`date +%Y%m%d_%H%M%S`
path=$1
file=zerosizedel.txt
log=$path/$file
echo "Beginning to delete files at $path which are 0bytes in size ">>$log
find $path -type f -size 0 -print -delete >>$log
echo "Completed removing files at $path which were 0bytes in size">>$log
[oracle@lnx133 ~]$

1 comment:

  1. Borgata Hotel Casino & Spa
    Borgata Hotel Casino & Spa is a Wedding Venue in Atlantic City, 안동 출장샵 New Jersey, USA Built for Success 이천 출장샵 and Generous 동두천 출장샵 Service. Amenities include 충청남도 출장안마 a casino; a seasonal outdoor swimming  Rating: 7/10 · ‎2,048 reviews · ‎Price range: Expensive 세종특별자치 출장안마

    ReplyDelete