1

I'm trying to run a shutdown script remotely on multiple Macs. The command I use to start it over ssh is:

ssh ADMIN@mac123 'bash -s' sudo < ./documents/ShutdownUPTIME.sh

Of course it asks me for an sudo password, which I type in correctly. The only message after that is: sudo: no tty present and no askpass program specified

Any ideas how I can fix this? My user is definitely a super-user

2

The error message appears when you try to run a command inside your bash call with sudo and, although the user ADMIN on the destination system mac123 has permissions to run commands with sudo, the option NOPASSWD is not specified for this particular user (in /etc/sudoers).

System would have to prompt user and wait for the password to be provided from the keyboard, however as no terminal is attached, the prompt would hang forever.

As a measure against such situation, system fails with the error message you got.


If you took time to understand my yesterday's answer:

provided ADMIN has passwordless sudo permissions for shutdown or all commands on macxxx machine)

You wouldn't run into this problem.

You should modify your script:

...
if [ $DAYS_UP -ge ${MAX_UPDAYS} ];then
    echo Mac is going to shutdown 
    sudo shutdown -h now
else
...

And edit the sudoers file on mac123, so that it contains, for example (it must match the command in the script):

ADMIN ALL=(ALL) NOPASSWD: /sbin/shutdown -h now

Bear in mind that you must do it using visudo program, otherwise you will likely break your system completely.


Alternatively you can use SUDO_ASKPASS environment variable and point it to a script providing the password (the second part of the error message). I do not recommend this method.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .