D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Another Scrip Problem

 

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

peter wrote:
> Hi
> 
> Thank you for your help but I am afraid I am being remarkably dense.
> What I want to do is check that the user is or is not a member of uucp.
> If he is not I need to add him.  The following works (except the gpasswd
> bit which I will test on another machine! (What faith!!).
> 
> #! /bin/sh
> groups > temp
> if grep -w 'uucp' temp; then
>       echo "thats great," ${USER} "is a member of uucp"
>       else echo "Oh Dear"
>       # sudo gpasswd -a ${USER} uucp
> fi
> rm temp
> 
> 
> However I do not think it is very elegant, and I do not like putting
> temp  files on other peoples machines.

You'd be better off using something like /tmp/$PID as a temp file too.
As written your script can do strange things if you have more than one
concurrent invocation.

The following should work in anything except the strangest of
configurations.

#!/bin/sh
if [ "$1" == "" ]; then
  echo "usage: $0 group <user>"
  exit -1
fi
if [ "$2" == "" ]; then
  USERNAME=$USER
else
  USERNAME=$2
fi
if [ "`id $USERNAME |awk '{print $3}'|grep \($1\)`" == "" ]; then
  echo "not found"
  exit 0
else
  echo "found"
  exit 1
fi


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIHG6vsoRLMhsZpFcRAjJjAJ9JAvTDxtwmImRn4AM9ONZ6CJQi8wCeKzQN
gqZ0xaOXhYm2SeT9VgCUITw=
=Y481
-----END PGP SIGNATURE-----


-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html