2008年10月2日 星期四

Delete Job FIle from System and Disk by KSHELL

#/bin/ksh

##Create Log Directory
if [ -d $HOME/rmdtab ]
then

tempdirname=$HOME/rmdtab/$( date +"%Y%h%d.%H%M%S")
mkdir $tempdirname

else

echo " Directory is not exists !"
exit

fi

tempdirname=$HOME/rmdtab/$( date +"%Y%h%d%H%M%S")
mkdir $tempdirname;

##Get Job File List ,and Sort File List.
setdtab show > $tempdirname/originfile.txt;

#Collect File List ,and Exclude RD Job File List.
grep -v "^[0-3] " $tempdirname/originfile.txt | grep "/eb[1-99]/ebtest/pattern/." |grep -v "/eb[1-99]/ebtest/pattern/RD/."> $tempdirname/2stfile.txt
grep -v "^[0-3] " $tempdirname/originfile.txt | grep -v "/eb[1-99]/ebtest/pattern/." > $tempdirname/notreatfile.txt

#Get Directory Name
cut -d " " -f 2 $tempdirname/2stfile.txt > $tempdirname/sortrawdata.txt

## Read File List File for sortrawdata,and Separator Job File name by space.
temp=" ";
while read myfile; do

temp=$temp$myfile" ";

done < $tempdirname/sortrawdata.txt

##Sort Job File List by Date , Check Job File exists ,and input sortdata.txt.
ls -td $temp > $tempdirname/sortdata.txt;

## Read File List from sortdata.txt ,Delete Job File Directory ,and Remove File List from System.
typeset -i tempindex=1;
tempnum=" ";
var=" ";

#Read Job File from sortdata.txt
exec 3< $tempdirname/sortdata.txt
while read -r mylines <&3;
do

#only delete 20 Job File by sort date.
if [ tempindex -gt 20 ]
then
#Check Job File in Sytem List ,and wait User Response.
tempnum=$tempnum$(grep $mylines $tempdirname/2stfile.txt | cut -d " " -f 1 )" ";
print -n "Delete "$mylines" (Y/N) \n"; read var;
if [ $var = "y" ]
then
echo $tempnum;
#Delete Job File From System and Disk.
setdtab remove $tempnum;
echo $mylines Delete!"
rm -r $mylines;
else
echo $mylines" Not Delete!";
fi
fi
var=" ";
tempindex=tempindex+1;
done

grep -v "^[0-3] " $tempdirname/originfile.txt | grep "/eb[1-99]/ebtest/pattern/RD" > $tempdirname/rdfile.txt

#Delete RD Job FIle.
exec 3< $tempdirname/rdfile.txt
while read -r myliness <&3;
do

if [ tempindex -gt 20 ]
then

tempnum=$tempnum$(grep $myliness $tempdirname/rdfile.txt | cut -d " " -f 1 )" ";
print -n "Delete "$myliness" (Y/N) \n"; read var;
if [ $var = "y" ]
then
echo $tempnum;
setdtab remove $tempnum;
echo $myliness" Delete!"
else
echo $myliness" Not Delete!"
fi
fi
var=" ";
tempindex=tempindex+1;
done


echo $tempnum;

沒有留言:

[Excel]如何創建自定義函數

在 Excel 內建函式中找不到自已想要的函式怎麼辦?事實上我們可以自已建一個,以下是一個簡單的Excel自定義函數示例,用於將民國年轉為西元: Function 民國轉西元(x As Double) As Double     民國轉西元 = x + 1911 End Func...