Click to See Complete Forum and Search --> : write a password file using shell programming


ngb
05-29-2003, 03:51 AM
i am trying to write a password file in shell programming under linux , now my situation is i would like to get the last record 's UID and increase the value by one, and assign it to a new user account. but i fail to select the last record.....it always come out with error when i run the program........the error is " the command not found"
i already create one record in passwd file .......
becca:12hjhh:1:1:becca thomas:/usr/becca:/usr/ucb/csh

suppose when i create another new user, the user id should be 2, but it come out with error : cannot found the command....
here is what i do :

tempnewID= `tail -1 /etc/passwd | awk -F: '{print $3}' `
newID= ` expr $tempnewID + 1 `


can anyone come out with more suitable command to get the result???thanks

goon12
05-29-2003, 09:09 AM
This should add the uid + 1:

#!/bin/bash

lastid=`cat /etc/passwd | tail -1 | cut -f3 -d:`
echo "lastid: " $lastid

newid=`expr $lastid + 1`
echo "newid: " $newid

bwkaz
05-29-2003, 10:25 PM
Cannot find what command? awk? tail? expr?

Do you have an awk program? Or should you be using gawk instead?

Does your bash work well with expr? Or should you be doing this instead:

newID=$(echo $(($tempnewID + 1)))?