Psyduck
Posts: 2
Joined: Sat May 23, 2015 7:07 pm

How to run a command at boot, and then at every 5 minutes?

Sun Jun 28, 2015 6:10 pm

Hello. I just started using the RPi2. I have a simple question.
How do I run this command at bootup (I"d preffer in the login thing section aka. wall of text).
/opt/vc/bin/vcgencmd measure_temp
Measures the temperature. It would open some new options.
Thanks.

User avatar
DougieLawson
Posts: 40246
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to run a command at boot, and then at every 5 minute

Sun Jun 28, 2015 6:40 pm

What's the point? That temperature reading doesn't really give you anything useful, it's about as much use as a bogomip.

But if you insist add a line to a crontab.

Code: Select all

*/5 * * * * /usr/bin/vcgencmd measure_temp >> /home/pi/temp_log
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
DaveDriesen
Posts: 113
Joined: Sun Mar 31, 2013 8:28 pm
Location: Top of the food chain
Contact: Website

Re: How to run a command at boot, and then at every 5 minute

Sun Jun 28, 2015 8:08 pm

The crontab thing.

In addition, you can use /etc/rc.local to run stuff at startup.

User avatar
DougieLawson
Posts: 40246
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to run a command at boot, and then at every 5 minute

Sun Jun 28, 2015 8:27 pm

DaveDriesen wrote: In addition, you can use /etc/rc.local to run stuff at startup.
That's a one-shot execution, it won't run every five minutes from rc.local (without some scripting).
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

User avatar
DaveDriesen
Posts: 113
Joined: Sun Mar 31, 2013 8:28 pm
Location: Top of the food chain
Contact: Website

Re: How to run a command at boot, and then at every 5 minute

Sun Jun 28, 2015 8:28 pm

Hence my backing towards your crontab post :)

lolderp

User avatar
Senor Larry
Posts: 3
Joined: Sun Jun 28, 2015 8:22 pm

Re: How to run a command at boot, and then at every 5 minute

Sun Jun 28, 2015 8:30 pm

But when I add it it says permission denied. I know I have to be a root user but I dont know all of the fancy terminal stuff.
Thanks to all of the kind replies.
Raspberry Pi2, 4:3 ratio (very bad) Yusmart monitor, Genius LuxeMate i200 keyboard, a generic old HP office mouse that lets through light an a galaxy tab 10.1 power supply.

chris30o0
Posts: 23
Joined: Mon Jul 21, 2014 9:42 pm

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 8:56 am

Where exactly did you put that line?
Did you do "crontab -e", "sudo crontab -e" or something different?

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 9:10 am

DougieLawson wrote:But if you insist add a line to a crontab.

Code: Select all

*/5 * * * * /usr/bin/vcgencmd measure_temp >> /home/pi/temp_log
to be pedantic, this is not answering the OP question :)

you should also have a @reboot entry to "run at boot and then at every 5 minutes". This is not giving a fixed 5 minutes interval between the first two execution

I just wanted to contradict Dougie :)

User avatar
RaTTuS
Posts: 10615
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 9:21 am

log into the user pi
then type
crontab -e
add
*/5 * * * * /usr/bin/vcgencmd measure_temp >> /tmp/temp_log
save and exit
and it will do it every 5 mins from then onwards [including after a reboot]
you do not have to be root to do this
if your /tmp is a ramdisk [90% sure that it will be] then you will not cause excessive ware on your SDcard [though 1 extra write ever 5 mins is not excessive]
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 10:23 am

Or, for that matter:

$ echo '*/5 * * * * /usr/bin/vcgencmd measure_temp >> /tmp/temp_log' | crontab

But, of course, as always, crontab is the wrong tool for this sort of thing.

And running every 5 minutes (in crontab), although not as outright silly as the usual thing we hear ("I want to run this every minute"), is still probably not a good idea. For one thing, it fills up the system logs with stuff that you may have to go and read at some point...

The "login method" is so much better.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
DougieLawson
Posts: 40246
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 10:41 am

Massi wrote:to be pedantic, this is not answering the OP question :)
Try it! It will take the patient's temperature every five minutes from the point when /etc/init.d/cron (in disguise as /etc/rc2.d/S16cron start) runs during boot up.
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 10:45 am

DougieLawson wrote:Try it! It will take the patient's temperature every five minutes from the point when /etc/init.d/cron (in disguise as /etc/rc2.d/S16cron start) runs during boot up.
isn't it doing the /5 on absolute time? it's with reference to start time of cron?

Damn, i need a new try to contradict you :)

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 10:46 am

Joe Schmoe wrote:Or, for that matter:

$ echo '*/5 * * * * /usr/bin/vcgencmd measure_temp >> /tmp/temp_log' | crontab

But, of course, as always, crontab is the wrong tool for this sort of thing.

And running every 5 minutes (in crontab), although not as outright silly as the usual thing we hear ("I want to run this every minute"), is still probably not a good idea. For one thing, it fills up the system logs with stuff that you may have to go and read at some point...

The "login method" is so much better.
For the case where "I want to do 'x' every 'regular time period'" cron is precisely the correct tool. Rolling your own solution would be dumb since you'd have to debug it, and cron has been around for a long time.

Just because you have no idea how to use it doesn't make it a poor choice.

User avatar
DougieLawson
Posts: 40246
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 10:52 am

Massi wrote: isn't it doing the /5 on absolute time? it's with reference to start time of cron?

Damn, i need a new try to contradict you :)
It will run on hh:05, hh:10, hh:15, hh:20, hh:25, hh:30, hh:35, hh:40, hh:45, hh:50, hh:55 and hh:00 each hour. The only odd event may be at 23:59:60 UTC on 30th June 2015.

Does it matter since the task the original poster is trying to do is 100% pointless?
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 11:05 am

Does it matter since the task the original poster is trying to do is 100% pointless?
+1. Great line. Pretty much says it all.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: How to run a command at boot, and then at every 5 minute

Mon Jun 29, 2015 11:07 am

Just because you have no idea how to use it doesn't make it a poor choice.
Actually, it very much does. So, you (non-rhetorical "you") are wrong again.

If someone (i.e., rhetorical "you") has no idea how to use something (a tool), then that tool is indeed a very poor choice for him to use.

Not that this has anything to do, per se, with this thread or with the OP.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Return to “Beginners”