- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script explanation
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2012 02:29 AM
07-20-2012 02:29 AM
Script explanation
What is the explanation of the below script.
#======= patrol user profile =======
LANG=C; export LANG
MAIL=/usr/mail/${LOGNAME:?}
tty -s
if [ $? -eq 0 ]
then
if [ `logname` != "root" ]
then
exit 1
fi
fi
Ajin.S
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2012 06:22 AM
07-20-2012 06:22 AM
Re: Script explanation
If the return code of the 'tty -s' command is 0, which means you are logged in with a terminal session and NOT running via cron, and you are NOT logged in as root then the script will exit with a return code of 1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2012 06:24 AM
07-20-2012 06:24 AM
Re: Script explanation
# Set the locale variable LANG to C and export it # (locale C means "classic unix processing: no particular localization, # all error messages in US English and character set US-ASCII only) LANG=C; export LANG # If the environment variable LOGNAME contains a value, set # variable MAIL to /usr/mail/<value of LOGNAME>. # If LOGNAME is not set, exit. MAIL=/usr/mail/${LOGNAME:?} # Test silently if the script is associated with a terminal. # If not (= the script is run non-interactively as a cron job or # some other background process, or its standard input has been # redirected), the result code $? will be set to # a non-zero value. tty -s # Test the result code of the previous command. If it was zero, # run the commands between the outermost "then" and the outermost "fi". if [ $? -eq 0 ] then # This will be executed only if the result code from the "tty -s" was # zero, i.e. the script is running with a terminal. # Run the command "logname" (which returns the current username) # and examine it's output. # If the output is something other than "root", run the commands # between the inner "then" and inner "fi". if [ `logname` != "root" ] then # This will be executed only if the script is running with a # terminal and the current username was not "root". # This command will exit the script with result code 1. exit 1 fi fi
The first two lines are primarily for setting up some environment settings, and the rest seems to be trying to
stop the script if it is not run by the root user.
If this script has been named as ".profile" in the patrol user's home directory, this would prevent logging in as the "patrol" user, but would allow root to use the "su", "sudo" or similar commands to switch to "patrol" user. If someone tried to log in as user "patrol", the session would immediately end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2012 06:26 AM
07-20-2012 06:26 AM
Re: Script explanation
>MAIL=/usr/mail/${LOGNAME:?}
Hmm, I would have thought it should be /var/mail/.
You can optimize the two "if"s to:
if [ $? -eq 0 -a $(logname) != "root" ]; then
exit 1
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2012 12:10 PM
07-20-2012 12:10 PM
Re: Script explanation
>>>MAIL=/usr/mail/${LOGNAME:?}
>>Hmm, I would have thought it should be /var/mail/.
/usr/mail is a symbolic link (transition link) to /var/mail.
root /usr # ls -ld mail
lrwxrwxrwt 1 root sys 9 Jun 30 2011 mail -> /var/mail
- Tags:
- tlink