Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have an AIX 6.1 server where I need to run a remote sudo command in a bash script.

Here is my bash script simplified:

testSudo.sh

#!/usr/bin/bash
set -x

sudo env

I can run the sudo command locally without password:

[user@server]$ sudo env
VAR=VAL
...

I can run the script locally:

[user@server]$ /tmp/testSudo.sh
+ sudo env
VAR=VAL
...

I can run sudo on the remote host:

[user@client]$ ssh user@server sudo env
VAR=VAL
...

I can run the script on the remote host with tty:

[user@client]$ ssh -t user@server /tmp/testSudo.sh
+ sudo env
VAR=VAL
...

I cant run the script on the remote host without tty (and I cant add the -t option in my context):

[user@client]$ ssh user@server /tmp/testSudo.sh
+ sudo env

It hangs there.

share|improve this question
    
Does running sudo on the remote server require a password? –  jw013 Jul 17 '13 at 17:12
    
So why not run ssh -t? –  Gilles Jul 17 '13 at 23:47
    
@jw013 No there is no password required while runnig sudo on the remote server. –  Pierre-Louis Laffont Jul 18 '13 at 7:56
    
@Gilles I'm making the request, is an extarnal program who does, so I can't change the ssh options. –  Pierre-Louis Laffont Jul 18 '13 at 7:57
add comment

1 Answer 1

Sudo when executed w/o terminal requires a helper program to handle password query:

SUDO_ASKPASS    Specifies the path to a helper program used to read the
password if no terminal is available or if the -A option is specified.

Normally when you connect via ssh and sudo will need a password but terminal is not allocated it will blow an error - on AIX this can behave different.

Check your sudo settings and enable NOPASSWD from all remote machines also, correct rule should look like that (add it on the end of /etc/sudoers) :

user ALL= NOPASSWD:/tmp/testSudo.sh

share|improve this answer
2  
I don't understand why I need to add 'user ALL= NOPASSWD:/tmp/testSudo.sh' in my sudoers. This script is not played in a sudo but it plays a sudo : 'sudo env'. I allready have a line saying 'user ALL= NOPASSWD:env'. –  Pierre-Louis Laffont Jul 18 '13 at 8:06
    
8 mnths delay in answer - hope you accept that ;) I would make a try and use fullpath to env ( like '/usr/bin/env' ) both in sudo config and your script. –  maq Apr 5 at 14:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.