using /usr/bin/cut in scripts...
Randal Schwartz
merlyn at iwarp.intel.com
Sat Jul 28 05:20:28 AEST 1990
In article <19253 at well.sf.ca.us>, whofan at 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 at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
More information about the Comp.unix.i386
mailing list