Linux MintThis forum is for the discussion of Linux Mint.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I was wanting to create a simple "double click" solution for shredding areas of mine or my families drives. I'm not too familiar with shell scripts at all but the one I'm trying to use is pretty simple but I can't exactly figure out what I need to do to get it do work!
The .sh file looks something like this:
#!/bin/sh
sudo for i in <drive> ; do shred -fvzn0 $i & done
whenever I try to run it, it asks for the password then immediately closes the window. if I attempt to run the .sh from terminal then it says something along the lines of "Shred: missing shred operand".
Wind back a bit and please explain how you intend to launch this script, where you are getting your drive values from, and what you have in /etc/sudoers to lock all this down?
Ok. There are at least two steps in this. First, get it working as you like it in the terminal. Then get it working via an icon using a .desktop file.
As far as step one goes, for the For Loop, are you typing in the list of drives or partitions by hand? Or are you getting them as output from a program or script?
If it's of any use to you, I use a recursive shred script written in bash (which I name shredd and call as a Caja action):
Code:
#!/bin/bash
function shredProcess {
if [ -d "$1" ] ; then
rmdir "$1"
if [ $? -ne 0 ]; then
echo "*** ERROR - $1 could not be deleted"
fi
elif [ -f "$1" ] ; then
shred -n 1 "$1" # overwrite with random data
sync # force sync of buffers to disk
shred -n 0 -z -u "$1" # overwrite with zeroes and remove file
if [ $? -ne 0 ]; then
echo "*** ERROR - $1 could not be deleted"
fi
fi
}
for f in "$@" # handle spaces in filenames
do
if [ -d "$f" ] ; then
find "$f" -depth -print0 | while IFS= read -r -d '' file
do
shredProcess "$file"
done
elif [ -f "$f" ] ; then
shredProcess "$f"
fi
done
this is wrong - the string '<drive>' is a pseudocode placeholder for something you need to fill in. it is NOT shell syntax.
also i'm not sure if shred works on drives or partitions. did you read its documentation?
i suspect you need "for i in <partitions>" instead.
edit: if you use the term "drive" in a windows mentality, you actually mean partitions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.