LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-20-2017, 10:41 PM   #1
CrabbyAbby2
LQ Newbie
 
Registered: Aug 2017
Posts: 3

Rep: Reputation: Disabled
Some parts of my safe_rm_restore code is not working


Good evening everyone!

I was able to fix my safe_rm code to "delete" my files. Although my code to restore the files looks great and works for the most part, I am having issues with some part of my code, particularly trying to overwrite the file and to move the file to the original directory based on its path. I have attached the code below. Any and all suggestions are greatly appreciated. Thank you!

Code:
#!/bin/bash


##2.

fileName=$1
inode=$2


## This will be the name of the restored files that is in the recycle bin.


##3.
movingfile(){

if [ -e $HOME/deleted/$1_$2 ]
                        then
                        mv $HOME/deleted/$1_$2  $(grep $1_$2 $HOME/.restore.info | cut -d":" -f2)
fi
}

## This will retrieve the files in the home deleted bin and retrieve the files that are in the hidden file.

##4.
safe(){

fileName=$HOME/deleted/$1_$2

if [ $# -eq 0 ]; then
        echo "safe_rm: missing operand"
        exit 1
fi
if [ ! -e $fileName ] ;
                then
                echo "safe_rm_restore :cannot restore '$1': No such file or directory"
                exit 1
fi
}

## This tests the conditions of the retreived file on whether it exists or is missing an operand.

##5.
restoreFile(){
fileName=$HOME/deleted/$1_$2

if [ -e $(grep  $1_$2 $HOME/.restore.info | cut -d":" -f2) ] ;
        then
                read -p "File currently exists. Do you want to overwrite y/n?:" word
if [[ $word = "yes" || $word = "Y" || $word = "y" ]] ;
                then
                        mv $HOME/deleted/$1_$2 $(grep $1_$2 $HOME/.restore.info | cut -d":" -f2) && exit 0 ## I used an if-then statement in order for the user to select what they want to do to the restored file.
fi

if [[ $word = "n" ]] ;
                then
                exit 1                                                         
	else
	echo "Invalid Option"
                        exit 1
fi
fi
}


##6.

restored(){

remove=$(grep -v $1_$2 $HOME/.restore.info | tee $HOME/.restore.info)
if [[ ! -e $HOME/deleted && -e $(grep $1_$2 $HOME/.restore.info | cut -d":" -f2) ]];
                then
                echo $remove
fi
}


safe $1 $2
movingfile $1 $2
restoreFile $1 $2
restored $1 $2
 
Old 08-22-2017, 07:01 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,618

Rep: Reputation: 5607Reputation: 5607Reputation: 5607Reputation: 5607Reputation: 5607Reputation: 5607Reputation: 5607Reputation: 5607Reputation: 5607Reputation: 5607Reputation: 5607
have you tried to insert set -xv at the beginning of your script?
 
  


Reply

Tags
unix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LaTeX Table code not working, even example code from book. This is my username Programming 1 12-31-2012 12:00 PM
gnome parts stop working or vanish from Ubuntu Hardy SaintDanBert Linux - Desktop 1 01-28-2009 11:05 AM
run-parts: /etc/cron.daily/man-db exited with return code 2 cccc Debian 1 03-03-2007 05:46 AM
parts of kde very slow, others not working edgjerp Linux - Software 1 12-14-2006 06:38 AM
uninterruptable parts of code DocBexter Programming 5 09-11-2003 05:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration