Tag Archives: Author Emmanuel Iroanya Jr

I'm Back! Help Please!

By gkelly1117

I have a task, I usually do manually, but with growing responsibilities I tend to forget to do this weekly, I want to write a script that automates this, but I cant seem to work it out in my head, I have the shell of it out, but need help, and you guys have helped me with EVERY problem I have posted, and have found help in others posts as well. Please see below shell code I have started.

Code:

#!/bin/ksh
#Author:Emmanuel Iroanya Jr
#Date:April 2nd, 2013
#Purpose: The purpose of this is to check data and rollout directory and keep file space optimal.

if [ "$1x" = "x" ]
then
echo "You must supply an environment parameter to this script"
echo "example: $0 tb82"
exit
fi

. /opt/origenate/$1/config/usrconfig.sh #Sources Environments Admin Config Variables

cd $ORDATA #Environments Data Storage Directory
du -sk * | sort -n -r | head -n 10 |awk '{print $2}' #Finds folder in Data Directory with most stuff in it.

cd $ORDATA/??? #I want to cd into Directory found with du -sk command above, what kind of loop do i Need? a for loop makes sense cant work out logic though?
cd backup #backup directory we save backup of files, big space issue offender

find *.zip -type f -a -mtime +3 -exec rm {} ;
find *.pdf -type f -a -mtime +3 -exec rm {} ;
find *.CSV -type f -a -mtime +3 -exec rm {} ;
find *.txt -type f -a -mtime +3 -exec rm {} ;

<br ...read more
Source: FULL ARTICLE at The UNIX and Linux Forums