Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-27-2013, 04:43 AM   #1
Mr. Alex
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Executing command on systemd poweroff/reboot

Hello LQers! Long time no visit. I reinstalled my Arch system and now experiencing the death of GNU/Linux as a normal and useful operating system. It went to barely usable garbage. I hate it now and I am severely disappointed in nearly all the development processes going on in the community. Anyway, with this new garbage-dee thing I can't figure out how to execute random command on reboot/poweroff (automatically, as root), just like I did it with echoing string to "/etc/rc.local.shutdown". Can anyone please just tell me? Because I tried to search and get suggestions like

Description=Console System Reboot Logging
DefaultDependencies=no console-kit-log-system-start.service

ExecStartPre=/bin/bash -c /home/domac/.bin/dwm-tmpfile store
I don't feel like digging any deeper... That is just a joke! I feel sick trying to fathom this.
Old 07-27-2013, 09:10 PM   #2
Registered: Apr 2013
Location: /home/
Distribution: Ubuntu 14.04
Posts: 50

Rep: Reputation: 7
A cron job could fit the job of doing something at startup (ie. stage 2 of a reboot, turning on again)

To add these cron jobs to the system, go to the console and do the following:
crontab -e
then at the bottom of the file gets opened, put the commands as shown below in there on the bottom of the file (where the hashtags end).

Quoting from the Cron Wikipedia page:
The following line specifies that the Apache error log clears at one minute past midnight (00:01) of every day of the month, of every day of the week, assuming that the default shell for the cron user is Bourne shell compliant:
1 0 * * *  printf > /var/log/apache/error_log
The following line makes the user program—ostensibly a Perl script—run every two hours, at midnight, 2am, 4am, 6am, 8am, and so on:
0 */2 * * *  /home/username/
Here's how the timings work:
* * * * * command to execute
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names)
│ │ │ └────────── month (1 - 12)
│ │ └─────────────── day of month (1 - 31)
│ └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)
So, for running a cron on boot, instead of using the asterisks, you would use @reboot in a fashion like
@reboot [what to do]
So for instance to execute a sh file on startup, do
@reboot sh /home/Alex/Desktop/
For more info on cron, have a look at the Wikipedia page.

As for the shutdown part of your question, you could just have a .sh file somewhere on your computer containing
[stuff to do, ie. echo Goodbye!]
sudo shutdown -r now
then run that whenever you needed to reboot or if you needed to shutdown, replace the "shutdown -r now" part with "poweroff"

Hope I helped.

Last edited by TRUNoise; 07-27-2013 at 09:21 PM. Reason: Forgot to include the on shutdown part
1 members found this post helpful.
Old 07-28-2013, 05:20 AM   #3
Mr. Alex
Senior Member
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
Yes, thanks, I didn't think of that solution.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
halt, reboot, poweroff, everybody! Jerry Mcguire Linux - General 5 10-18-2010 10:15 AM
reboot/poweroff how? demmylls Linux - General 2 08-13-2009 10:52 AM
Panic; reboot/poweroff; Tralce Linux - Kernel 0 12-04-2006 03:54 PM
reboot vs poweroff??? bigdog0007 Linux - Newbie 4 09-16-2005 03:48 AM
family access to command poweroff & reboot pixelV Slackware 12 02-27-2003 04:18 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:18 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration