Discussion:
Running something every minute
Add Reply
Michael F. Stemper
2021-04-07 13:27:00 UTC
Reply
Permalink
I have a process that I'd like to run roughly once a minute. There
are two options:

1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
wrapper kicked off by an @reboot entry in my crontab.
2. Have it directly executed every minute by a five-stars entry in
my crontab.

What are the pros and cons of each approach?
--
Michael F. Stemper
Isaiah 10:1-2
Anssi Saari
2021-04-07 20:03:57 UTC
Reply
Permalink
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
Well, if your script dies due to some error condition, then with option
1 it stays dead until you reboot.

On the other hand, if you run it with cron every minute then it runs for
sure. And if there's an error then you get an email once a minute about
it...
gamo
2021-04-08 11:54:59 UTC
Reply
Permalink
Post by Anssi Saari
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
Well, if your script dies due to some error condition, then with option
1 it stays dead until you reboot.
On the other hand, if you run it with cron every minute then it runs for
sure. And if there's an error then you get an email once a minute about
it...
Well in Ubuntu desktop you are not emailed in option 2, but anyway I
would chose the option 1 maybe because it's more transparent and you
could modify it, in example a 'sleep 60' is not exactlly once per minute
because the task takes time and so on...
--
http://gamo.sdf-eu.org/
perl -E 'say "Code could contain bugsh";'
Henry Crun
2021-04-08 12:47:19 UTC
Reply
Permalink
Post by gamo
Post by Anssi Saari
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
Well, if your script dies due to some error condition, then with option
1 it stays dead until you reboot.
On the other hand, if you run it with cron every minute then it runs for
sure. And if there's an error then you get an email once a minute about
it...
Well in Ubuntu desktop you are not emailed in option 2, but anyway I
would chose the option 1 maybe because it's more transparent and you
could modify it, in example a 'sleep 60' is not exactlly once per minute
because the task takes time and so on...
my preference would be to combine the two approaches:
write, compile and link in the language of your choice, using whatever "wait 60" or "sleep 60" or equvalent the language
provides. This will save the program setup 60 times a hour
In cron setup a script to run every 1 or 2 hours to check that your program is still executing, and restart it if
neccesary; you could email on whatever event you choose

(can you see I come from an OS where program initialization takes a toll...?)
--
Mike R.
Home: http://alpha.mike-r.com/
QOTD: http://alpha.mike-r.com/qotd.php
No Micro$oft products were used in the URLs above, or in preparing this message.
Recommended reading: http://www.catb.org/~esr/faqs/smart-questions.html#before
and: http://alpha.mike-r.com/jargon/T/top-post.html
Missile address: N31.7624/E34.9691
Michael F. Stemper
2021-04-08 18:12:44 UTC
Reply
Permalink
Post by Henry Crun
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
write, compile and link in the language of your choice,
It's a bash script, so no compilation or linking is required.
Post by Henry Crun
using whatever
"wait 60" or "sleep 60" or equvalent the language provides.
"sleep 60"
Post by Henry Crun
In cron setup a script to run every 1 or 2 hours to check that your
program is still executing, and restart it if neccesary; you could email
on whatever event you choose
I don't think that would be an option, as I've never configured a mail
server.
--
Michael F. Stemper
Why doesn't anybody care about apathy?
gamo
2021-04-09 00:52:22 UTC
Reply
Permalink
Post by Henry Crun
In cron setup a script to run every 1 or 2 hours to check that your
program is still executing, and restart it if neccesary; you could email
on whatever event you choose
Fully agree!!!

That's a compromise solution between launching a lot of times a 'stupid'
program and that the program takes care of doing a rerun and report
possible problems in the execution or input/output possible problems.
Post by Henry Crun
(can you see I come from an OS where program initialization takes a toll...?)
Yes. And you could have a long beard.

Off topic: I download the hercules emulator but realized that
configuration shows that's not-for-humans software, like
trolling in the devices equivalents that 0009 is /
By the way, I will be pleased if anyone pass a "normal"
hercules.cnf archive and could run the z/Arch emulator
mode.

Cheers.
--
http://gamo.sdf-eu.org/
perl -E 'say "Code could contain bugsh";'
gamo
2021-04-09 07:38:01 UTC
Reply
Permalink
Post by gamo
I will be pleased if anyone pass a "normal"
hercules.cnf archive
No problem. I finally run it and realize that
as an being an emulator, it's only designed to
run mainframe software and it's not compatible
with running local software, IMHO. It's a pitty
yo can type POSIX and something friendly
appairs :-)
--
http://gamo.sdf-eu.org/
perl -E 'say "Code could contain bugsh";'
Jonathan N. Little
2021-04-08 13:52:57 UTC
Reply
Permalink
Post by gamo
Well in Ubuntu desktop you are not emailed in option 2
Only because the email is not defined for the crontab user by default
adding line:

MAILTO="***@email.address"

to your crontab settings, and a local relay server like nullmailer to
send messages to remote mailserver.
--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Michael F. Stemper
2021-04-08 18:08:21 UTC
Reply
Permalink
Post by gamo
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
Well in Ubuntu desktop you are not emailed in option 2, but anyway I
would chose the option 1 maybe because it's more transparent and you
could modify it, in example a 'sleep 60' is not exactlly once per minute
because the task takes time and so on...
Not a problem; as I said, I want to run it roughly once a minute. A
slippage of a second or two per hour isn't a big deal.
--
Michael F. Stemper
Why doesn't anybody care about apathy?
Michael F. Stemper
2021-04-08 18:06:50 UTC
Reply
Permalink
Post by Anssi Saari
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
Well, if your script dies due to some error condition, then with option
1 it stays dead until you reboot.
On the other hand, if you run it with cron every minute then it runs for
sure. And if there's an error then you get an email once a minute about
it...
Fortunately, my system doesn't know my email address.

