I'm trying to shutdown Macs after 24 hours of runtime with this script:

BOOT_TIME=$(sysctl -n kern.boottime | sed -e 's/.* sec = \([0-9]*\).*/\1/')
CURR_TIME=$(date +%s)

DAYS_UP=$(( ( $CURR_TIME - $BOOT_TIME) / 86400 ))
    if [ $DAYS_UP -ge ${MAX_UPDAYS} ];then
        echo Mac is going to shutdown 
        shutdown -h now
        echo No shutdown needed

The file name is ShutdownUPTIME.sh. Now when I try to type in:

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

it wants a password. I type that in and then the script runs. The only thing that pops up though is:

shutdown: NOT super-user

The user is in the sudoers file as ALL=(ALL) ALL on both Macs. Any ideas?


You are running ssh command locally as root and the remote bash (hence the whole script) as the user ADMIN@macxxx (without switching to root on the remote server).

You must precede either bash or shutdown with sudo (provided ADMIN has passwordless sudo permissions for shutdown or all commands on macxxx machine).

So either:

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


if [ $DAYS_UP -ge ${MAX_UPDAYS} ];then
    echo Mac is going to shutdown 
    sudo shutdown -h now
  • I only used the ssh connection. But I wanted to show my script in case something is wrong with the script. So I just use ssh ADMIN@macxxx 'sudo bash -s' < ./documents/ShutdownUPTIME.sh, but it says I am not a super user. My user is in the sudoers file as ALL=(ALL) ALL, on both the local and the remote Mac. – Gunter Dec 12 '16 at 8:38
  • From the message you cited now, ADMIN does not have sudo permissions on the macxxx. – techraf Dec 12 '16 at 8:45
  • Yes he has. That is why I asked this question. – Gunter Dec 12 '16 at 9:00
  • So include the relevant information I the question, not in the comments to an answer. If the system refuses to change the user with sudo, it means the user has no permissions. In the commands you included in the question, you don't even try to use sudo on the remote machine. – techraf Dec 12 '16 at 9:06

You must log in to answer this question.

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