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:
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.
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.)
Apparently (within the limits of maximum command line characters per line) you can keep adding "-and \! -name username" entries till you're satisfied.
So:
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 ----------
I'm trying to understand, actually if you can recommend a great book that describes all this stuff I'd love to know of it. Like I said, I can usually pick apart and fix stuff that already exists, but making my own is beyond me.
So if I wanted to implement that line to find and remove anything after 1 day would it look like this?
So then that would make it skip the user "JoeUser", and the "Shared" folder?
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: ---------- Post updated at 05:55 PM ---------- Previous update was at 05:32 PM ----------
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:
That find on the "remove after x days" was a sweet score!
I actually set it to 3 days to give the inevitable student that forgot to save to a flash drive the opportunity to save face. Though more often than not it's the Grad students that haven't learned this lesson yet and they lose months of work.
That did it. I've got it running on all our units without flaw. So now what?
Thanks so much for all the help [MA]Flying_Meat. And for the tips on what to read. I actually started teaching myself some Objective-C and even the little I've picked up so far in that helped me understand more some of the code you'd written.
I think the problem is finding and using on a regular basis practical uses for creating scripts. I'm not in an environment that requires much of it and being the only one doing it it makes it more of a challenge.
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)
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)
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)
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)
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)
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)
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)