Hi guys i cant figure this out. I am pretty new to mac and have been lumped with supporting the macs at our university (i am starting to enjoy it actually)
Anyway i want to impliment a script to run ever X minutes to shutdown a machine if nobody is using it.
I have created a PowerSchedule.sh file in /Library/Scripts (this is where the login and logout script are located so i put it in the same place)
I have run a chmod 755 and the script is now executable
I have also run a chgrp admin so that it is the same as the other scripts
Now i am trying to get this to run ever 1 minute at the moment just to see if it works. I am using chronnix to create the cron job
I have it set to every 1 minute and the file i have it opening is /Library/Scripts/PowerSchedule.sh
However it just doesnt seem to be working, if i restart a machine and stay at the login screen it never shuts down the machine. is it possible it only wants to run as the user i was logged in with when i ran cronnix? How can i just get it to run as root?
Anyones help would be greatly appreciated
Here is the script
#!/bin/sh
# Sleep or shutdown script
# tryin' to be 'green'.....
# look for exception file
if [ -f "/var/db/.dontSleep" ]; then
exit 0
fi
# if we're a laptop, exit.
# No shutting down laptops (or waking them up unbidden!)
IS_LAPTOP=`/usr/sbin/system_profiler SPHardwareDataType | grep "Model" | grep "Book"`
if [ "$IS_LAPTOP" != "" ]; then
exit 0
fi
# check the time; exit if it's between 5 am and 10 am **CHANGED TO 10 for testing**
current_hour=`/bin/date +%H`
if [ $current_hour -gt 5 -a $current_hour -lt 10 ]; then
exit 0
fi
# now check idle time;
# exit if we've been idle less than 20 minutes
idleTime=`ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=int((pop @F)/1000000000); print $idle,"\n"; last}'`
if [ $idleTime -lt 1200 ]; then
exit 0
fi
# tell Power Manager to wake us up or turn us on at 6am M-F
pmset repeat wakeorpoweron MTWRF 06:00:00
# check to see if a user's logged into the console
login_status=`/usr/bin/who | /usr/bin/awk '{ print $2 }'`
for i in $login_status; do
if [ $i = "console" ]; then
# someone's logged in, sleep
osascript -e 'tell application "System Events" to sleep'
exit 0
fi
done
# if we got this far, it's OK to shut down.
/sbin/shutdown -h now
exit 0
Anyway i want to impliment a script to run ever X minutes to shutdown a machine if nobody is using it.
I have created a PowerSchedule.sh file in /Library/Scripts (this is where the login and logout script are located so i put it in the same place)
I have run a chmod 755 and the script is now executable
I have also run a chgrp admin so that it is the same as the other scripts
Now i am trying to get this to run ever 1 minute at the moment just to see if it works. I am using chronnix to create the cron job
I have it set to every 1 minute and the file i have it opening is /Library/Scripts/PowerSchedule.sh
However it just doesnt seem to be working, if i restart a machine and stay at the login screen it never shuts down the machine. is it possible it only wants to run as the user i was logged in with when i ran cronnix? How can i just get it to run as root?
Anyones help would be greatly appreciated
Here is the script
#!/bin/sh
# Sleep or shutdown script
# tryin' to be 'green'.....
# look for exception file
if [ -f "/var/db/.dontSleep" ]; then
exit 0
fi
# if we're a laptop, exit.
# No shutting down laptops (or waking them up unbidden!)
IS_LAPTOP=`/usr/sbin/system_profiler SPHardwareDataType | grep "Model" | grep "Book"`
if [ "$IS_LAPTOP" != "" ]; then
exit 0
fi
# check the time; exit if it's between 5 am and 10 am **CHANGED TO 10 for testing**
current_hour=`/bin/date +%H`
if [ $current_hour -gt 5 -a $current_hour -lt 10 ]; then
exit 0
fi
# now check idle time;
# exit if we've been idle less than 20 minutes
idleTime=`ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=int((pop @F)/1000000000); print $idle,"\n"; last}'`
if [ $idleTime -lt 1200 ]; then
exit 0
fi
# tell Power Manager to wake us up or turn us on at 6am M-F
pmset repeat wakeorpoweron MTWRF 06:00:00
# check to see if a user's logged into the console
login_status=`/usr/bin/who | /usr/bin/awk '{ print $2 }'`
for i in $login_status; do
if [ $i = "console" ]; then
# someone's logged in, sleep
osascript -e 'tell application "System Events" to sleep'
exit 0
fi
done
# if we got this far, it's OK to shut down.
/sbin/shutdown -h now
exit 0