Sudo question


 
Thread Tools Search this Thread
Operating Systems AIX Sudo question
# 1  
Old 09-01-2015
Sudo question

I am running AIX 6.6.5.115 and am experiencing a problem using sudo. I have shell scripts that I created for our HR user and shell scripts that I created for root administrators. I do have a need to embed a sudo command in the user shell script to run one command as root. However the two environments are different and the command will fail if I use a sudo -u root followed by the command as it is using the HR user variables rather than the true root variables. Can someone please offer me some suggestions on how to do this? I am new to sudo and am trying to learn it on my own due to budget constraints.

Thanks in advance,

Ron
# 2  
Old 09-01-2015
You havent chown us the line in sudoers file for that HR user...
Have you tried to pass a line in sudoers like ?
Code:
HRuser ALL=(ALL)   NOPASSWD:<the command you want to pass>

# 3  
Old 09-01-2015
I have not tried that as I have three different commands any one of which many need to be run depending on what is being processed on that particular day. I thought I should be able to just run the command via sudo but the environment and PS1 variables due not set properly when using sudo commands. I can manually set everything with the exception of the PS1 variable.
# 4  
Old 09-01-2015
Code:
$ sudo -u root

usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
            [command]
usage: sudo [-AbEHknPS] [-C num] [-g group] [-h host] [-p prompt] [-u user]
            [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C num] [-g group] [-h host] [-p prompt] [-u user] file
            ...

$

You haven't shown us what you're actually doing so I'm only guessing, but you may want to sudo su - instead of sudo su.

The -u root is redundant.
# 5  
Old 09-01-2015
Here is the command and error, the error is coming up due to the wrong environment variables and PS1 variables being set (user variables, not root). The reason for the sudo -u root is so the user does not get prompted for the root password when the script runs as they do not have access to the root login. The user will just click on an icon in windows to run the script and only be prompted for their user login.

Command:
Code:
sudo -u root /opt/AMSADV3/AMSJobInteractionClient/impenrl.sh

Error:
Code:
AMS ADVANTAGE 3.x Batch CommandLine Processor 1.1
Load Balancing Enabled

Exception in thread "main" java.lang.NullPointerException
at com.amsinc.gems.adv.batch.jobmanagerclient.AMSJobInteractionClient.<init>(AMSJobInteractionClient.java:265)
at com.amsinc.gems.adv.batch.jobmanagerclient.AMSJobInteractionClient.main(AMSJobInteractionClient.java:3010)


---------- Post updated at 12:41 PM ---------- Previous update was at 12:30 PM ----------

The variables are different as shown below, I have also removed ssh ip addresses and server names for this post that would normally show in the environment for security reasons. When logged in as the hr user and the script is launched the PS1 User name shows the hr user not the root user.

HR User:
Code:
HOME=/opt/AMSADV3/hrm39
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/opt/AMSADV3/hrm39/bin:/usr/bin/X11:/sbin:.
MAIL=/var/spool/mail/hr
SHELL=/bin/csh
TZ=America/New_York
SSH_TTY=/dev/pts/2
TERM=xterm
AUTHSTATE=compat
LANG=en_US
LOCPATH=/usr/lib/nls/loc
LC__FASTMSG=true
ODMDIR=/etc/objrepos
CLCMD_PASSTHRU=1
NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat

root user:
Code:
 LANG=en_US
LOGIN=root
SSH_TTY=/dev/pts/4
CLCMD_PASSTHRU=1
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin
LC__FASTMSG=true
LOGNAME=root
MAIL=/usr/spool/mail/root
LOCPATH=/usr/lib/nls/loc
PS1=xxxxxxxxx [$USER]: $PWD >
USER=root
AUTHSTATE=compat
SHELL=/usr/bin/ksh
ODMDIR=/etc/objrepos
HOME=/
TERM=xterm
MAILMSG=[YOU HAVE NEW MAIL]
PWD=/
TZ=America/New_York
ENV=//.kshrc
A__z=! LOGNAME


Last edited by Corona688; 09-01-2015 at 03:04 PM..
# 6  
Old 09-01-2015
Try sudo -i so it runs the script in a proper root shell with root's environment.
# 7  
Old 09-02-2015
First: a script should set its own set of variables. You wouldn't have this problem then. Do something like this:

Code:
#! /bin/ksh

. /some/common/environment.file

<...rest of your script...>

If you really have to set some environment outside the script use sus "-c" switch:

Code:
sudo su -c ENV=/some/file /your/command

Attention: "-c" will wipe out your environment completely before the ENV variable is set. You better make sure that everything you ever need is defined in "/some/file" one or the other way.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Sudo question

Hi All I want to grant elevated privs to a user that will be running a script as a background task. It will be launched from an ssh session via an embedded command in its key that just allows that account to run that script. I'm reading up on sudo and notice that - user ALL=(ALL) ALL ... (2 Replies)
Discussion started by: steadyonabix
2 Replies

2. UNIX for Dummies Questions & Answers

Question about sudo

Hello all, I have a script (script.sh) that is owned and executed by root. Now I need to give another user (user1) sudo access to execute that script. I edited the /etc/sudoers file, and created the following: # Runas alias specification Runas_Alias RO = root user1 ALL=(RO)... (1 Reply)
Discussion started by: designbc
1 Replies

3. UNIX for Dummies Questions & Answers

Sudo question

Folks; I have SUDO configured on my SUSE boxes to allow a specific groups to run specific duties so one group has ALL permission & other group has permission to run a few commands only. when i look at the sudoer log, i see people login info only, Is there a way to capture every thing users do... (3 Replies)
Discussion started by: Katkota
3 Replies

4. Ubuntu

sudo question.

Hello all, Anyone fimilar with su -l command? So when I do su -l <user> any user it doesn't prompt me for password for that user. How I enable sudo to prompt for password whenever su -l command is used. Please help! thanks, -Lalit :D (7 Replies)
Discussion started by: email-lalit
7 Replies

5. Cybersecurity

sudo question

Hi, Is it possible to stop users from copying a login shell, say bash, to another name and then executing it via sudo to gain root priviliges? Normal users have read access to login shells, so they can copy them without any limitations. How can I stop this? Thanks (12 Replies)
Discussion started by: melias
12 Replies

6. Linux

Sudo question

Hello, I would like to know what should I put on the sudoers file to block a determined group os using just one specific command as root? He can do anything, but not execute program X, how can I do this? Thank you very much. (2 Replies)
Discussion started by: Zarnick
2 Replies

7. UNIX for Dummies Questions & Answers

Sudo question

Folks; I have a sudo question: - I have a real user named "greg" and another generic user named "devuser" & application that must be run like start/stop as "devuser" user. Is there a way to: Have user Greg login into the Solaris 10 box as himself then sudo as "devuser" to be able to... (10 Replies)
Discussion started by: Katkota
10 Replies

8. UNIX for Advanced & Expert Users

SUDO question - please help

Hi, I was wondering if someone can give me some pointers about configuring SUDO. I am trying to configure SUDO to have about 30 users run about 200 scripts as a different user. I understand that I can create an User_Alias but how do I give that User_Alias rights to run all the scripts in a certain... (5 Replies)
Discussion started by: sajjad02
5 Replies

9. UNIX for Dummies Questions & Answers

sudo question

how do i go about adding a file to sudo so a user name oracle can run the file??? for some reason my man pages dont have anything for sudo. files sudoers exist in /etc can anyone help this is urgent thank you (1 Reply)
Discussion started by: TRUEST
1 Replies
Login or Register to Ask a Question