The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
EOF checking the below ramkrix High Level Programming 10 03-11-2008 01:43 AM
checking for non-zero value philplasma UNIX for Dummies Questions & Answers 6 01-08-2008 04:51 PM
Checking cp progress MarGur UNIX for Dummies Questions & Answers 0 05-15-2007 05:13 PM
Checking for PXE maestro@altiris SUN Solaris 5 05-25-2004 01:06 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-19-2007
filthymonk filthymonk is offline
Registered User
  
 

Join Date: May 2007
Posts: 59
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 (permalink)  
Old 07-19-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
use $USERNAME

Code:
if [ $USERNAME != 'root' ]
 then
  echo "you are not root"
 else
  echo "you are root"
 fi
  #3 (permalink)  
Old 07-19-2007
filthymonk filthymonk is offline
Registered User
  
 

Join Date: May 2007
Posts: 59
hmmm ... i echo $USERNAME and i got nothing
  #4 (permalink)  
Old 07-19-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
which shell and os are you using ?
  #5 (permalink)  
Old 07-19-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,957
else you might try

Code:
id | sed 's/).*$//;s/^.*(//'
  #6 (permalink)  
Old 07-19-2007
filthymonk filthymonk is offline
Registered User
  
 

Join Date: May 2007
Posts: 59
i'm using sun solaris 9, bash
  #7 (permalink)  
Old 07-19-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,910
Quote:
Originally Posted by filthymonk View Post
[...]
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0