[CLUE-Cert] scripting fun

Lynn Danielson lynn.danielson at clue.denver.co.us
Thu Jul 5 11:44:14 MDT 2001


Trying out something like I suggested below, I recently had to add
"-n 1" to xargs so that it would pass the command only one argument
at a time.  

I've also had trouble getting the "{}" replacement string to work.
It's supposed to work with xargs, the same way it works with find's
-exec switch, but the substitution doesn't happen under either Red
Hat 7.1 or Solaris 7.  Does anyone else have experience with this?

Lynn


Lynn Danielson wrote:
> 
> I think the following should work:
> 
> egrep "^s[0-9]+:" /etc/passwd | cut -f1 -d: | xargs -r usermod -G us,exclusiv
> 
> egrep wil print all lines from the passwd file which begin with "s" followed
> by any number of numerals followed by a colon.  Cut will filter for the first
> field which is delimited with a colon.  Xargs will pass its input to usermod
> as arguments.
> 
> Lynn
> 
> jdlabarnhart at home.com wrote:
> >
> > Hello all,
> >
> > When I setup a sysad class I make groups us, them, exclusiv and secret.
> > I need to add students to the us and exclusiv groups. I do this by using
> > a "for" loop.
> >
> > for User in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
> > do
> > usermod -G us,exclusiv s$User
> > done
> >
> > A simple 4 line script. Now what I would like to do is get rid of the 1
> > 2 3 ... line of the for loop and do something like
> >
> > cat /etc/password | xargs grep s*
> > for User in $SUser
> > do
> > usermod -G us,exclusiv s$User
> > done
> >
> > I know what the users are but would like to automate the process a
> > little more. There are goals that need to be met.
> >
> > 1. Small script. 5 -10 lines at max. make it easy to remember.
> > 2. Done in memory. While we could do this with temp files we want to do
> > this without. makes it more fun.
> >
> > Why would we do something like this? How about that a development group
> > is put together to do some work. They will work on project X and will
> > need to access the same documents.
> >
> > /etc/passwd
> > root:x:0:0:root:/root:/bin/bash
> > bin:x:1:1:bin:/bin:
> > daemon:x:2:2:daemon:/sbin:
> > adm:x:3:4:adm:/var/adm:
> > sync:x:5:0:sync:/sbin:/bin/sync
> > shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
> > halt:x:7:0:halt:/sbin:/sbin/halt
> > operator:x:11:0:operator:/root:
> > ftp:x:14:50:FTP User:/var/ftp:
> > sympa:x:89:89:Sympa Mailing list manager:/var/lib/sympa:/bin/bash
> > nobody:x:99:99:Nobody:/:
> > alias:x:400:401:qmail alias user:/var/qmail/alias:/bin/true
> > s1:x:501:501::/home/s1:/bin/bash
> > s2:x:502:502::/home/s2:/bin/bash
> > s3:x:503:503::/home/s3:/bin/bash
> > s4:x:504:504::/home/s4:/bin/bash
> > s5:x:505:505::/home/s5:/bin/bash
> >
> > /etc/group
> > root:x:0:root
> > bin:x:1:root,bin,daemon
> > daemon:x:2:root,bin,daemon
> > sys:x:3:root,bin,adm
> > adm:x:4:root,adm,daemon
> > tty:x:5:
> > disk:x:6:root
> > lp:x:7:daemon,lp
> > mem:x:8:
> > kmem:x:9:
> > wheel:x:10:root
> > us:x:401:
> > them:x:402:
> > excluciv:403:
> > secret:404:
> > s1:x:501:
> > s2:x:502:
> > s3:x:503:
> > s4:x:504:
> > s5:x:505:



More information about the clue-cert mailing list