Operating System - HP-UX
1829559 Members
2129 Online
109992 Solutions
New Discussion

Ids free in file /etc/passwd -Script-

 
Oscar Castillo Murillo
Occasional Advisor

Ids free in file /etc/passwd -Script-

As obtaining the ids free of the file / etc/passwd by means of a script}

Thanks for your help.
5 REPLIES 5
saju_2
Respected Contributor

Re: Ids free in file /etc/passwd -Script-

Hi

Which id you r looking UID or GID or something else..

For UID

use
cat /etc/passwd|cut -f3 -d ":" |sort -n
This will show the used UID's in sorted order
For GID
cat /etc/passwd|cut -f4 -d ":" |sort -n

regards
CS
Oscar Castillo Murillo
Occasional Advisor

Re: Ids free in file /etc/passwd -Script-

I need extract the ids free but not the list of ids in used.

rveri
Super Advisor

Re: Ids free in file /etc/passwd -Script-

Hi Oscar ,

Please use this command , to see the UID's used in the order and to find which are not used.

$ cat /etc/passwd | awk -F ":" '{print $3}' | sort -n


Cheers ,
Veri.
------
D Block 2
Respected Contributor

Re: Ids free in file /etc/passwd -Script-

there is a command called: 'logins', with the 's' at the end.

# man logins

Golf is a Good Walk Spoiled, Mark Twain.
saju_2
Respected Contributor

Re: Ids free in file /etc/passwd -Script-

Hi

I tried one script , but for that you need one file with integers 1 to 500 or what ever the last UID you want

I made such a file by
ls -rt /tmp|awk '{print NR}'>numbers
Then sort the UID by
cat /etc/passwd|cut -f3 -d ":">idsort

then write a script

rm /tmp/nonids
for i in `cat /tmp/numbers`
do
j=`grep -x $i idsort; echo $?`
if [ $j -eq 1 ]
then
echo $i>>/tmp/nonids
fi
done


Check the file nonids , it will contain UIDs which were not in the server

Regards
CS