How to check files in Backtrack
Write a script, which copies file1
to file2, check to see whether file2 exists already, if file2 exists then check
that whether there is write permission on file2 or not, if there is write
permission on file2 then warn user before copying file1 to file2, and get
permission to proceed else exits, otherwise copy files.
Code
#!/bin/bash
clear
echo "
==== File Copying Program ==== "
echo "
"
echo
"These are the files in present directory"
ls
echo
""
echo
"Please enter source filename "
read a
vre=`pwd`
if [ -f
$vre/$a ];
then
echo "
"
else
echo
"Enter valid file name"
exit 0
fi
echo
"Please enter destination filename "
read b
vre1=`pwd`
if [ -f
$vre1/$b ];
then
echo
"File dont have write permissions"
echo "Do
you want to change mode and allow writting ? , (y)es or (n)o "
read d
case $d in
y)
chmod 600 $b
cp $a $b
echo "
File Copied Successfully"
exit 0
;;
n)
exit 0
;;
esac
else
echo
"File Name Invalid in present directory"
exit 0
fi
else
echo
"Enter valid file name"
exit 0
Screen Shot
No comments:
Post a Comment