Thursday, 6 June 2013

Simple script that copy files to directory in backtrack


Simple script that copy files to directory in backtrack 

 Write a script that copy files to directory /temp, remove them from the current directory, clean up anything a user has in the /temp directory over ten (10) days old. Finally send mail to user.

Code 

#!/bin/bash
While true
do
echo " Script no.1 "
echo " ------------------------ "
echo " Command Menu "
echo " ------------------------ "
echo "1.Copy the file to the temp directory"
echo "2. Remove files that are over 10 days old from the temp directory"
echo "3. Send mail to user"
echo "q. Quit"
echo " ------------------------ "
echo -n "Input Your Choice : "
read b
case "$b" in
1)
echo -n "Enter the filename to be copied : "
read b
if( mv $b \temp) ; then
echo "File has been copied to the temp directory, Successfully !"
read b
else
echo "Error!"
read b
fi
;;
2)
find /root/noman/temp/* -mtime -10 -exec rm {} \;
echo "files that were over 10 days old are deleted successfully"
ls -1 temp
read b
;;

3)
mail
;;
q)
exit 0
;;
*)
echo " Invalid Choice... Try Again "
sleep 2
;;
esac

done

Screen Shot

backtrack learning exercise


No comments:

Post a Comment