Ah! Sorry. The quoting thing gets me periodically. When to quote/not to quote, which quote method... You can probably remove the quotes from within that particular if statement and it would probably still work.
A time stamp operation would necessarily require a rework of the logic behind the logout script. Instead of using the current user ($USER) you would have to loop through every user profile EXCEPT the current user.
It can be done, but...
Here is an example of a loop for that sort of thing:
for i in `ls /Users`
do
if [ $i = ".localized" ] || [ $i = "Shared" ] || [ $i = $USER ]; then
# go to next folder in the loop
continue
else
# do something with the folder, for instance:
# rm -R /Users/"$i"
echo "$i removed"
fi
done
You would insert your timestamp check and deletion routine after the "else", presumably by nesting an if statement there. Failing the timestamp check would require continuing the loop, a la "continue" as seen above.
The time stamp check value would be the current day and time minus 1 day.
This should help:
http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html
Where you get the time stamp from on the user's home folder? My own home folder does show my login time, as do a couple of preference files in my home folder's Library/Preferences. You will need to kajigger the date info to work correctly in a comparison. You'll also want to verify the specific time stamp file as the valid choice across a few different logins, both admin and non admin, just to be sure.
Let us know if you achieve nirvana.
(I vaguely recall seeing something along these lines in some long ago Enterprise or Edu list...)
---------- Post updated at 04:59 PM ---------- Previous update was at 01:56 PM ----------
Or!
find /Users -maxdepth 1 \! -mtime -1d
Will return all folders that have not been modified in the last 24 hours (again, testing is important.)
find /Users \( \! -name Users -and \! -name .localized -and \! -name Shared -and \! -name $USER \) -maxdepth 1 \! -mtime -1d
Apparently (within the limits of maximum command line characters per line) you can keep adding "-and \! -name username" entries till you're satisfied.
So:
find /Users \( \! -name Users -and \! -name .localized -and \! -name Shared -and \! -name $USER \) -maxdepth 1 \! -mtime -1d -exec rm -R {} \;
Note the first exclusion "Users". Very important!
The find command output without exclusions looks like this:
$ find /Users -maxdepth 1 \! -mtime -1d
/Users
/Users/.localized
/Users/Shared
You probably do not want to recursively delete the /Users directory.
---------- Post updated at 05:13 PM ---------- Previous update was at 04:59 PM ----------
P.S.
I found this nugget at
CLI Fun: Delete files older than x days