[comp.unix.i386] using /usr/bin/cut in scripts...

whofan@well.sf.ca.us (Brian Lawrence Dear) (07/28/90)

 
 
The following is a portion of an installation script.  This portion
reads the /etc/group file, figures out what's the next available
group ID, and then creates a new group and assigns it that next
available ID number:
 
          gid=`/usr/bin/cut -f3 -d: /etc/group|sort -n|tail -1`
          gid=`eval $gid + 1`
          echo "mygroup::$gid:user1,user2,usern" >> /etc/group
 
Thing is, the /usr/bin/cut command is not available on everyone's
SCO XENIX machine.  /usr/bin/cut gets installed if you install
the SCO Text Processing stuff.
 
So.. my question is, is there an alternative to the script
above that I can use and rest assured it'll work on all SCO
XENIX 386 platforms, to add a new group as described?
 
-- brian dear
   coconut computing, inc.

Please respond via e-mail to ..!ucsd!coconet!brian

merlyn@iwarp.intel.com (Randal Schwartz) (07/28/90)

In article <19253@well.sf.ca.us>, whofan@well (Brian Lawrence Dear) writes:
| The following is a portion of an installation script.  This portion
| reads the /etc/group file, figures out what's the next available
| group ID, and then creates a new group and assigns it that next
| available ID number:
|  
|           gid=`/usr/bin/cut -f3 -d: /etc/group|sort -n|tail -1`
|           gid=`eval $gid + 1`
|           echo "mygroup::$gid:user1,user2,usern" >> /etc/group
|  
| Thing is, the /usr/bin/cut command is not available on everyone's
| SCO XENIX machine.  /usr/bin/cut gets installed if you install
| the SCO Text Processing stuff.
|  
| So.. my question is, is there an alternative to the script
| above that I can use and rest assured it'll work on all SCO
| XENIX 386 platforms, to add a new group as described?

awk -F: '{if (maxgid < $3) maxgid = $3}
END { print "mygroup::" maxgid+1 ":user1,user2,usern" }' /etc/group >>/tmp/$$
cat /tmp/$$ >>/etc/group; rm /tmp/$$

It'd be about the same in Perl, as in:

perl -pi.bak -e '$t=(split(/:/))[2]; $m = $t if $m < $t;
$_ .= sprintf ("mygroup::%d:user1,user2,usern\n",$m+1) if eof;' /etc/group

which leaves the old /etc/group in /etc/group.bak.

But, as you said, you want it to work on all SCO XENIX platforms, and
Perl isn't installed there (yet... just wait!).

Just another Perl hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/

als@roxanne.mlb.semi.harris.com (Alan Sparks) (07/28/90)

In article <19253@well.sf.ca.us> whofan@well.sf.ca.us (Brian Lawrence Dear) writes:
>
>The following is a portion of an installation script.  This portion
[deleted]
>          gid=`/usr/bin/cut -f3 -d: /etc/group|sort -n|tail -1`
>          gid=`eval $gid + 1`
>          echo "mygroup::$gid:user1,user2,usern" >> /etc/group
> 
>Thing is, the /usr/bin/cut command is not available on everyone's
[deleted]> 
>So.. my question is, is there an alternative to the script
[deleted]

Might I suggest replacing the first line with:

	gid=`/bin/awk -F: '{print $3}' etc/group|sort -n|tail -1`

daveh@marob.masa.com (Dave Hammond) (07/29/90)

In article <19253@well.sf.ca.us> Brian Lawrence Dear writes:
>
>          gid=`/usr/bin/cut -f3 -d: /etc/group|sort -n|tail -1`
> 
>Thing is, the /usr/bin/cut command is not available on everyone's
>SCO XENIX machine.[...]
>
>So.. my question is, is there an alternative to the script
>above that I can use and rest assured it'll work on all SCO
>XENIX 386 platforms, to add a new group as described?

One alternative is awk.  Replace "/usr/bin/cut -f3 -d:" with
"awk -F: '{print $3}'":

          gid=`awk -F: '{print $3}' /etc/group|sort -n|tail -1`


Another alternative is to get the public domain version of cut from
your local comp.sources archive.

--
Dave Hammond
daveh@marob.masa.com
uunet!masa.com!marob!daveh

dmt@PacBell.COM (Dave Turner) (07/31/90)

In article <19253@well.sf.ca.us> whofan@well.sf.ca.us (Brian Lawrence Dear) writes:
.The following is a portion of an installation script.  This portion
.reads the /etc/group file, figures out what's the next available
.group ID, and then creates a new group and assigns it that next
.available ID number:
. 
.          gid=`/usr/bin/cut -f3 -d: /etc/group|sort -n|tail -1`
.          gid=`eval $gid + 1`
.          echo "mygroup::$gid:user1,user2,usern" >> /etc/group
. 

If you have sed, you could replace line one above with:

	gid=`sort -t: -rn +2 -3 /etc/group | sed -n -e "1s/.*:.*:\(.*\):.*/\1/p"`



-- 
Dave Turner	415/823-2001	{att,bellcore,sun,ames,decwrl}!pacbell!dmt