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
GTIMER(1)							      GTimer								 GTIMER(1)

NAME
gtimer - an application for recording time spent on user-defined tasks. SYNOPSIS
gtimer [-midnight offset] [-weekstart day] [-nosplash] [-resume] [-start task] DESCRIPTION
GTimer allows the user to time one or more activities. Users define tasks that can be timed. Text annotations can also be added to tasks. Reports can be generated that summarize time spent and annotations. OPTIONS
-midnight offset Specify the offset of midnight to use. Users can allow time spent after midnight to be recorded for the previous day. For exam- ple, the command gtimer -midnight 400 will not consider everything 3:59AM the previous day. -weekstart day Specify which day of the week should be considered the beginning of the week when generating reports. day should be a number between 0 and 6, where 0 is Sunday. For example, the command gtimer -weekstart 1 will use Monday as the first day of the week for all weekly reports. The default is 0 (Sunday). -resume Start timing any tasks that were still be timed when GTimer last exited. -start taskname Start timing the specified task immediately. This option can be used more than once on the command line. For example, you can start a tasks with: gtimer -start 'GTimer development' -nosplash Do not display the splash window on startup. FILES
~/.gtimer/ data storage SEE ALSO
enscript(1), lpr(1) AUTHOR
Craig Knudsen <cknudsen@cknudsen.com> <http://www.cknudsen.com/> GTimer WWW home page: <http://www.cknudsen.com/gtimer/> GTimer Mar 19, 2003 GTIMER(1)
All times are GMT -4. The time now is 05:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy