Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shellscript problem 1

Status
Not open for further replies.

Nostradamus

Technical User
May 3, 2000
419
SE
take a look at this script...

#!/usr/bin/ksh

ID=10000

id_user()
{
ID=`expr $ID + 1`
}

cat $1 |
while read line
do
USER=`echo $line | awk '{print $1}'`
INFO=`echo $line | awk '{print $2 " " $3}'`

echo mkuser id=$ID home=/home/$USER gecos="$INFO" $USER

id_user

done

This is (a simplyfied version) one of a couple of scripts I use to add users.

The input variable ($1) looks like this (as you might have guessed)
first column username
second column first name of user
third column last name of user.

As you can see I began the uid from 10 000 and for each new user (line in the input file) a add 1 number.
If the input file has 10 lines/users, then the last uid would be 10 010.

How do I add this number to the script?
The next time I run this script I want the ID variable to tell 10010 instead of 10000.

Hope you understand what I mean. /Sören
 
Change

ID=10000

to

ID=`tail -1 /etc/passwd |cut -f3 -d:`

That will always take the last ID # of the last user in /etc/passwd, and put it in the ID variable.

Bill.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top