HPE 9000 and HPE e3000 Servers
1748270 Members
3640 Online
108760 Solutions
New Discussion юеВ

A help on script

 
SOLVED
Go to solution
so_2
Regular Advisor

A help on script

Hi All,

For a user revalidation purpose , i need to get the details of users in certain format.
ie CUSID|USERID|COMMENT|Primary goup|enabled/disabled|last logon|

I have compiled a small script for that, but it is not working. The fist line ie cutting the first column of passwd file itself is not working. I am not able to explain why as when i look the syntax is correct.

Could any one help me here?
for i in `cat /etc/passwd`
do
USER=`$i|cut -f 1 -d ":"`
COMMENT=`$i | cut -f 5 -d ":"`
GROUP=`groups $user`
enable=`/usr/lbin/getprpw -l -r -m lockout $USER`
LAST=`last | grep $USER | head -1 | awk '{print $4 "\t" $5 "\t" $6}'`
URT="IN-TEST"

done


Thanks so
4 REPLIES 4
Matti_Kurkela
Honored Contributor
Solution

Re: A help on script

The problem is that in the third and fourth lines, the content of $i is going to be executed as a command.

A fixed version:
...
USER=`echo $i|cut -f 1 -d ":"`
COMMENT=`echo $i | cut -f 5 -d ":"`
MK
Matti_Kurkela
Honored Contributor

Re: A help on script

Also, your script seems to be sensitive to the maximum length of the command line. If you have a large amount of users, this may cause problems.

You might want to replace your 'for' loop with something like this:

exec # the following commands will read from
# /etc/passwd unless specified otherwise

while read i
do
USER=... # as before
# ...and so on...
done

MK
Yang Qin_1
Honored Contributor

Re: A help on script

Try this one:

#!/usr/bin/ksh

while read i
do
USER=`echo $i|cut -f 1 -d ":"`
COMMENT=`echo $i | cut -f 5 -d ":"`
GROUP=`echo $i | cut -f 4 -d ":"`
enable=`/usr/lbin/getprpw -l -r -m lockout $USER`
LAST=`last -1 $USER | awk '{print $4 "\t" $5 "\t" $6}'`
URT="IN-TEST"

done < /etc/passwd

Yang
so_2
Regular Advisor

Re: A help on script

Hi Both,

I completed it with the help of both your comments.Thanks a lot.from my query itself it is understood that I am a biginer in scripting.I am not sure this forum is meant for addressing such queries, if i am wrong apologies.

Points have been assigned .

Thanks again
s.o