Shell script to move certain files on scheduled time

Hi Friends,

I want a shell script which will move certain .jar files from a specified location (say /publish/content) to (/publish/archive) on every saturday morning 6 am.
One more thing to add is that before moving files it must check free space at (/publish/archive), if it is more than 60 % free then only it will move other wise not.

Thanks
Looking for your support

can you give some examples of the files you want moved this way i can work up a regex for you so you don't need to change the script every time?

I would recommend using Cron to do the timing portion, then it is as simple as doing something like the following (off the cuff)

#!/bin/bash
df|grep "/publish/archive"|if [[ "`awk '{print $5}'|sed 's/%//'`" > "60" ]]
then
mv /publish/content/[here is where i would put the regex for the files] /publish/archive
else
echo "No space in /publish/archive" | mailx -s "archive space alert" my@email.com
fi

[[UNTESTED!!!]]

Thanks for you help...

in that location files can be any ways..like abcd.jar, xyz.jar, 123.jar
what i want is to move only the files with extension .jar.

i guess for this you need to use mv *.jar, or something like that.

Waiting for your response

the shell is there for you to try out the commands. why don't you try your best.?

that is easier than i thought :smiley:

*.jar

now i want this script to create a dir in /publish/archive with name jar_'current date' and move the files into the same dir.

Adam please suggest

space=`df -gt | grep "/fnsspool_a" |awk '{print $5}' |sed 's/%//'`
if [ $space > "60" ]
then
for i in `*.jar`
do
mv $i /publish/archive
done
else
echo "NO SPACE in /publish/archive"
fi