1753494 Members
5223 Online
108794 Solutions
New Discussion юеВ

Re: scripting help

 
Brian Lee_4
Regular Advisor

scripting help

Whenever a file is put on the server it goes to the root /interface/Exel and the file type is xxxx.INT.
If it is larger than 1kb, i want to rename it to exel887_$(%Y%m%H%M%S).txt.
If it is less than 1kb, i want to rename it to exel997__$(%Y%m%H%M%S.txt.

I would like to make it as looping script because there are more than 2 INT extension files in the directory.
brian lee
3 REPLIES 3
Sridhar Bhaskarla
Honored Contributor

Re: scripting help

Hi Brian,

Test this before you go for it. Hopefully I understood your requirement.

LIMIT=1
DIR=/interface/Exel
DATE=$(date +%Y%m%H%M%S)

ls -1 $DIR/*.INT|while read ENTRY
do
FILE=$(basename "$ENTRY")
SZ=$(du -ks "$ENTRY"|awk '{print $1}')
if [[ $SZ -ge $LIMIT ]]
then
mv $DIR/"$FILE" $DIR/"${FILE}_exel887_${DATE}.txt"
else
mv $DIR/"$FILE" $DIR/"${FILE}_exel997_${DATE}.txt"
fi
done

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: scripting help

The first thing you better put into your script is a delay loop to at least check the size of the file twice because it may be growing at the very moment you determine its size.

If I were doing this, I would make use of Perl's stat and localtime functions.

You also need to clarify whether you want the current time or the file's last modication time. This is an easy script but writing it for you does you no favors. You need to do a bit on your own first.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: scripting help

My point is about not doing it for you is appropriate because you ranked yourself in your Profile as an expert in this area.
If it ain't broke, I can fix that.