From csh script, how to know if logged in as root?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting From csh script, how to know if logged in as root?
# 1  
Old 04-19-2009
From csh script, how to know if logged in as root?

I know that when I'm logged in as root in (Solaris or Linux), I would get the # sign at the terminal screen.

But from a csh script, how do I know if I'm running that script logged in as root or not?
# 2  
Old 04-19-2009
You could add the following to your script:
Code:
echo `whoami`
sleep 5

However, from an administrative point of view, if you are not sure if you are running that script as root, you probably should not be running that script as root.
# 3  
Old 04-19-2009
Just guessing - but aren't there any built-in variables and/or commands availably you could query, approximately as follows:

Code:
if [ $UID == 0 ]
if [ $USER == 'root' ]
if [ $( whoami ) == "root" ]

# 4  
Old 04-19-2009
Test $LOGNAME .
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

2. Shell Programming and Scripting

How to see actual username who logged in as root with sudo

Hi, Thanks for looking at this. I would like to know who is actually logged in as sudo root ? ex: i have many users given sudo rights as root, and all of they are making changes as root and it is difficult for me to know who did what ,a s it shows as rot only. Is there any way to find or... (4 Replies)
Discussion started by: ramanaraoeee
4 Replies

3. UNIX for Advanced & Expert Users

Need to see what ther Root users are doing while logged in to terminal

I have a server that i need to monitor what the .bash_history file for the root user already logged in to the server I am logged in as root and have another person logged on as root and i want to monitor what they are doing: root ? :0 2010-10-19 11:54 root + pts/1 ... (1 Reply)
Discussion started by: calicowboy54
1 Replies

4. Shell Programming and Scripting

Get current logged in user from a script run as root.

Ok, so, in order to install some dependencies of a program I made, a script has to be run as root. The thing is that I have to copy some things into the home folder of currently logged in user, but the variable $HOME returns '/root' and the $USER returns 'root' :( Is there any way to see who is... (7 Replies)
Discussion started by: hakermania
7 Replies

5. Shell Programming and Scripting

number of users logged in script

My admin needs a shell script in Korn that will show conditions based on users logged in. I have never used the Korn shell and have no clue what I am doing, can anyone help. here are the conditions that need to be returned. if users are below 5 displays should be: performance is high if... (1 Reply)
Discussion started by: vthokiefan
1 Replies

6. Shell Programming and Scripting

Script to check users logged out

Hi, Here is the script that I have written to check if a particular user is has logged out, and if yes, then a mail needs to be sent to the management the details of whatever has been captured by the script command. echo "The current users are:" who | awk '{print $1}' | sort > temp1 cp... (1 Reply)
Discussion started by: ggayathri
1 Replies

7. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

8. Shell Programming and Scripting

script on user who logged in????

writing a script that will check every 5 seconds whether a particular user has logged into the system # Determine if someone is logged on # Version 4.0 if then echo “ Incorrect number of arguments” echo “Usage: $ ison4 <user>” else user=“$1” if who | grep “$user” > /dev/null then... (2 Replies)
Discussion started by: kim187
2 Replies

9. UNIX for Dummies Questions & Answers

Run non-root script as root with non-root environment

All, I want to run a non-root script as the root user with non-root environment variables with crontab. The non-root user would have environment variables for database access such as Oracle or Sybase. The root user does not have the Oracle or Sybase enviroment variables. I thought you could do... (2 Replies)
Discussion started by: bubba112557
2 Replies
Login or Register to Ask a Question