Hi all,
I have been tasked with creating a script that sends a file into a created "recycling" directory and another script that restores a "deleted" file. I have already created the removal script but am stuck on the restoring part.
I need to restore the file to its original location by using its path name, which can be found in the .restore.info file that I created.
Here is the removal script:
# did the user enter a filename
if [ -z "$1" ]; then
echo "No file was entered"
exit
fi
# warns the user if a directory and not a file was entered
if [ -d "$1" ]; then
echo "Directory name entered. Please enter file name"
exit
fi
# if the correct file name is entered then display file deleted
if [ ! -f "$1" ]; then
echo "$1 Does not exist"
exit
fi
# finds inode of a file to avoid files with the same name
inode=$(stat -c '%i' $1) 2>/dev/null
# shows the path of the file
path=$(readlink -f "$1") 2>/dev/null
# prints name of the file and its path in the .restore.info file
echo "$1_$inode:$path" >> ~/.restore.info 2>/dev/null
# warns the user if they enter this script as an argument
if [ $1 = "remove123" ]; then
read -p "Are you sure you want to delete remove? y/n: " answer
#if yes, then remove the file otherwise do nothing
if [[ $answer = y ]] ; then
mv "$1" deleted/"$1"_"$inode" 2>/dev/null
echo "$1_$inode:$fixedPath" >> ~/.restore.info 2>/dev/null
else
exit
fi
fi
#moves to deleted dir
mv "$1" deleted/"$1_$inode" | cut -d " " -f 1 2>/dev/null
So far for my restore script, I have:
#find the original path of the file
path=$(readlink -f "$1/.restore.info") 2>/dev/null
#move the file back to its original path
mv $1 $path
Please forgive me for my basic language, I'm very new to Unix programming.