However, I started running option 2 yesterday and learned that although
I had disabled cron logging to /var/log/syslog, somehow I missed
keeping it from logging to /var/log/auth.log, which gives me two more
messages per minute, making it (auth.log) pretty useless.
--
Michael F. Stemper
Why doesn't anybody care about apathy?
Anssi Saari
2021-04-09 06:35:47 UTC
Reply
Permalink
Post by Michael F. Stemper
However, I started running option 2 yesterday and learned that although
I had disabled cron logging to /var/log/syslog, somehow I missed
keeping it from logging to /var/log/auth.log, which gives me two more
messages per minute, making it (auth.log) pretty useless.
I guess curious minds want to know, what is it that you want to run
every minute?
Michael F. Stemper
2021-04-09 12:45:16 UTC
Reply
Permalink
Post by Anssi Saari
Post by Michael F. Stemper
However, I started running option 2 yesterday and learned that although
I had disabled cron logging to /var/log/syslog, somehow I missed
keeping it from logging to /var/log/auth.log, which gives me two more
messages per minute, making it (auth.log) pretty useless.
I guess curious minds want to know, what is it that you want to run
every minute?
A script that writes CPU temperature to a file. Lines look like


2021-04-09 07:42:51 59.0 3326
2021-04-09 07:43:51 59.0 3332
2021-04-09 07:44:51 59.0 3329
--
Michael F. Stemper
Exodus 22:21
Paul
2021-04-09 18:12:30 UTC
Reply
Permalink
Post by Michael F. Stemper
Post by Anssi Saari
Post by Michael F. Stemper
However, I started running option 2 yesterday and learned that although
I had disabled cron logging to /var/log/syslog, somehow I missed
keeping it from logging to /var/log/auth.log, which gives me two more
messages per minute, making it (auth.log) pretty useless.
I guess curious minds want to know, what is it that you want to run
every minute?
A script that writes CPU temperature to a file. Lines look like
2021-04-09 07:42:51 59.0 3326
2021-04-09 07:43:51 59.0 3332
2021-04-09 07:44:51 59.0 3329
I suppose it would depend on what is still supported.

https://askubuntu.com/questions/41794/how-to-monitor-log-server-hardware-temperatures-load

Paul
Michael F. Stemper
2021-04-09 19:03:07 UTC
Reply
Permalink
Post by Paul
Post by Michael F. Stemper
Post by Anssi Saari
I guess curious minds want to know, what is it that you want to run
every minute?
A script that writes CPU temperature to a file. Lines look like
2021-04-09 07:42:51 59.0 3326
2021-04-09 07:43:51 59.0 3332
2021-04-09 07:44:51 59.0 3329
I suppose it would depend on what is still supported.
https://askubuntu.com/questions/41794/how-to-monitor-log-server-hardware-temperatures-load
My script is a wrapper around the sensors command which that
page references.

If there's some pseudo-file in /proc that has this information,
I'd happily take it directly from there.
--
Michael F. Stemper
Galatians 3:28
Andrei Z.
2021-04-08 12:43:11 UTC
Reply
Permalink
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
Repeat a command every x interval of time in terminal? - Ask Ubuntu
https://askubuntu.com/questions/430382/repeat-a-command-every-x-interval-of-time-in-terminal

How To Repeat A Command Every X Seconds On Linux - Linux Uprising Blog
https://www.linuxuprising.com/2020/12/how-to-repeat-command-every-x-seconds.html
Michael F. Stemper
2021-04-08 18:15:50 UTC
Reply
Permalink
Post by Andrei Z.
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
Repeat a command every x interval of time in terminal? - Ask Ubuntu
https://askubuntu.com/questions/430382/repeat-a-command-every-x-interval-of-time-in-terminal
I don't want it running in a terminal, I want it running in the
background, as is done by cron.
Post by Andrei Z.
How To Repeat A Command Every X Seconds On Linux - Linux Uprising Blog
https://www.linuxuprising.com/2020/12/how-to-repeat-command-every-x-seconds.html
The "watch" option that page suggests isn't appropriate, because I want
it running in the background.

The "sleep" option it suggests is exactly what I gave as my first option
in my original post.
--
Michael F. Stemper
Psalm 94:3-6
Chris Elvidge
2021-04-08 13:39:39 UTC
Reply
Permalink
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
There's another option : systemd-timers
Article about it/them: https://opensource.com/article/20/7/systemd-timers
--
Chris Elvidge
England
Michael F. Stemper
2021-04-08 18:23:37 UTC
Reply
Permalink
Post by Chris Elvidge
Post by Michael F. Stemper
I have a process that I'd like to run roughly once a minute. There
1. Wrap it in a script with a while [ 1 ] and a sleep 60. Have the
2. Have it directly executed every minute by a five-stars entry in
my crontab.
What are the pros and cons of each approach?
There's another option : systemd-timers
Article about it/them: https://opensource.com/article/20/7/systemd-timers
Oh, that's interesting. I never even heard of those before. This
will take some reading. Thanks.
--
Michael F. Stemper
Psalm 94:3-6
Loading...