Script for Removing User Folder

TomDay
Release Candidate Programs Tester

Sorry total scripting newbie here. I am trying to remove a user folder via a shell script in Casper Imaging that used to work great in DeployStudio:
#!/bin/sh

rm -R /Macintosh HD/Users/apple

exit 0

I placed this .sh file in a config in Casper Admin, kick it off and the user folder is still there on reboot. has to be something in my syntax?

For a frame of reference what I am trying to to:
We lend users laptops with a local account on them, and then when the person returns the laptop, we wipe that user folder so the next person that uses the laptop doesn't see any of the previous web browsing history, files etc.

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

So, a few points.

First, I'm presuming from your post this would be running from an imaging setup where you won't be booted to the Macintosh HD. In that case, you need to include the full path, using /Volumes/, like this:

rm -rfd /Volumes/Macintosh HD/Users/apple

Second, Not sure if the above script lines are exactly what is in your script, but the backslash in the path to "Macintosh HD" needs a space after it, not before. You currently have

/Macintosh HD/

and, including the above point, it should be:

/Volumes/Macintosh HD/

Backslashes go before the character to be escaped, in this case a space. But... you could also just quote the whole path and not worry about spaces or other characters.

rm -rfd "/Volumes/Macintosh HD/Users/apple"

View solution in original post

5 REPLIES 5

nessts
Valued Contributor II

in a script -rf might be more helpful than an interactive -R

TomDay
Release Candidate Programs Tester

Thx I should have mentioned that I was originally trying -rf and since it didn't work I tried -R also

mm2270
Legendary Contributor III

So, a few points.

First, I'm presuming from your post this would be running from an imaging setup where you won't be booted to the Macintosh HD. In that case, you need to include the full path, using /Volumes/, like this:

rm -rfd /Volumes/Macintosh HD/Users/apple

Second, Not sure if the above script lines are exactly what is in your script, but the backslash in the path to "Macintosh HD" needs a space after it, not before. You currently have

/Macintosh HD/

and, including the above point, it should be:

/Volumes/Macintosh HD/

Backslashes go before the character to be escaped, in this case a space. But... you could also just quote the whole path and not worry about spaces or other characters.

rm -rfd "/Volumes/Macintosh HD/Users/apple"

Hobbs155
Contributor

We have had many issues with scripts not running during imaging, we have to set them to run at reboot for them to work.

TomDay
Release Candidate Programs Tester

Thx for all the detail on the full path! With your direction I see that I had a misplaced ""!

Script works perfectly now. really looking forward to gaining some scripting knowledge next month at JNUC :-)