0

I want to restart and then shutdown from terminal. Means that we want to startup terminal after restart and then shutdown automatically.

What I am doing with explanation:

  1. Manually start my pc
  2. Run terminal manually
  3. After working on some program for some x minutes
  4. Then the program would ask for restart
  5. This restart would be done from terminal manually
  6. Then after restart again terminal would startup automatically
  7. Terminal would delay shutdown for some x minutes then automatically shutdown

conclusion point 6: only after restart terminal would execute some script automatically which would run for some y minutes then pc would automatically shutdown

How to start up automatically after boot?

  1. Terminal automatically
  2. Some script in the terminal that automatically shuts the pc down.
  • Can you explain which of the above steps you want to be done automatically and which of the above steps you want to be done done manually ? – thom Nov 14 '13 at 16:54
  • 1
    learn bash scripting tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html – Waqas Nov 14 '13 at 17:19
  • @RanaMuhammadWaqas Please update your bookmarks tldp.org/LDP/abs/html – LiveWireBT Nov 16 '13 at 10:02
  • You don't need bash for that... – Braiam Nov 17 '13 at 21:43
1

to restart from terminal

shutdown -r now

to shutdown from terminal

shutdown -h now

to add commands at login, put them in the file ~/.bash_login

If you add a shutdown command to a login file your computer will immediately shutdown after login... always. This is not very productive I guess. What you could do in some situations is to delay the shutdown by a few minutes in order to be able to cancel the login-shutdown when needed. In that case add to ~/.bash_login the following command

shutdown -h 1

if you don't want the computer to shutdown a minute after login you should think about typing

shutdown -c

in a terminal...

I don't know what you want to do exactly but this sounds like a clumsy way to deal with shutdowns and restart, it could get annoying I guess.

  • conclusion point 6: only after restart terminal would execute some script automatically which would run for some y minutes then pc would automatically shutdown – ahmed Nov 21 '13 at 12:49
  • best way is to create a bash script – ahmed Jan 3 '14 at 17:34
0

Add following to bottom of your ~/.bash_login: run: nano ~/.bash_login

if [ -f ~/.isrestart ]; then
    rm ~/.isrestart
    nano # Replace with your program
    shutdown -h 1
fi

Create file restart_run_shutdown: run: nano ~/restart_run_shutdown

#!/bin/bash
touch ~/.isrestart
shutdown -r 1

Make file executable:

chmod u=rwx ~/restart_run_shutdown

If you will use all this from X:

  1. Configure telminal to run bash as login shell.
  2. Add terminal to startup applications

Done. At step 5 run "~/restart_run_shutdown", every thing else will work as expected. If anything goes wrong, you have 1 minute to run "shutdown -c". After test scripts - you can replace 1 with 0, to not wait 1 minute but I don`t recommend this.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.