Rule to securely delete file on external HD

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up.

Moderators: Mr_Noodle, Moderators

Rule to securely delete file on external HD

Postby Jo* » Tue Jul 29, 2008 10:17 am

Hi there,

I'd like to set up a rule in Hazel that will securely delete a dmg on an external harddrive.

I use DropDMG to create a compressed, encrypred dmg that is being backed up to an online backup-server once or twice a week.

Both the creation of the dmg and the backing-up to the online backup-server are automated.

However, DropDMG does not overwrite an exisiting dmg with the same name that is still in place on the ext. HD but rather gives it a _1.dmg name.

So in order to keep the whole procedure automatic, I would like to erase the dmg after it has been sent to the server so DropDMG will create a dmg with the same name the next time - thus allowing for an automatic transfer of the file to the online backup-server (as setup in a script).

Since the dmg is only used for this sole purpose, I would like to securely delete it using the equivalent of the Finders "securely delete trash". I also backup a complete bootable clone of the int. HD to my ext. HD - the online backup is meant for total desaster like theft or the like.

The Hazel rule I set up is as follows:


If all of the following conditions are met

Full Name - is - file.dmg

Date Created - is not in the last - 2 - Days

Do the following

Run shell script - embedded script

Shell: ???

Send Growl notification - with pattern - ...


I would like to securely delete the dmg not taking a detour over the regular trashcan but rather securely delete it right away.

Any idea of how the shell script should look like. Keep in mind, the file to be deleted is on an external drive. I'm very much of a scripting amateur, so explanation catered to the dummy would be very much appreciated (like what has to be in the upper part of the Edit Script window of Hazel, and what should be stated in the lower window).

Since the creation of the dmg by DropDMG as well as the transfer of the dmg are part of an overnight process, I assume Hazel would delete the file exactly 48 hrs later, right? (as the rule says "Date Created - is not in the last - 2 - Days").

Thanks

Jo*
Jo*
 
Posts: 7
Joined: Fri Jul 25, 2008 3:41 pm

Re: Rule to securely delete file on external HD

Postby Mr_Noodle » Tue Jul 29, 2008 11:36 am

To do a secure delete, you need to use the 'srm' command. The script would look something like:

Code: Select all
srm -frm $1


The 'f' option is to "force" the removal. 'r' is recursive (in case you are deleting a folder, for instance) and 'm' is for "medium" which is does a 7 pass overwrite on the file. If you do 'man srm' on the commandline, you can get a full description of the options. $1 is the file being processed.

It won't necessarily be exactly 48 hours but pretty close (like within minutes, usually). I don't know if you require absolute precision on this or not.

That said, Hazel's built-in move action will allow you to overwrite an existing file. The old file goes to the trash, though, plus it's a local move, not one to a server. That said, if you could mount the backup server as a network share and don't mind moving the old one to the trash, you could do a move to the share with the overwrite option set.
Mr_Noodle
Site Admin
 
Posts: 3817
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rule to securely delete file on external HD

Postby Jo* » Tue Jul 29, 2008 4:03 pm

Bingo...

The shell script works great!

Thanks a lot for your quick reply!

I guess I'll do it with -s instead of -m since the dmg measures about 1.5gig and that takes ages to be overwritten. Instead I'll rather delete the partition every now and then with secure pass using diskutility.

It doesn't have to be deleted precisely after 48 hrs. I set up the backup to run at midnight and would like the dmg to be deleted right thereafter (at night) due to performance issues with my PowerBook. The secure pass takes up to 70% of CPU usage.

The built-in move action would be a great alternative but would stuff my trash with a bunch of large files if I won't keep an eye on that. I could use Hazel's built-in delete function on these but as I said I try to delete the large stuff overnight. Having said that, if I use Hazel's built-in delete function (tab in the middle) and set it to "Delete files sitting in the trash for more than -2- -Days-" are the files in the trash then deleted one by one individually once they have been in the trash for 48 hrs. (+ a couple of minutes)?

Thanks again!

Jo*

EDIT: The srm process just finished a minute ago (just got the Growl notification), but the dmg is still present on the volume of the external drive and still takes the 1.5 gig in space, although it's not mountable anymore.

When I first set up the rule in Hazel, I chose the volume (which in fact is one of three partitions of the ext. HD) in the folder column of the Hazel window and added the rules in the Rules-window on the lower right. When I double-click the rule, it shows the volume under "Folder" at the top.

