Tux

...making Linux just a little more fun!

[ILUG] shell users/scripters, how do you script yours?

Rick Moen [rick at linuxmafia.com]


Wed, 12 Mar 2008 10:36:44 -0700

Now, there is a BOfH!

----- Forwarded message from Rory Browne <rbmlist@gmail.com> -----

Date: Wed, 12 Mar 2008 17:24:44 +0000
From: Rory Browne <rbmlist@gmail.com>
To: Irish Linux Users Group <ilug@linux.ie>
Subject: Re: [ILUG] shell users/scripters, how do you script yours?
On Wed, Mar 12, 2008 at 2:39 PM, Gavin McCullagh <gmccullagh@gmail.com> wrote:

> Hi,
>
> On Wed, 12 Mar 2008, Rory Browne wrote:
>
> > Returning to the topic, I wouldn't worry too much about executing ls
> > once. I think it only becomes a problem when you run an executable
> > inside a loop that repeats a lot.
>
> Fair point, though the fact that a file called "some file" will be treated
> as two files called "some" and "file" would be my concern.
>

I have a procedure for dealing with when my users put spaces in their filenames.

find / -name '* *' -exec ls -l {} \;

Taking the third column in the output, you get the username, which you can then pipe to ps -u -o pid | xargs -i kill -9 {}

This gives you the list of users with spaces. Some manipulation with Awk, or Perl, can turn this into a list of usernames prefixed with userdel -r, which can then be piped to /bin/sh.

After you've finished deleting your accounts, you can then hire a hitman to ensure that they never receive accounts on any of your systems again.

-- 
Irish Linux Users' Group mailing list
About this list : http://mail.linux.ie/mailman/listinfo/ilug
Who we are : http://www.linux.ie/
Where we are : http://www.linux.ie/map/


Top    Back


Ben Okopnik [ben at linuxgazette.net]


Wed, 12 Mar 2008 22:06:16 -0400

On Wed, Mar 12, 2008 at 10:36:44AM -0700, Rick Moen wrote:

> Now, there is a BOfH!
> 
> ----- Forwarded message from Rory Browne <rbmlist@gmail.com> -----
> 
> Date: Wed, 12 Mar 2008 17:24:44 +0000
> From: Rory Browne <rbmlist@gmail.com>
> To: Irish Linux Users Group <ilug@linux.ie>
> Subject: Re: [ILUG] shell users/scripters, how do you script yours?
> 
> On Wed, Mar 12, 2008 at 2:39 PM, Gavin McCullagh <gmccullagh@gmail.com> wrote:
> > Hi,
> >
> > On Wed, 12 Mar 2008, Rory Browne wrote:
> >
> > > Returning to the topic, I wouldn't worry too much about executing ls
> > > once. I think it only becomes a problem when you run an executable
> > > inside a loop that repeats a lot.
> >
> > Fair point, though the fact that a file called "some file" will be treated
> > as two files called "some" and "file" would be my concern.
> >
> 
> I have a procedure for dealing with when my users put spaces in their filenames.
> 
> find / -name '* *' -exec ls -l {} \;

I'd say that he fell short of the holy title of BOfH - specifically on the 'O' qualifier - as well as instantly qualifying for the Darwin Award.

ben@Tyr:~$ find /usr/share -name '* *' -exec stat -c %U {} \;
root
root
root
root
root
root
root
root
root

The above means that he just killed himself. Perhaps he meant to say "find /home/ -name '* *' -exec ls -l {} \;" instead of "find / -name '* *' -exec ls -l {} \;" ... but Unix isn't very forgiving of anyone who runs untested scripts on a live system - especially when they use the "--send-the-assassins" option of "userdel". [sigh] Sad but true.

> Taking the third column in the output, you get the username, which you
> can then pipe to ps -u -o pid | xargs -i kill -9 {}

You don't need any of that; see below.

> This gives you the list of users with spaces. Some manipulation with
> Awk, or Perl, can turn this into a list of usernames prefixed with
> userdel -r, which can then be piped to /bin/sh.

# "sort -u" will produce a unique list
find / -name '* *' -exec stat -c %U {} \; | sort -u | xargs userdel -r

...a.k.a. "autoDarwination".

> After you've finished deleting your accounts, you can then hire a
> hitman to ensure that they never receive accounts on any of your
> systems again.

Poor Rory. Such a fine man - so generous with his advice... only made the one tiny, innocent mistake in his life... [sob] Break out the whiskey, lads, and we'll remember him properly. :)

-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *


Top    Back