- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Alternatives to 'whoami' for scripts that run in b...
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
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
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
тАО10-31-2003 09:37 AM
тАО10-31-2003 09:37 AM
Usage: who [-rbtpludAasHTqRm] [am i] [utmp_like_file]
r run level
b boot time
t time changes
p processes other than getty or users
l login processes
u useful information
d dead processes
A accounting information
a all (rbtpludA options)
s short form of who (no time since last output or pid)
H print header
T status of tty (+ writable, - not writable, x exclusive open, ? hung)
q quick who
R print host name
ttytype: couldn't open /dev/tty for reading
Is there another way to determine which login is attempting to execute the script in background?
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2003 09:51 AM
тАО10-31-2003 09:51 AM
Re: Alternatives to 'whoami' for scripts that run in background. Scripts are limited to specific user.
Something like this should work fine:
if [ ! `id -u` = 123 ]
then
USER=`id -un`
echo "Run permission denied for user " ${USER}
exit 1
fi
(Where 123 is the "correct" userid)
Admittedly, I haven't used this from a crontab, but
then again, I don't really have a reason to do that, in my case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2003 09:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2003 10:02 AM
тАО10-31-2003 10:02 AM
Re: Alternatives to 'whoami' for scripts that run in background. Scripts are limited to specific user.
Create the group, make root and oracle members of it. Then change the ownership of the script to root with a group of new-group (or whatever you define) and then change the permission on the script to 550 and you are good to go.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-31-2003 10:29 AM
тАО10-31-2003 10:29 AM
Re: Alternatives to 'whoami' for scripts that run in background. Scripts are limited to specific user.
ami.sh
If a match is found, 0 is returned, otherwise 1 is returned.
Here's the script contents:
#!/usr/bin/sh
BNAME=`/usr/bin/basename $0`
passwdID=""
login=""
if [ $# -ne 1 ] ; then
echo "Usage: /usr/local/bin/ami
echo ' ex: /usr/local/bin/ami oracle'
exit 2
else
login=$1
fi
[ "X${RETURNMODE}" = "X" ] && RETURNMODE=0
id $login > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo "ERMS0001: Error - Invalid Login: ($login) configured in $BNAME ... Not in /etc/passwd. Terminating... "
exit 1
fi
passwdID=`grep "^${login}:" /etc/passwd | awk -F: ' { print $3 } '`
idID=`/usr/bin/id -u`
if [ "$passwdID" = "$idID" ] ; then
retval=0
else
retval=1
fi
[ $RETURNMODE -eq 1 ] && echo $retval
exit $retval