LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Turning off computer with a single command (https://www.linuxquestions.org/questions/linux-newbie-8/turning-off-computer-with-a-single-command-327517/)

xuper 05-26-2005 10:03 PM

Turning off computer with a single command
 
One thing that has really started to annoy me every night is when I am falling half asleep in front of the pc and I click on shutdown and then have to wait for everything to close and for the computer to tell me that it is safe to turn it off. Is it possible to shutdown linux with a single command just as in windows? or be able to shut it down by hitting the reset button?

running mandrake 10.1

JimBass 05-26-2005 10:11 PM

As root, or with sudo, issue the command
Code:

/sbin/shutdown -h -t0 now
That should shut you off within 20 seconds. If your computer does not power off, you may need to add modules to your kernel for that to work, but generally it should kill it easily.

Peace,
JimBass

ilikejam 05-26-2005 10:22 PM

I've got Ctrl-Alt-Del mapped to 'shutdown -h now', but that doesn't work in X, so it might not be a lot of use.

Dave

gbhil 05-26-2005 10:29 PM

in ~/.bashrc add this line with your current aliases

alias off="sudo /sbin/poweroff"

assuming sudo is setup for it, you can then issue the command "off" from a terminal to shut down.

aes canis 05-26-2005 10:33 PM

I found this on the net, but shamefully cannot remember where...
So, I'm not claiming originallity for it, and appologise to the original author!:
----------------------------------------
Making poweroff and reboot buttons
In Slackware when we want to power-off we need to give the command shutdown -h now as root in a terminal. (Because there is no entry for shutdown in the menu)
We can make a power-off button, but it needs some work, here is how to do that:
Edit the sudoers file, as root, with vi.
There is a special command to open the sudoers file in vi though - NOT vi sudoes, but:
Code:

# visudo
This will open the file in vi so press i to put vi in insert mode and paste the next line at the end of the file:
Code:

username ALL=(ALL) NOPASSWD: /sbin/shutdown -h now, /sbin/reboot
You need to do this for every user you will allow to reboot and halt.
Then save and close the file:
We now gave bruno sudo permission to give the commands sudo /sbin/reboot and sudo /sbin/halt and we can meke special buttons on the tastbar:
Rightclick on the taskbar and choose Add | Special Button | Non-KDE application. You will get a little GUI where you can put in the top box (Executable):
Code:

sudo /sbin/reboot
Click the icon button to change the icon to the one you like. Click OK and you are ready.
Do the same for:
Code:

sudo /sbin/halt
Every user you did add in the sudoers file will be able to press the buttons and reboot or halt the system.
------------------------------------------------
After that, I made a toolbar short cut to /sbin/shutdown -h now which works. So, when logged in as a regular user, I can shut the PC off properly without having to log out, login as root & then shutdown.

fancypiper 05-26-2005 10:54 PM

Why shut it down? I have cron jobs that run and do stuff for me during my physical sleep. I like my computer to do work while I take it easy, so the only time I go down is when I decide to switch between my 4 operating systems.

alias is your friend, see my .bashrc file.
Code:

# Duron 950 uilleann .bashrc for root
# User specific aliases and functions

# Change bash prompt. See the article
export PS1='\d \@ \[\e[31;1m\]\u\[\e[34;1m\]@\[\e[36;1m\]\H \[\e[34;1m\]\w\[\e[31;1m\] # \[\e[0m\]'

# Turn off and reboot
alias off='shutdown -h now'
alias boot='shutdown -r now'

# Run Gentoo file manager as root
alias gentoo='gentoo --root-ok'

# Change permissions of /home/fancy and /pub
alias fancystuff='chown -R fancy.fancy /home/fancy && chown -R fancy.fancy /pub'
alias philstuff='chown -R phil.user /home/phil && chown -R phil.user /pub'

# Keep 1000 lines in .bash_history (default is 500)
export HISTSIZE=1000
export HISTFILESIZE=1000

#Stop bash from caching duplicate lines.
HISTCONTROL=ignoredups

# Disk free
alias df='df -h'

# Alter the ls command
alias ls='ls -ac'
alias lls='ls -lac'

# xterm
# alias xterm='xterm -bg black -fg white'

# Launch links with my linux links page
alias links='links /home/fancy/bookmarks.html'

# For nano editor because I forget which one I use in which distro
alias pico='nano -w'
alias nano='nano -w'

# New name for top front end
alias gtop='gnome-system-monitor'

# Script needs to be on the bottom of the file or RH updates will fsck it up
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

Code:

# Duron 850 tinwhistle .bashrc for user fancy
# User specific aliases and functions

# Start X server
alias x='startx'

# Change bash prompt. See the article
# http://www-106.ibm.com/developerwork.../l-tip-prompt/
export PS1='\d \@ \[\e[32;1m\]\u\[\e[34;1m\]@\[\e[36;1m\]\H \[\e[34;1m\]\w\[\e[32;1m\] $ \[\e[0m\]'
# For the root account use this
# export PS1='\d \@ \[\e[31;1m\]\u\[\e[34;1m\]@\[\e[36;1m\]\H \[\e[34;1m\]\w\[\e[31;1m\] # \[\e[0m\]'

# Keep 1000 lines in .bash_history (default is 500)
export HISTSIZE=1000
export HISTFILESIZE=1000

#Stop bash from caching duplicate lines.
HISTCONTROL=ignoredups

# Disk free
alias df='df -h'

# Set paths
alias path='echo -e ${PATH//:/\\n}'

# Allow local users to use my X session
# xhost +local:

# I can't remember the new gnome command!
alias gtop='/usr/bin/gnome-system-monitor'

# Alter the ls command
alias ls='ls -ac'
alias lls='ls -lac'

# Become system administrator
alias god='su -'

# xterm
# alias xterm='xterm -bg black -fg white'

# Launch links with my linux links page
alias links='links /home/fancy/bookmarks.html'

# For nano editor because I forget which one I use in which distro
alias pico='nano -w'
alias nano='nano -w'

# Script needs to be on the bottom of the file or RH updates will fsck it up
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi


xuper 05-26-2005 10:58 PM

When I type

/sbin/shutdown -h -t0 now

the computer closes all programs running and then tells me its ok to shut it down, so it is the same as shutting it down through the gui. What I want to be able to do is to click on shutdown in the GUI and have the pc shutdown automatically, not have to wait for all the programs to close and then press the reset button. This may not be a critical problem but it is really annoying having to wait for all the programs to close in order for the pc to shutdown

fancypiper 05-26-2005 11:03 PM

If you want your data written to disk correctly before shutting down, the programs need to close to sent the stuff to the disk properly. You risk data corruption if the processes aren't stopped.

I can open an x terminal, give these commands and everything turns off for me:

god
<give password>
off

sudo might be better, but I am stuck in my rut from my 1999 Linux install.

JimBass 05-26-2005 11:10 PM

If your computer doesn't physically power off, it is missing kernel modules, or has a promblem with acpi or apm, whichever power management you're using. Do a search here on linux questions or google.com/linux, and you'll find ways to modify things so the power will shut off at the end of a shutdown.

Peace,
JimBass

cs-cam 05-27-2005 04:03 AM

From my experience, it seems generally laptops use apm and desktops use acpi. You just need to load the modules so the kernel can access the physical hardware required to poweroff.

mrcheeks 05-27-2005 04:22 AM

I think cs-cam, got the right answer. You didn't explain the real problem at the beginning too

pjbii 05-27-2005 11:41 AM

# init 0


All times are GMT -5. The time now is 07:14 AM.