The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   delete user on logout (http://hintsforums.macworld.com/showthread.php?t=35961)

kaptagat 03-09-2005 05:40 AM

Thanks, it was running as root and using $1 fixed it.

The working script now looks like :-

#!/bin/sh -f

username=$1
if [ "$username" = "fred" ]; then
echo "bye"
elif [ "$username" = "root" ]; then
echo "bye"
else
rm -r /Users/$1
fi
------------------------------------------

One last question, the echo command seems "messy", is there another way to say if ... then do nothing ?

weltonch777 03-12-2005 07:09 PM

Quote:

Originally Posted by kaptagat
One last question, the echo command seems "messy", is there another way to say if ... then do nothing ?

The ! operator in unix makes checks for NOT, and the && operator is a logical AND. Therefore,

Code:

if [ ! "$1" = "fred" ] && [ ! "$1" = "root" ]
  then rm -r /Users/$1
fi

Should be all you need.
Of course, given the extreme nature of what you are doing, you should test this script first.

Chris

giskard22 03-13-2005 09:20 PM

Hayne, in the preceding reply, is correct. Login/logout hooks run as root. That's why you must use the $1 argument.

Anyways, just to provide some verification, I believe you're finally doing it right. When you log into a network user (i.e. a user from an Active Directory or an LDAP/Open Directory), the NetInfo database on the local machine isn't modified at all. All you need to do is delete the user's home directory from the file system.

In my setup, all the students use the same login. However, just in case someone logs out accidentally or has a crash, I don't want to erase their data right away. My version of your script movies their home directory to a folder in /Library. I use a single 'rm' command via cron every night to clean the folder out.

kaptagat 03-15-2005 04:55 AM

Thanks weltonch 777

Works a treat and is short and elegant. Yours is the one I'm going with.

I will also use a version on login which "blows away" all the rubbish folders such as movies and sites.

Thanks to everyone for their help.

X@vier 04-27-2005 11:14 AM

this is just what i was looking for, thnx to all the people that shared their knowledge

X@vier


All times are GMT -5. The time now is 10:21 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.