Skip to main content
Solved

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


Forum|alt.badge.img+8

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!

Best answer by vadanx

#!/bin/sh

rm -rf /Users/*/.minecraft

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

~Andrew

View original
Did this topic help you find an answer to your question?

23 replies

bentoms
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • November 14, 2013

@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

Forum|alt.badge.img+10
  • Valued Contributor
  • 182 replies
  • November 14, 2013

Ooh, I like that.


Forum|alt.badge.img+7
  • Contributor
  • 60 replies
  • Answer
  • November 14, 2013
#!/bin/sh

rm -rf /Users/*/.minecraft

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

~Andrew


Forum|alt.badge.img+10
  • Valued Contributor
  • 182 replies
  • November 14, 2013

Ooh, I like that more.


Forum|alt.badge.img+8

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....


Forum|alt.badge.img+11
  • Contributor
  • 33 replies
  • November 14, 2013

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.


Forum|alt.badge.img+1
  • New Contributor
  • 5 replies
  • November 14, 2013

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.


Forum|alt.badge.img+11
  • Contributor
  • 33 replies
  • November 14, 2013

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


scottb
Forum|alt.badge.img+18
  • Valued Contributor
  • 1285 replies
  • November 14, 2013
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!


Forum|alt.badge.img+12
  • Contributor
  • 417 replies
  • November 14, 2013

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!


Forum|alt.badge.img+1
  • New Contributor
  • 4 replies
  • November 15, 2013

@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?


Forum|alt.badge.img+1
  • New Contributor
  • 4 replies
  • November 15, 2013

@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?


Forum|alt.badge.img+1
  • New Contributor
  • 4 replies
  • November 15, 2013

@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


Forum|alt.badge.img+7
  • Contributor
  • 60 replies
  • November 15, 2013

@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.


Forum|alt.badge.img+7
  • Contributor
  • 60 replies
  • November 15, 2013

@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.


Forum|alt.badge.img+1
  • New Contributor
  • 4 replies
  • November 15, 2013

@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?


Forum|alt.badge.img+8

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
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • November 16, 2013

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


Forum|alt.badge.img+7
  • Contributor
  • 60 replies
  • November 18, 2013

@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. :)


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • November 18, 2013

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


Forum|alt.badge.img+3
  • New Contributor
  • 9 replies
  • July 31, 2020

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.


Forum|alt.badge.img+18
  • Esteemed Contributor
  • 831 replies
  • January 4, 2021

@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


sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3536 replies
  • January 4, 2021

@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"


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings