Sponsored Content
Operating Systems OS X (Apple) Scripting User Account Removal Post 302603587 by panacea on Thursday 1st of March 2012 12:06:26 PM
Old 03-01-2012
Close

Ok, I've got the script in place, and the write command set, but I think the code had an error in it?

Code:
# If user is an admin, exit script 
dscl . -read /Groups/admin GroupMembership | grep -q "$USER"
if [ "$? -eq 0 ]; then
# the next line could be substituted for the previous 2 lines
#if [ $USER = "adminuser1" ] || [ $USER = "adminuser2" ] || [ $USER = "adminuser3" ]; then 
echo "LOGOUT: admin folders will not be deleted."
exit 1
fi 

# If home directory exists, delete 
if [ -d "/Users/$USER" ]; then 
echo "LOGOUT: user account cleanup."
rm -R /Users/"$USER" 
dscl . -delete /Users/"$USER"
fi 
exit 0

I put a closing " after the first if [ "$? -eq 0 and now it runs properly. Hehehe, however, it didn't see my admin user as an admin and wiped that out. When I use the substituted line that specifies the user it then works properly.

Totally awesome. Thank you so so much for the help.

Now, is there a way to put a time stamp on that? So say I want to delete the user folder after a period of 24hrs. So if a user doesn't come on that machine for 24 hrs then it gets wiped, but if they happen to come and use that same machine within the specified time period, it skips it.

Last edited by panacea; 03-01-2012 at 01:27 PM..
 

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
ALTER USER 
MAPPING(7) SQL Commands ALTER USER MAPPING(7) NAME
ALTER USER MAPPING - change the definition of a user mapping SYNOPSIS
ALTER USER MAPPING FOR { username | USER | CURRENT_USER | PUBLIC } SERVER servername OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] ) DESCRIPTION
ALTER USER MAPPING changes the definition of a user mapping. The owner of a foreign server can alter user mappings for that server for any user. Also, a user can alter a user mapping for his own user name if USAGE privilege on the server has been granted to the user. PARAMETERS
username User name of the mapping. CURRENT_USER and USER match the name of the current user. PUBLIC is used to match all present and future user names in the system. servername Server name of the user mapping. OPTIONS ( [ ADD | SET | DROP ] option ['value'] [, ... ] ) Change options for the user mapping. The new options override any previously specified options. ADD, SET, and DROP specify the action to be performed. ADD is assumed if no operation is explicitly specified. Option names must be unique; options are also vali- dated by the server's foreign-data wrapper. EXAMPLES
Change the password for user mapping bob, server foo: ALTER USER MAPPING FOR bob SERVER foo OPTIONS (user 'bob', password 'public'); COMPATIBILITY
ALTER USER MAPPING conforms to ISO/IEC 9075-9 (SQL/MED). There is a subtle syntax issue: The standard omits the FOR key word. Since both CREATE USER MAPPING and DROP USER MAPPING use FOR in analogous positions, and IBM DB2 (being the other major SQL/MED implementation) also requires it for ALTER USER MAPPING, PostgreSQL diverges from the standard here in the interest of consistency and interoperability. SEE ALSO
CREATE USER MAPPING [create_user_mapping(7)], DROP USER MAPPING [drop_user_mapping(7)] SQL - Language Statements 2010-05-14 ALTER USER MAPPING(7)
All times are GMT -4. The time now is 08:49 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy