Posted on 11-04-2011 08:31 AM
Hi all,
I'm getting confused with Login Hooks (either OS X or Casper's), Schedule Tasks or LaunchD item.
Need to make a script that will remove ~/Library/Preferences/extensis.plist from every user on a Mac once a month, every month at 9am.
I've been at it all day and just can't figure it out.. So many different ways of doing it… A friend of mine suggested a Python script… I was like "What what what??!!" So not sure how to tackle it.
I'm sure it's a simple script but everything I'm Googling seems so convoluted.
Thanks in advance!!!
--
Pat Camporeale
"From now on I will be referred to as Mister Pastulio"
![external image link](attachments/ac8efdacd0f84d1e805f1c48461d22ee)
Herengracht 258
1016BV Amsterdam
Posted on 11-04-2011 08:37 AM
Scheduled task
-------
#!/bin/bash
shortname=stat -f '%u %Su' /dev/console | awk '{print $2}'
rm /Users/"$shortname"/Library/Preferences/extensis.plist
----
Unless I'm missing something?
Posted on 11-04-2011 08:55 AM
Or loop through all home folders, something along the lines of:
cd /Users
for account in *
do
rm /Users/$account/Library/Preferences/extensis.plist
done
Schedule it with a launchd item...
![external image link](attachments/57d4d1f217a04dac8284ea2f62e652de)
Posted on 11-04-2011 09:14 AM
You say 'all' users.
If the users all are in /Users, then there is no reason you shouldn't be able to do
rm /Users/*/Library/Preferences/extensis.plist
However, this isn't the tidiest, since Shared wont have a file of this, but it wont stop the script running.
To be neater, you could run
ls -1 | grep -v Shared | while read line
and run the rm command for that file.
ls -1 | grep -v Shared | while read line
do
rm /Users/"$line"/Library/Preferences/extensis.plist
done
For a more elegant solution, you would actually check to see if the file existed before removing!
It'll be something like:
ls -1 | grep -v Shared | while read line
do
if [ -f /Users/"$line"/Library/Preferences/extensis.plist ]
then
rm /Users/"$line"/Library/Preferences/extensis.plist
fi
done
Haven't tested this, but it should work!
If your users are network users, then clearly this is going to need handled differently.
You can then either use a policy to trigger this or write your own launchd item to run the script. For launchd, google StartInterval and StartCalendarInterval
![external image link](attachments/1df15409e30a425999bcc78ac3a9b08f)
Posted on 11-04-2011 09:14 AM
+elenty billion for scheduled task via launchd
my method
#!/bin/bash
userList=$(dscl . list /Users UniqueID | awk '$2 > 500 { print $1 }')
for u in ${userList} ; do
rm /Users/${u}/Library/Preferences/extensis.plist
done
exit 0
This will loop through all users with UID greater than 500
-Tom
![external image link](attachments/f288188e6db14cecbdcdd7f196285d3a)