Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to move 10 oldest files from one directory to another 1

Status
Not open for further replies.

billy1

Technical User
Sep 16, 2002
73
IE
Hi,

our database writes archived files to a directory. When this directory fills up it crashes the application. I usually move the 10 oldest files to another directory.
Is there a script that I can run everytime the directory fills up to move the last ten files from one directory to another ?

Many thanks!
 
If your database application regularly crashes, then you should consider creating a cron script to monitor the free space, eg.

#!/usr/bin/ksh
freespace=$(df -b /archive/dir|awk '{print $5}')
if [ "$freespace" -lt 32768 ]
then
mv $(ls -tr /archive/dir|head) /another/dir
fi
 
Also we can use the following ,

for i in `/usr/bin/ls -t | tail -10 `
do
mv $i $target_dir
done

Just an option .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top