Using cron to shutdown machine while at login window

I have a problem with my “Energy Saver” prefs in that the machine won’t shutdown at the scheduled time, so I wrote a script:

on awake from nib theObject
	
	tell application "System Events"
		
		shut down
		
	end tell
	
end awake from nib

but when the machine is sitting at the login window the script launches from cron but just sits there and won’t shutdown, so then I tried to at a “killall loginwindow” to the script to see if that was the hangup, but that only recycles the loginwindow with no shutdown.

Can someone please tell me how to execute a shutdown if a machine is at the login window?

Thanks
DAVE

what user is the cron running as ?

Hello,

I’ve tried it as many users including
“root”.

Dave

you should just use the unix command for it from the cron

shutdown -h now

and must be run as root, i havent tested it but it should work.

Kim,

I tried that and it works (I’m using Cronnix) if I test it with the “RUN NOW” button, but if I set it to run at a certain time and then log out to the login screen the command does not execute.

Any ideas?

Dave

BTW… Yes it’s set in root.

i just tried it using /etc/crontab and it didn’t shutdown the system (same problem your having), which is strange. maybe it runs of launchd or something ?

That’s a good possibility. I’ll try and figure it out. I’ll post if I do.

Thanks
Dave

Do you know how the “Shut Down” button is utilized on the login window?

Dave

no, but we cant get a unix command to run so something tells me that the cron is ignored.(which seems crazy)

i think you may need to use a plist file out lined in here
man launchd.plist

Sorry, I forgot to mention that this problem is on my Panther machines.

Dave

good news i got it to work

i created this file and saved it /Library/LaunchDaemons/com.custom.shutdown.plist


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.custom.shutdown</string>
        <key>ProgramArguments</key>
        <array>
                <string>/sbin/shutdown</string>
                <string>-h</string>
                <string>now</string>
        </array>
        <key>LowPriorityIO</key>
        <true/>
        <key>Nice</key>
        <integer>1</integer>
        <key>StartCalendarInterval</key>
        <dict>
                <key>Hour</key>
                <integer>0</integer>
                <key>Minute</key>
                <integer>43</integer>
        </dict>
</dict>
</plist>

and they typed in
sudo launchctl load /Library/LaunchDaemons/com.custom.shutdown.plist

and it will be done (change the hour and min digit to suit yourself)

Thanks I’ll use that for my Tiger machines. I wish it were that easy on Panther.

Dave

Kim,

Do you know how to get a script to push a button on screen?.. say the shutdown button in the login window?

Dave

i have no idea about the login window buttons.