How to delete a specific file in every users home folder?

steventhemacman
New Contributor III

Hi,

Found a variant of Minecraft that puts an invisible folder at the root of the local AD users home folder. It creates a folder called ".minecraft". I am not very good at scripts, and I don't want to accidentally screw things up.

I know you can do a path to a file in a policy, but am not sure how to do that for every local AD user account.

So just asking for peoples best practice to do away with this file.

Thanks!

1 ACCEPTED SOLUTION

vadanx
Contributor
#!/bin/sh

rm -rf /Users/*/.minecraft

That would cover it safely, I'd say. Maybe run in a policy once per day

~Andrew

View solution in original post

23 REPLIES 23

bentoms
Release Candidate Programs Tester

@steventhemacman, try this:

  1. Create a DMG of the file in Composer.
  2. Index when uploaded to Casper Admin
  3. Set to Fill Existing Users
  4. Tick "Allow This Package to be uninstalled...."
  5. Run a policy to uninstall

tuinte
Contributor III

Ooh, I like that.

vadanx
Contributor
#!/bin/sh

rm -rf /Users/*/.minecraft

That would cover it safely, I'd say. Maybe run in a policy once per day

~Andrew

tuinte
Contributor III

Ooh, I like that more.

steventhemacman
New Contributor III

Unfortunately bentoms policy didn't work...I wonder if it is because it is a invisible folder. Not sure. I triple checked everything, the policy runs, but the folder is still there...I will try the script from vadanx next....

DVG
New Contributor III

You can always set their volume to 10 and use a SAY command to alert them that Minecraft should not be installed on your equipment. That tends to drive the point home...for awhile.

Dusty VanGilder

pcarrier
New Contributor

Because Minecraft is a drag and drop install,why not just disallow any process named Minecraft? If it can't start, it can't dump those folders.

Check out restricted software to limit the use of this app.

DVG
New Contributor III

.jar file and squashing it has caused us issues with our EOC browser and other programs.

Dusty VanGilder

scottb
Honored Contributor
You can always set their volume to 10 and use a SAY command to alert them that Minecraft should not be installed on your equipment. That tends to drive the point home...for awhile.

Maybe the best solution I've read in a while :)
Or, I'm sick like you!

acdesigntech
Contributor II

i like the volume suggestion :)

In practice the wildcard has not always worked for me when running through Casper remote or policy. For some reason the wildcard is not always expanded by the shell.

To that end I've written a boiler plate script that loops through every home directory and performs operations that need to occurr on every existing user. At the end I do whatever it is I need to do to the user template and voila!

Osbourne
New Contributor

@vadanx

I am running open directory on mountain lion server. I need to delete every users firefox profile due to corruption. I am a complete newbie when it comes to scripts. Will these commands work for me through terminal, as long as I point it to the correct directory?

Osbourne
New Contributor

@vadanx

I am running open directory on mountain lion server. I need to delete every users firefox profile due to corruption. I am a complete newbie when it comes to scripts. Will these commands work for me through terminal, as long as I point it to the correct directory?

Osbourne
New Contributor

@vadanx][/url][/url

I am running open directory on mountain lion server. I need to delete every users firefox profile due to corruption. I am a complete newbie when it comes to scripts. Will these commands work for me through terminal, as long as I point it to the correct directory?

edit: Sorry about the multiple posts

vadanx
Contributor

@Osbourne

Do you have network home profiles? Or local to the Mac?

If local to the Mac;

rm -rf /Users/*/Library/Application Support/Firefox

Would cover that, but always practise a script in as close to the environment that it's going to be used in. You could test it with Firefox launched and quit to see if it creates the desired effect you want and expect.

vadanx
Contributor

@Osbourne

Do you have network home profiles? Or local to the Mac?

If local to the Mac;

rm -rf /Users/*/Library/Application Support/Firefox

Would cover that, but always practise a script in as close to the environment that it's going to be used in. You could test it with Firefox launched and quit to see if it creates the desired effect you want and expect.

Osbourne
New Contributor

@vadanx][/url

They are network. my path would be

/DataHD/Usershome

So would

rm -rf /DataHD/Usershome/*/Library/Application Support/Firefox

be the proper usage?

steventhemacman
New Contributor III

I have restriced software set to block "Minecraft" processes, but it does not seem to work, hence my post. Not sure why it isn't working...but the simple command from vadanx seems to be working great.

bentoms
Release Candidate Programs Tester

@steventhemacman. Glad you got it working. I was trying to find a non-scripting way!

vadanx
Contributor

@steventhemacman

Good to see it's working. More often than not the simplest solutions tend to be the best, as long as it doesn't create additional headaches. :)

tlarkin
Honored Contributor

Hey Everyone,

Just my 2 cents here. Using wild cards in scripts could end up in undesired results. Also, when looking at mass deleting files from end users or even file shares on servers I typically like to get some sort of report going first before I pull the 'delete-trigger.' The find binary is perfect for this. I did also try spotlight's binary (mdfind) but it had trouble finding hidden files, the dot file names. I am thinking Spotlight on purpose does not index hidden files.

So, I would maybe build an extension attribute like so:

#!/bin/bash

# find .minecraft and report on it

currentUser=$(ls -l /dev/console | awk '{ print $3}')

# find the file we are looking for

badFile=$(find /Users/${currentUser} -name '.minecraft' -print)

if [[ -e ${badFile} ]]

  then echo "<result>has minecraft</result>"

fi

Then, later on scope out a smart group based on the EA to remove it, by sending out a script on one of your every triggers.

#!/bin/bash

# find .minecraft and report on it

currentUser=$(ls -l /dev/console | awk '{ print $3}')

# find the file we are looking for

badFile=$(find /Users/${currentUser} -name '.minecraft' -print)

if [[ -e ${badFile} ]]

  then rm -rf ${badFile}

fi

exit 0

example output of the delete script:

$ bash -x rm_minecraft.sh
++ ls -l /dev/console
++ awk '{ print $3}'
+ currentUser=tlarkin
++ find /Users/tlarkin -name .minecraft -print
+ badFile=/Users/tlarkin/.minecraft
+ [[ -e /Users/tlarkin/.minecraft ]]
+ rm -rf /Users/tlarkin/.minecraft
+ exit 0

Using the '-print' switch with the find command will allow you to report on this first. Even though it may be unlikely, but someone may make a legit file called "minecraft," and wild carding the commands could delete that file as well. Like, perhaps if a student was writing a paper on that topic. Also, reporting on it allows you to take those reports to those in charge. When I worked for the K12 educational system, I typically never did anything other than build reports and hand them over to the administration for them to decide what to do. If an admin requested I remove files/software I instead built a report in the JSS and emailed it to them so they could decide what to do. This is just my personal experience and I know every K12 environment is different.

Thanks,
Tom

HappyMarcus
New Contributor II

Bringing an old thread to life here, but since this was one of the first results that poped up when googling the issue I thought an update could be useful for any other who have the same question.

I managed to get this working by using the following script:

#!/bin/sh

#Get current logged in user
USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }')

#Delete the file
sudo -u $USER rm /Users/$USER/the/rest/of/the/path.filetype

exit 0

Worth noting here is that if you use ~ instead of /Users/$USER/ the script only succeeds when run as a Self Service policy. If using any other trigger the script fails since it tries to run in the root-directory instead.

GabeShack
Valued Contributor III

@tlarkin I like the approach you are using, but I'm not getting the results in my EA. Im thinking the echo command isn't quite working since the rest of the script seems to function. I updated the get current user command and switched to using the mdfind since its not an invisible file and finds it quite quickly but im just not getting any results with it. I'd actually like to get this working because then I can modify it to work with loads of files. See below:

#!/bin/bash

# find RobloxStudio.dmg and report on it

currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')

# find the file we are looking for

badFile=$(mdfind -onlyin /Users/${currentUser} -name 'RobloxStudio.dmg')

if [[ -e ${badFile} ]]

  then echo "<result>has RobloxStudio</result>"

fi

Gabe Shackney
Princeton Public Schools

Gabe Shackney
Princeton Public Schools

sdagley
Esteemed Contributor II

@gshackney Try this for your EA:

#!/bin/bash

fileToFind="RobloxStudio.dmg"
# find RobloxStudio.dmg and report on it

currentUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{print $3}')

# find the file we are looking for

badFile=$(mdfind -onlyin /Users/${currentUser} -name "$fileToFind")

if [[ -n ${badFile} ]]; then
    echo "<result>Has $fileToFind</result>"
else
    echo "<result>Not found</result>"
fi

The mdfind command can return multiple results, so the -e won't necessarily work. The -n checks to see if it returns anything. Note that it'll also return a hit on "NotRobloxStudio.dmg"