How to get the user Id of an user? [message #152691] |
Mon, 26 December 2005 08:16 |
rajus19
Messages: 18 Registered: September 2005
|
Junior Member |
|
|
Hi I would like to write a script which accepts the user name from the command line and it should find the user id of that particular user name.
Could any one of you pls give me the command which will be useful.
Thanks in Advance
Raju
|
|
|
Re: How to get the user Id of an user? [message #152767 is a reply to message #152691] |
Tue, 27 December 2005 00:00 |
tarundua
Messages: 1080 Registered: June 2005 Location: India
|
Senior Member |
|
|
Script
ogmatix:SID=testdb=>cat usr.sh
#username
uname="$1"
#user id
uid=`sqlplus -S "/as sysdba"<<EOF
set heading off;
select user_id from dba_users
where username like upper('$uname');
EOF`
echo "USER ID:$uid"
dogmatix:SID=testdb=>./usr.sh tanu [B]<-- username[/B]
USER ID:
49
regards,
tarun
|
|
|
|
|
Re: How to get the user Id of an user? [message #153002 is a reply to message #153000] |
Wed, 28 December 2005 06:01 |
tarundua
Messages: 1080 Registered: June 2005 Location: India
|
Senior Member |
|
|
@rajus19
Thats why its always good to explain your requirement properly in your very first post.
[oracle@localhost scripts]$ cat > user_id.sh
# Unix user id
uname="$1"
uid=`grep \^$uname /etc/passwd | awk -F ":" ' { print $3 }'`
echo $uid
[oracle@localhost scripts]$ chmod +x user_id.sh
[oracle@localhost scripts]$ ./user_id.sh tarun
502
|
|
|
|
Re: How to get the user Id of an user? [message #156302 is a reply to message #156199] |
Tue, 24 January 2006 10:02 |
rkl1
Messages: 97 Registered: June 2005
|
Member |
|
|
we can get the info using the simple cut and grep utility
#name.sh
grep -i $1 /etc/passwd|cut -f 3 -d ":"
explanation: we are selecting the field #3 and using the : as the delimiter to get the uid.
or if you just run it with login name:
grep -i oracle /etc/passed|cut -f 3 -d ":"
now run it after chmod +x name.sh
name.sh oracle
|
|
|