Sponsored Content
Operating Systems OS X (Apple) Scripting User Account Removal Post 302604067 by [MA]Flying_Meat on Friday 2nd of March 2012 08:55:05 PM
Old 03-02-2012
Your find line:
Don't forget \! -name Users

Otherwise, yes It would not delete JoeUser, .localized, Shared, nor $USER.

You definitely want to exclude Users, as that would get deleted if it's time stamp is older than a day. Bad, since every home folder you wanted to keep would get deleted too.

You could remove the "exit 1" line from the script so that you still get notification that your admin user account/s will not be deleted. Your first if statement would then just for the notification, proceeding on to the find and delete operation. It should look like this:
Code:
# If home directory exists, delete 
find /Users \( \! -name Users -and \! -name JoeUser -and \! -name .localized -and \! -name Shared -and \! -name $USER \) -maxdepth 1 \! -mtime -1d -exec rm -R {} \;
dscl . -delete /Users/"$USER"
exit 0

---------- Post updated at 05:55 PM ---------- Previous update was at 05:32 PM ----------

As far as creating your own goes:
Advanced Bash-Scripting Guide

Verrrry handy.

Other than that, there's a "Learn Shell Scripting in 24 Hours" which even if it takes 24 days still isn't bad. Also web search, maybe even a quick and dirty Unix class at a local Community College?

It should be said that there is usually more than one way to accomplish the same task. Some might make use almost exclusively of awk, while others might never get much outside of python. Still others might scoff at not using ruby.

I've found that these Unix forums provide real examples of tasks one might need to perform, particularly Shell Programming and Scripting, Unix for Dummies... and Unix for Advanced. I have spent a few hours since finding these forums trying code out to see what it does. If the commands are not exclusive to a particular version of Unix, then it will be informative.
I find shell scripting (bash and/or sh) to be adequate, if admittedly sometimes clunky, for my needs. Learning something else is almost always limited to finding I cannot complete the task in the shell by itself. My most recent tenuous forays into the unknown have been simple awk line parsing with it's marvelous print function.
Pretty darned rare, but then I'm a simple kinda guy.
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
RMM(1)								     [nmh-1.5]								    RMM(1)

NAME
rmm - remove messages SYNOPSIS
rmm [+folder] [msgs] [-unlink | -nounlink] [-version] [-help] DESCRIPTION
By default, rmm will remove the specified messages by renaming each of the message files with a site-dependent prefix (usually a comma). Such files will then need to be removed in some manner after a certain amount of time. Many sites arrange for cron to remove these files once a day, so check with your system administrator. Alternately, if you wish for rmm to really remove the files representing these messages, you can use the -unlink switch. But messages removed by this method cannot be later recovered. If you prefer a more sophisticated method of `removing' messages, you can define the rmmproc profile component. For example, you can add a profile component such as rmmproc: /home/foouser/bin/rmm_msgs then instead of simply renaming the message file, rmm will call the named program or script to handle the files that represent the messages to be deleted. Some users of csh prefer the following: alias rmm 'refile +d' where folder `+d' is a folder for deleted messages, and alias mexp 'rm `mhpath +d all`' is used to "expunge" deleted messages. The current message is not changed by rmm, so a next will advance to the next message in the folder as expected. FILES
$HOME/.mh_profile The user profile PROFILE COMPONENTS
Path: To determine the user's nmh directory Current-Folder: To find the default current folder rmmproc: Program to delete the message SEE ALSO
refile(1), rmf(1) DEFAULTS
`+folder' defaults to the current folder `msgs' defaults to cur `-nounlink' CONTEXT
If a folder is given, it will become the current folder. BUGS
Since refile uses your rmmproc to delete the message, the rmmproc must NOT call refile without specifying -normmproc, or you will create an infinte loop. MH.6.8 11 June 2012 RMM(1)
All times are GMT -4. The time now is 08:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy