I'm trying to shutdown Macs after 24 hours of runtime with this script:
#!/bin/bash
BOOT_TIME=$(sysctl -n kern.boottime | sed -e 's/.* sec = \([0-9]*\).*/\1/')
CURR_TIME=$(date +%s)
MAX_UPDAYS=1 #Days
DAYS_UP=$(( ( $CURR_TIME - $BOOT_TIME) / 86400 ))
if [ $DAYS_UP -ge ${MAX_UPDAYS} ];then
echo Mac is going to shutdown
shutdown -h now
else
echo No shutdown needed
fi
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?
Best Answer
You are running
ssh
command locally as root and the remote bash (hence the whole script) as the userADMIN@macxxx
(without switching to root on the remote server).You must precede either
bash
orshutdown
withsudo
(providedADMIN
has passwordless sudo permissions forshutdown
or all commands onmacxxx
machine).So either:
Or: