Shell Scripting for Recycle Bin. Delete,Trash,Restore
Hi everyone,
This is what I have done so far, but can't get it to work somehow. Anyone can please help? Delete: Code:
#!/bin/bash Code:
#!/bin/bash Code:
#!/bin/bash |
1) use [code][/code] tags when posting code
2) What exactly does "Can't get it to work" mean? 3) Code:
Y|y|yes|Yes|YES) echo "`readlink -f $1`" >> ~/Paths & mv $1 ~/Dustbin b) variables should be in double quotes c) I would also recommend using the "$()" over backticks d) use $HOME instead of ~ in scripts e) Also note the difference between & (forking to background) and && (running if previous command was successful) Code:
Y|y|yes|Yes|YES) echo "$(readlink -f "$1")" >> "$HOME/Paths" && mv "$1" "$HOME/Dustbin" ;; 4) Code:
if ["$1" == "-a"] b) spaces are needed between braces ([ and ] are both keywords that need to be read as separate tokens by bash) c) unless you want backwards compatibility, prefer [[ ]] to [] 5) What is the point of this? Code:
cd ~/Dustbin Code:
rm ~/Dustbin/* 7) Code:
for line in `ls` Code:
for line in * Code:
echo "Are you sure you want to permanently delete this file?" $line "Yes/No" Code:
echo "Are you sure you want to permanently delete this file? $line Yes/No" Code:
Y|y|yes|Yes|YES) rm $line 10) Code:
rm Paths THE LAST SCRIPT: 11) Code:
restore =`grep $2 ~/Paths` 12) Code:
grep $2 ~/Paths Anyway, the Paths file probably doesn't exist anymore since you may have deleted it by the second script. What was it for again? |
Thanks for your help, much appreciated!
Delete Script is working smashing after your help. Another question, is there any way I can edit that script and that will let me delete the directories also?
THE SECOND SCRIPT: 7) Code:
for line in * So for instance, Code:
#trash Code:
cd $HOME/Dustbin Code:
# trash 10) Code:
rm Paths THE LAST SCRIPT: The Paths file keeps hold of the Original Location of the Deleted file which is sitting in the Recycle Bin. You're correct that it is getting deleted in Script 2 which it should be, because if user deletes a file, it goes to the bin and then he can later restore to it its original location but when the user deletes it using "trash", then it will remove the file as no point of keeping record of the deleted file and instead it will create a new empty file in the same location.(I hope it make sense?) And how I can fix this now? as just now, restore isn't working at all! Thanks |
Quote:
Quote:
Code:
for line in * Code:
for line in Dustbin/* Quote:
|
1. These look basic scripts, but you need to work on scripting little more. I assume that Paths file contains a simple list of files that were deleted. Codes could be short and simple, as:
Trash: PHP Code:
PHP Code:
Quote:
4. It's recommended to use $() over backticks while defining variables. Go through: http://mywiki.wooledge.org/BashFAQ/082 |
Code:
if ["$1" == "-a"]; Code:
rm=$(rm -i) |
Thanks for your help!
Thanks both of you for your help, now I have managed to get Delete and Trash working perfect, but restore still ain't working, I am posting my (current) scripts just now so that we can now have a clear look and see where I am getting wrong, as it is getting kinda messed up just now.
DELETE Code:
#!/bin/bash Code:
#!/bin/bash Code:
#!/bin/bash |
Code:
rm=$(rm -i) PHP Code:
Quote:
PHP Code:
|
Shivaa I appreciate your help, but the thing is right, it took me alot of time to get atleast those 2 scripts right. And I actually don't feel comfortable changing them unless it will make my Restore script to work. So I mean as I said, I do appreciate but because they are working fine just now I don't see the point of changing them to something else.
Whereas, the Restore Script is concerned, I am actually not getting any error message but it just doesn't seems to work! In clear words, It's not restoring the file back to it's original location. That's why I again posted my Scripts after making all the changes, so that we can just have a look at it and see where it is getting wrong, as to me it should work and move the file from Dustbin Directory to back to its Original Location. Thanks a ton! |
Quote:
Quote:
PHP Code:
|
In that case, use set -xv just below the interpreter line in restore script and then invoke the script again. It will show you the execution of the script line-by-line. You can then find out the wrong part of it.
#!/bin/bash set -xv while read -r filename do echo "Where would you like to save this file?:" read location mv -i $filename $location done < ~/Paths [/PHP][/QUOTE] NOW after adding set -xv to the Restore Script.. I have attached the screenshot showing the Output. Thanks! |
Make sure which script you're running? The one I suggested or your own? And do not stick to an approach when it's not helping & there's another way availale to achive results. I don't understnad why you're using restore =`grep $1 $HOME/Paths` and ifilename=`basename $restore "` variables & getting same problem again & agian:
Code:
ls ~/Dustbin # What's need of using this? Let's say ~/Path contains: abc def ghi Then you can try: Code:
#!/bin/bash |
Paths is a name of a file which is keeping record of the "Original Location of a file" as then it can be used to Restore the file back to that location.
Have a look at this screenshot, it tells you what's happening just now.. and if you thinking changing my Restore script with your will help me get outta here then I ain't got any problem with that.. Thanks |
Where's the first time posted question? Have you removed that? It's not admissible at all that you remove your original question!
And you're sharing output of your own code (which is incorrect and carries lot of misconception) again & again, so I'm not willing to give same answer again & again. If you can't try what other have suggested to you, then do not expect solution! |
I didn't even had a look at my Original Question, I dunno where it is.. plus I was not able to connect to this website from last couple of minutes.. it was just coming up "PAGE NOT FOUND"...
Sorry Shiva, if you think I'm being mean, that's not my intention. I'm here to Learn Linux, and solve as much problems as I can, am not saying what you're saying is wrong or it won't work but I wasn't too sure if it will do what I want to do. (You getting me) I'll just change it just now and see what it does what you are saying.... Thanks! |
All times are GMT -5. The time now is 04:35 PM. |