Sponsored Content
Operating Systems OS X (Apple) Scripting User Account Removal Post 302603665 by [MA]Flying_Meat on Thursday 1st of March 2012 08:13:45 PM
Old 03-01-2012
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. :P

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:

Code:
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:
https://www.unix.com/answers-frequent...rithmetic.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. Smilie
(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.)

Code:
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:
Code:
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. Smilie

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

Last edited by [MA]Flying_Meat; 03-01-2012 at 06:02 PM..
This User Gave Thanks to [MA]Flying_Meat For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

creatin user account

hi all, i m tryin to create a new account on the unix work station. do i use 'useradd' command? can u guyz advice on the usage of 'useradd' command as it can comes with 'useradd -D' or 'useradd -e' thanks :confused: (1 Reply)
Discussion started by: damian
1 Replies

2. Post Here to Contact Site Administrators and Moderators

user account

hi how to disable the useraccount in aix (should not remove). (1 Reply)
Discussion started by: chomca
1 Replies

3. UNIX for Dummies Questions & Answers

Difference between : Locked User Account & Disabled User Accounts in Linux ?

Thanks AVKlinux (3 Replies)
Discussion started by: avklinux
3 Replies

4. Shell Programming and Scripting

How to suspend a user account?

Hi, guys. I have two questions: I need to write a script, which can show all the non-suspended users on system, and suspend the selected user account. There are two things I am not sure: 1. How can I suspend user's account? What I think is: add a string to the encrypted password in shadow... (2 Replies)
Discussion started by: daikeyang
2 Replies

5. Red Hat

RPM Updation & Keeping User Change files during removal

Hi All, I have a RPM for an Java based application. Currently it works fine. But recently I want to implement that when newer packages gets installed over the older one, the rpm should only update the older files with the newer one (I know this could be done by rpm -Uvh xxx.rpm), but it... (0 Replies)
Discussion started by: jw_amp
0 Replies

6. Cybersecurity

Please help identify these user account

Please help me identify these user accounts.. bin, lp, nuucp, smbnull, mysql, tftp Can we remove these user or disable these users?We have to apply the security policy about the user identification.Since it was settup by our vendor long time ago. We do not have these informations about these... (3 Replies)
Discussion started by: rdstkg
3 Replies

7. Red Hat

User Account Sync

Hi All, I want to know is there any way where if i add a user in a centos machine the can be replicated to another centos automatically. As i have setup DRBD with heartbeat for apache webserver everything is working fine but the only thing im stuck in is about system account for ftp. Can any... (3 Replies)
Discussion started by: search4u2003
3 Replies

8. Linux

User Account Policy

Hi, i have the following config in the system-auth files auth required /lib/security/$ISA/pam_env.so auth sufficient /lib/security/$ISA/pam_unix.so likeauth nullok auth required /lib/security/$ISA/pam_deny.so account required ... (2 Replies)
Discussion started by: yprudent
2 Replies

9. HP-UX

User account

I need to check actual date a user was disabled on my HP-UX server. Audit is claiming the user account was active during the last audit exercise. (7 Replies)
Discussion started by: cyriac_N
7 Replies
All times are GMT -4. The time now is 10:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy