Quote:
Originally Posted by
KevinADC
Well, it is your task, so what have you tried?
THis is my file named mycron which I add it to the crontab entry later to run every 5 mins and this works. But I havnt done the last part - to run another script if everything succeeds.
Thanks for the reply Yogesh. But in ur code, what if the mv fails - ie, say the destination directory doesnt exist or something else ... only after all this succeeds I need to start another script.
#
# Taking action if a particular file appears in a dir
#
filename="/home/mrudula/myfile"
count=`find "$filename" | wc -l`
if [ "$count" -eq 1 ]
then
# Renaming filename
new_filename="$filename".new
mv $filename $new_filename
echo "$filename" renamed to "$new_filename"
# Moving to backup directory
bkup_dir="$filename"-bckup
mkdir "$bkup_dir"
mv "$new_filename" "$bkup_dir/$(basename $new_filename)"
echo "$new_filename" moved to "$bkup_dir"
else
echo "No file found - "$filename""
fi