checking uid


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking uid
# 1  
Old 07-19-2007
checking uid

How do i go about getting the uid of the user and verify ?

Code:
if [ $uid != 'root' ] 
then 
        echo "You are not a superuser, please login as a superuser"
        exit1; 
fi

the above code doesn't work. can some guru please help me.
1. how to get the uid of the user ? i know by typing id but how to get the script to verify its a su?
2. how do i exit the whole script if he/she is not a su?
3. Is the above, able to continue the rest of the process if its a su?

-Thanks & Regards-
# 2  
Old 07-19-2007
use $USERNAME

Code:
if [ $USERNAME != 'root' ]
 then
  echo "you are not root"
 else
  echo "you are root"
 fi

# 3  
Old 07-19-2007
hmmm ... i echo $USERNAME and i got nothing
# 4  
Old 07-19-2007
which shell and os are you using ?
# 5  
Old 07-19-2007
else you might try

Code:
id | sed 's/).*$//;s/^.*(//'

# 6  
Old 07-19-2007
i'm using sun solaris 9, bash
# 7  
Old 07-19-2007
Quote:
Originally Posted by filthymonk
[...]
1. how to get the uid of the user ?

Code:
$ ps -p $$
   PID TTY      TIME CMD
 10387 pts/4    0:00 bash
$ id
uid=0(root) gid=1(other)
$ echo $UID
0
$ [ "$UID" -eq 0 ]||{ echo 'Go away!';exit 1;}
$ su - oracle
$  [ "$UID" -eq 0 ]||{ echo 'Go away!';exit 1;}
Go away!
logout

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Stop boot system at "Checking protected password and checking subsystem databases"

Hi, (i'm sorry for my english) I'm a problem on boot sco unix 5.0.5 open server. this stop at "Checking protected password and checking subsystem databases" (See this image ) I'm try this: 1) http://www.digipedia.pl/usenet/thread/50/37093/#post37094 2) SCO: SCO Unix - Server hangs... (9 Replies)
Discussion started by: buji
9 Replies

2. Solaris

UID Admin

Hi All, I have to give permission to one of the groups called as "ABC" as like the permissions of the group "UNIXADM". Could you please some one help on this issue ? (3 Replies)
Discussion started by: ramareddi16
3 Replies

3. Solaris

Changing uid value

Hi, I want to change user id gefadm ,uid=0(root) gid=0(root) to uid=16649(isaadmin) gid=16284(dstage), how can i change this uid ,gid one value to another value. Please provide the steps how can i change , uid=0(root) gid=0(root) to uid=16649(isaadmin) gid=16284(dstage). Thanks in advance for... (2 Replies)
Discussion started by: sridhardwh
2 Replies

4. AIX

More than 1 UID 0

Hi, Can any one please tell what are the risks of having more than one users having UID 0 (root)? Thanks Naveed (9 Replies)
Discussion started by: naveedaix
9 Replies

5. UNIX for Dummies Questions & Answers

Duplicated UID

Hi folks! I need you help to discover what's the impact of a duplicated UID in an operating system. What's the meaning when someone put in different users the same UID? (3 Replies)
Discussion started by: phcostabh
3 Replies

6. Shell Programming and Scripting

UId

is tty command opens a process in the system if yes then why process got the userid????? (5 Replies)
Discussion started by: Mac91
5 Replies

7. Shell Programming and Scripting

uid script help

i need a script to process a password file and based on the UIDs in the password file, generate the new UID that is 1 greater than the highest uid. i have some script logic but i dont really understand it. any help? #!/usr/bin/perl ########################################## #... (3 Replies)
Discussion started by: livewire06
3 Replies

8. Shell Programming and Scripting

Shall I go for uid or ppid?

Hi Guys, I'd like to ask your advice on the following, I've written this script to terminate a given process by name: #!/bin/bash echo 'Please enter the process you wish to terminate' read process pid=$(pidof $process) kill -9 $pid echo $2 to make it safer I want it to reject the... (4 Replies)
Discussion started by: Lora Graham
4 Replies

9. UNIX for Dummies Questions & Answers

Reversing UID's

Is it possible given a uid to determine information about the person with the uid? An example would be simple information regarding what group and the name of the person associated with that uid. It seems there is probably an easy staring me in the face but i cant seem to find it... (3 Replies)
Discussion started by: dreaming1
3 Replies

10. UNIX for Dummies Questions & Answers

UID problem

I'm teaching myself UNIX, so bear with me! :) I created two user accounts on my box. One day I shut down the system using "shutdown -h 1". The system shut down cleanly. A few days I rebooted the box, no problem. But root is the only account that can log in. The other 2 user accounts... (10 Replies)
Discussion started by: ChrisFoxx
10 Replies
Login or Register to Ask a Question