What went wrong?
Jo*
 
Posts: 7
Joined: Fri Jul 25, 2008 3:41 pm

Re: Rule to securely delete file on external HD

Postby Mr_Noodle » Wed Jul 30, 2008 9:37 pm

srm/secure delete can be a resource-intensive process as it has to do several overwrites of the file.

The trash function looks at each file individually, so yes, when a particular file is 2 days old, it will be deleted after it is 2 days old. The age of the other files doesn't affect it. If you can use the move action, I would recommend that. If you are worried about your trash getting too big, you can set the trash options to clean it out by age and also by size. And if a particular file is bigger than the size limit, you can set Hazel to delete it immediately.

As for why the dmg is still there, it's hard to say without seeing the rules. Email me the rules (click on "Contact Support" in the "Info" pane) and also describe to me the workflow (i.e. which folder is which). I'll see if I can find any problems there.
Mr_Noodle
Site Admin
 
Posts: 3817
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rule to securely delete file on external HD

Postby Coolspec » Wed May 25, 2011 10:46 am

Mr_Noodle wrote:srm/secure delete can be a resource-intensive process as it has to do several overwrites of the file.

The trash function looks at each file individually, so yes, when a particular file is 2 days old, it will be deleted after it is 2 days old. The age of the other files doesn't affect it. If you can use the move action, I would recommend that. If you are worried about your trash getting too big, you can set the trash options to clean it out by age and also by size. And if a particular file is bigger than the size limit, you can set Hazel to delete it immediately.

As for why the dmg is still there, it's hard to say without seeing the rules. Email me the rules (click on "Contact Support" in the "Info" pane) and also describe to me the workflow (i.e. which folder is which). I'll see if I can find any problems there.


Hi
I'm new to this game. Is this script valid in Snow Leopard? I'm having difficulties implementing it. Hazel keeps rejecting the code. Would be happy to make it work

Claude
Coolspec
 
Posts: 3
Joined: Wed May 25, 2011 8:07 am
Location: Montreal, Canada

Re: Rule to securely delete file on external HD

Postby Mr_Noodle » Wed May 25, 2011 2:53 pm

Please post the error you are getting from the logs.
Mr_Noodle
Site Admin
 
Posts: 3817
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Rule to securely delete file on external HD

Postby Coolspec » Thu May 26, 2011 4:05 pm

Hi

I see in the Log the notification that the file was shredded. But the file is still there

2011-05-26 15:38:22.500 hazelfolderwatch[12062] Hazel Alert: File Shredded
2011-05-26 15:38:22.500 hazelfolderwatch[12062] [Custom Message] Hazel Alert: File Shredded

I have entered the code this way: Top line: /bin /sh
Lower box: srm -frm $1

Thanks for your input

Claude

Update- 5/27: Appears to be working. I saw that the file had disappeared. I will try some more today and advise.
Coolspec
 
Posts: 3
Joined: Wed May 25, 2011 8:07 am
Location: Montreal, Canada

Re: Rule to securely delete file on external HD

Postby Coolspec » Sat May 28, 2011 6:18 pm

Hi
I have created a rule to shred any file entering the "shred" folder. The rule goes like this:
a) If all of the conditions are met
b) Any files
c) Run shell scrip..... Run embedded
d) Growl notification

Here is how I laid my script: Top line: /bin/sh
lower large box: srm -frm $1

Unfortunately it's not working. Can you help?

Thanks

Claude
Coolspec
 
Posts: 3
Joined: Wed May 25, 2011 8:07 am
Location: Montreal, Canada

Re: Rule to securely delete file on external HD

Postby Mr_Noodle » Mon May 30, 2011 10:23 pm

Did you email me about this? If not, then here is the fix:

/usr/bin/srm -frm "$1"

You have to specify the full path (this is always a good practice as scripts tend to be executed in different contexts plus it can be a security hole). Also note the quotes around the argument to handle paths which have spaces in them.
Mr_Noodle
Site Admin
 
Posts: 3817
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Tips & Tricks/Rule Recipe Exchange

Who is online

Users browsing this forum: No registered users and 4 guests



Copyright © 2006-2012 Noodlesoft, LLC, All Rights Reserved. Mac and the Mac logo are trademarks of Apple Computer, Inc., registered in the U.S. and other countries.