Home » Infrastructure » Unix » How to get the user Id of an user?
How to get the user Id of an user? [message #152691] Mon, 26 December 2005 08:16 Go to next message
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 Go to previous messageGo to next message
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 #152985 is a reply to message #152691] Wed, 28 December 2005 05:18 Go to previous messageGo to next message
cgk_js
Messages: 48
Registered: December 2005
Member
We can also get user_id (user#) from v$session
Re: How to get the user Id of an user? [message #153000 is a reply to message #152691] Wed, 28 December 2005 05:50 Go to previous messageGo to next message
rajus19
Messages: 18
Registered: September 2005
Junior Member
what I need is the unix login user id, not the db user id.

Thanks in Advance
Raju
Re: How to get the user Id of an user? [message #153002 is a reply to message #153000] Wed, 28 December 2005 06:01 Go to previous messageGo to next message
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 #156199 is a reply to message #153002] Mon, 23 January 2006 08:59 Go to previous messageGo to next message
kshkid
Messages: 24
Registered: November 2005
Junior Member
instead of two process,

here is a simpler one,

awk -F":" ' /<loginname>/ {print $3}' /etc/passwd
Re: How to get the user Id of an user? [message #156302 is a reply to message #156199] Tue, 24 January 2006 10:02 Go to previous message
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

Previous Topic: Installation of Oracle database 10g Release 2 Grid Control on Solaris 5.9 (64bit)
Next Topic: oracle and compatibility: solaris 8 vs solaris 9
Goto Forum:
  


Current Time: Wed Apr 24 14:34:58 CDT 2024