Shutdown script

d0b33

Honorary Master
Joined
Jul 16, 2004
Messages
17,506
Reaction score
493
Location
Western Cape
This is the current script I use to shutdown my PC using MythTV...
Code:
#!/bin/sh
# This script uses dbus to tell HAL to shut down your computer
dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown

But ever since I moved to 64bit whenever I have a lan connection active the PC won't shutdown, only if I unplug the lan cable will it shut down.

Is it possible to add a command that disables lan before shutdown to this script?

>Ubuntu Intrepid 64bit
 
Last edited:
Why not just try "ifdown eth0"? I've used that before in a script to connect a 3G card

Thanks mate that worked.

I wonder if I should replace my shutdown command too, sometimes it does not respond. Is there a better shutdown command than that dbus one? because this command I found mythtv use so I copied it.
 
Why not use "shutdown -h now"?

Thanks tried that but got nothing.

This is what my script looks like:

Code:
#!/bin/sh
# my shutdown script
ifdown eth0
shutdown -h now

I notice now that the "ifdown eth0" command does nothing either. My system shuts down with lan active now(the update I ran yesterday could have fixed something?)
 
Try using the full path, e.g.
/sbin/shutdown -f now

I try to generalise things as far as possible in my scripts with things like `which shutdown` instead of "/sbin/shutdown" etc.
I suspect that "ifdown" is distro-dependent, so I would use "ifconfig eth0 down" instead, with the full path or by substitution using "which". One can even take it up a notch with variable substitution by testing if the variable is actually defined and giving a diagnostic message if it isn't, e.g.

Code:
SHUTDOWN="`which shutdown` -f now"
if [ -z ${SHUTDOWN} ]; then
    echo "Command not found in path!"
    exit 1
else
    ${SHUTDOWN}
fi
 
Try using the full path, e.g.
/sbin/shutdown -f now

I try to generalise things as far as possible in my scripts with things like `which shutdown` instead of "/sbin/shutdown" etc.
I suspect that "ifdown" is distro-dependent, so I would use "ifconfig eth0 down" instead, with the full path or by substitution using "which". One can even take it up a notch with variable substitution by testing if the variable is actually defined and giving a diagnostic message if it isn't, e.g.

Code:
SHUTDOWN="`which shutdown` -f now"
if [ -z ${SHUTDOWN} ]; then
    echo "Command not found in path!"
    exit 1
else
    ${SHUTDOWN}
fi


Thanks, will give it a shot.
 
Top
Sign up to the MyBroadband newsletter
X