How to run scripts every 5 seconds?












58















I have a script that needs to be run every five seconds. I know that cron can do tasks by the minute, but is there a way to run something every second?










share|improve this question




















  • 3





    What problem are you trying to solve? Are you sure cron is the right solution?

    – andol
    Aug 4 '10 at 19:11






  • 1





    I know cron isn't the right solution. I was saying it wasn't in the question. Please read. I am trying to make a script run every 5 seconds.

    – myusuf3
    Aug 4 '10 at 19:20






  • 2





    Sorry, guess I got the question slightly wrong. Yet, still wondering if you are trying to solve the right problem.

    – andol
    Aug 4 '10 at 19:25













  • For people coming here looking how to run something every 5 seconds. I strongly recommend instead you look at learning how to program realtime with tools like socket.io as an example.

    – Brandon Bertelsen
    Jul 18 '17 at 19:05











  • Have you discovered the bash sleep command? sleep 5 pauses (perhaps within a loop) for 5 seconds)...?

    – SDsolar
    Apr 23 '18 at 19:03
















58















I have a script that needs to be run every five seconds. I know that cron can do tasks by the minute, but is there a way to run something every second?










share|improve this question




















  • 3





    What problem are you trying to solve? Are you sure cron is the right solution?

    – andol
    Aug 4 '10 at 19:11






  • 1





    I know cron isn't the right solution. I was saying it wasn't in the question. Please read. I am trying to make a script run every 5 seconds.

    – myusuf3
    Aug 4 '10 at 19:20






  • 2





    Sorry, guess I got the question slightly wrong. Yet, still wondering if you are trying to solve the right problem.

    – andol
    Aug 4 '10 at 19:25













  • For people coming here looking how to run something every 5 seconds. I strongly recommend instead you look at learning how to program realtime with tools like socket.io as an example.

    – Brandon Bertelsen
    Jul 18 '17 at 19:05











  • Have you discovered the bash sleep command? sleep 5 pauses (perhaps within a loop) for 5 seconds)...?

    – SDsolar
    Apr 23 '18 at 19:03














58












58








58


15






I have a script that needs to be run every five seconds. I know that cron can do tasks by the minute, but is there a way to run something every second?










share|improve this question
















I have a script that needs to be run every five seconds. I know that cron can do tasks by the minute, but is there a way to run something every second?







scripts cron






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 30 '16 at 18:25









guntbert

9,142133169




9,142133169










asked Aug 4 '10 at 19:03









myusuf3myusuf3

13.2k338099




13.2k338099








  • 3





    What problem are you trying to solve? Are you sure cron is the right solution?

    – andol
    Aug 4 '10 at 19:11






  • 1





    I know cron isn't the right solution. I was saying it wasn't in the question. Please read. I am trying to make a script run every 5 seconds.

    – myusuf3
    Aug 4 '10 at 19:20






  • 2





    Sorry, guess I got the question slightly wrong. Yet, still wondering if you are trying to solve the right problem.

    – andol
    Aug 4 '10 at 19:25













  • For people coming here looking how to run something every 5 seconds. I strongly recommend instead you look at learning how to program realtime with tools like socket.io as an example.

    – Brandon Bertelsen
    Jul 18 '17 at 19:05











  • Have you discovered the bash sleep command? sleep 5 pauses (perhaps within a loop) for 5 seconds)...?

    – SDsolar
    Apr 23 '18 at 19:03














  • 3





    What problem are you trying to solve? Are you sure cron is the right solution?

    – andol
    Aug 4 '10 at 19:11






  • 1





    I know cron isn't the right solution. I was saying it wasn't in the question. Please read. I am trying to make a script run every 5 seconds.

    – myusuf3
    Aug 4 '10 at 19:20






  • 2





    Sorry, guess I got the question slightly wrong. Yet, still wondering if you are trying to solve the right problem.

    – andol
    Aug 4 '10 at 19:25













  • For people coming here looking how to run something every 5 seconds. I strongly recommend instead you look at learning how to program realtime with tools like socket.io as an example.

    – Brandon Bertelsen
    Jul 18 '17 at 19:05











  • Have you discovered the bash sleep command? sleep 5 pauses (perhaps within a loop) for 5 seconds)...?

    – SDsolar
    Apr 23 '18 at 19:03








3




3





What problem are you trying to solve? Are you sure cron is the right solution?

– andol
Aug 4 '10 at 19:11





What problem are you trying to solve? Are you sure cron is the right solution?

– andol
Aug 4 '10 at 19:11




1




1





I know cron isn't the right solution. I was saying it wasn't in the question. Please read. I am trying to make a script run every 5 seconds.

– myusuf3
Aug 4 '10 at 19:20





I know cron isn't the right solution. I was saying it wasn't in the question. Please read. I am trying to make a script run every 5 seconds.

– myusuf3
Aug 4 '10 at 19:20




2




2





Sorry, guess I got the question slightly wrong. Yet, still wondering if you are trying to solve the right problem.

– andol
Aug 4 '10 at 19:25







Sorry, guess I got the question slightly wrong. Yet, still wondering if you are trying to solve the right problem.

– andol
Aug 4 '10 at 19:25















For people coming here looking how to run something every 5 seconds. I strongly recommend instead you look at learning how to program realtime with tools like socket.io as an example.

– Brandon Bertelsen
Jul 18 '17 at 19:05





For people coming here looking how to run something every 5 seconds. I strongly recommend instead you look at learning how to program realtime with tools like socket.io as an example.

– Brandon Bertelsen
Jul 18 '17 at 19:05













Have you discovered the bash sleep command? sleep 5 pauses (perhaps within a loop) for 5 seconds)...?

– SDsolar
Apr 23 '18 at 19:03





Have you discovered the bash sleep command? sleep 5 pauses (perhaps within a loop) for 5 seconds)...?

– SDsolar
Apr 23 '18 at 19:03










8 Answers
8






active

oldest

votes


















60














Cron only allows for a minimum of one minute. What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 5 seconds. That way your task would be run more or less every 5 seconds, depending on how long the task itself takes.



#!/bin/bash

while true; do
# Do something
sleep 5;
done


You can create a my-task.sh file with the contents above and run it with sh my-task.sh. Optionally you can configure it with supervisor as a service so that it would start when the system boots, etc.



It really does sound like you're doing something that you probably shouldn't be doing though. This feels wrong.






share|improve this answer


























  • One can need a a cron running every 5 or even less seconds to be used in PHP based scrapers.

    – Ravish Kumar
    Dec 26 '17 at 11:57



















30














You could have a cron job kick-off a script every minute that starts 12 backgrounded processes thusly:



* * * * * ~/dostuff.sh


dostuff.sh:



(sleep 5 && /path/to/task) &
(sleep 10 && /path/to/task) &
(sleep 15 && /path/to/task) &
(sleep 20 && /path/to/task) &
(sleep 25 && /path/to/task) &
(sleep 30 && /path/to/task) &
(sleep 35 && /path/to/task) &
(sleep 40 && /path/to/task) &
(sleep 45 && /path/to/task) &
(sleep 50 && /path/to/task) &
(sleep 55 && /path/to/task) &
(sleep 60 && /path/to/task) &




My question, though, is What on EARTH could you be doing that needs to run every 5 seconds?






share|improve this answer



















  • 1





    Well, this came in handy to me when I made a script that repeatedly checks the /media directory for a drive I plug in to usb for automatic backups...

    – VF1
    Aug 22 '13 at 2:52






  • 26





    What on EARTH - statistics, garbage collection, file sync, online status, you name it.

    – ruX
    Jul 16 '16 at 23:53






  • 2





    Referencing external API for near-realtime data. Running request every 5 sec is MUCH better than doing it on every pageview.

    – Sergey Kudriavtsev
    Jul 18 '16 at 21:41






  • 1





    What if crontab execute the dostuff.sh file twice? For example at 55th second, the script is executed but didn't finished yet, but the cron calls the script again, what'll happen?

    – TomSawyer
    Sep 14 '16 at 9:16






  • 2





    THIS IS BAD! It potentially runs the script more than once at a time (if it happens to take longer than 5 seconds) which could lead to a race condition in any (even temporary) files accessed. DO NOT DO THIS if doing the same thing twice at the same time could cause a problem! (And that usually will!)

    – Nonny Moose
    Jan 10 '18 at 1:52



















27














Just use a loop:



while true ; do ./your-script & sleep 5; done


This will start your-script as a background job, sleep for 5 seconds, then loop again.
You can use Ctrl-C to abort it, or use any other condition instead of true, e.g. ! test -f /tmp/stop-my-script to only loop while the file /tmp/stop-my-script does not exist.






share|improve this answer


























  • If I include the ampersand, it says bash: syntax error near unexpected token ';', so I took it out. I have bash 4.3.11. My command runs quickly so it's ok if it runs in the foreground.

    – Tyler Collier
    Dec 4 '16 at 4:48






  • 1





    @TylerCollier If you did need ./your-script to run in the background (during the 5-second sleep), you could keep & but drop the ;. As & serves the purpose of separating the commands, it's unnecessary (and apparently not allowed) to have ; after it on the same line. Another way is to write the loop in multiple lines (with a line break after & and, optionally, line breaks after do and before done as well). Since the ; after & appears to be a typo, I've removed it. blueyed: Please feel free to put the ; back if you really want it; if so, I suggest also adding an explanation.

    – Eliah Kagan
    Dec 30 '16 at 20:40











  • @EliahKagan FWIW, it works on Zsh (no syntax error), but it is not really necessary. Thanks for the edit!

    – blueyed
    Jan 12 '17 at 11:43



















10














You could use the GNU package mcron, a "Vixie cron" alternative.



http://www.gnu.org/software/mcron/manual/mcron.html#Top



"Can easily allow for finer time-points to be specified, i.e. seconds. In principle this could be extended to microseconds, but this is not implemented."






share|improve this answer
























  • That is exactly what I was looking for. Thank you!

    – SDsolar
    Jun 5 '17 at 9:44











  • Please post this as an answer to my question here: askubuntu.com/questions/922216/… so I can accept your answer.

    – SDsolar
    Jun 5 '17 at 9:47











  • stackoverflow.com/questions/44470965/…

    – SDsolar
    Jun 15 '17 at 2:37











  • askubuntu.com/questions/832072/…

    – SDsolar
    Jun 15 '17 at 2:38











  • mcron requires sendmail to be installed and activated by default. how to disable it?

    – ihsan
    Jul 11 '17 at 1:04



















2














Minimum configuration in cron is minutes, you can't set it for 5 seconds. You could use Quartz which does allow seconds. http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html






share|improve this answer


























  • It seems Quartz is not open source. Is this correct?

    – txwikinger
    Aug 4 '10 at 19:24











  • It has an open source version. It doesn't have a page but just go to the download page. You don't have to fill out the form just click take me to the download.

    – Cody Harlow
    Aug 4 '10 at 19:27













  • seems to be open source as of at least 2018. github.com/quartz-scheduler/quartz

    – dogmatic69
    Feb 18 '18 at 16:39





















2














Use cacti to monitor router and switch,but Cron only allows for a minimum of one minute,so
if one port/device down,there is no warning until two minutes past.






share|improve this answer



















  • 1





    I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.)

    – David Foerster
    Feb 23 '16 at 8:51



















1














I've done this sort of thing very successfully (and the end result rans weeks at a time, till the machine is rebooted). As for what I was doing right now, updating information and putting it into cache - updating every 10 seconds.



#!/bin/sh

SLEEP=5

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# echo and restart...
exec $0


The 'exec $0' restarts the script, but replacing the running script. It can be initially started with a crontab '@reboot' line.






share|improve this answer



















  • 7





    Why not use a while loop instead of repeatedly restarting the script?

    – David Z
    Aug 4 '10 at 19:56



















1














You could use a SystemD timer unit, which will trigger a service - that you'd set up to do what you want - every 5 seconds.



Suppose your service unit is called mystuff.service and is installed in /etc/systemd/system (check out SystemD user services if you want to replace a user's crontab), then you can write a timer unit to run the service at boot time and then every 5 seconds, like this:



/etc/systemd/system/mystuff.timer



[Unit]
Description=my stuff's schedule
[Timer]
OnBootSec=5
OnUnitActiveSec=5
[Install]
WantedBy=timers.target


Then reload the systemd configuration, enable the timer unit and start it.






share|improve this answer





















  • 1





    It's the best solution, the only downside is that cron is a lot easier to overview and configure. SystemD is a pain and it starts with it's directory structure. Still the best for a 5 second interval

    – John
    Dec 17 '18 at 17:32











  • Wouldn't the above snippet go in /etc/systemd/system/mystuff.timer instead of mystuff.service?

    – Brooks
    7 hours ago











  • @Brooks: yes, my bad - bad copy & paste on my side. Fixed.

    – Guss
    7 hours ago











  • Thanks...glad to know I'm not crazy while I'm learning systemd :)

    – Brooks
    7 hours ago










protected by Community Jun 7 '18 at 18:57



Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



Would you like to answer one of these unanswered questions instead?














8 Answers
8






active

oldest

votes








8 Answers
8






active

oldest

votes









active

oldest

votes






active

oldest

votes









60














Cron only allows for a minimum of one minute. What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 5 seconds. That way your task would be run more or less every 5 seconds, depending on how long the task itself takes.



#!/bin/bash

while true; do
# Do something
sleep 5;
done


You can create a my-task.sh file with the contents above and run it with sh my-task.sh. Optionally you can configure it with supervisor as a service so that it would start when the system boots, etc.



It really does sound like you're doing something that you probably shouldn't be doing though. This feels wrong.






share|improve this answer


























  • One can need a a cron running every 5 or even less seconds to be used in PHP based scrapers.

    – Ravish Kumar
    Dec 26 '17 at 11:57
















60














Cron only allows for a minimum of one minute. What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 5 seconds. That way your task would be run more or less every 5 seconds, depending on how long the task itself takes.



#!/bin/bash

while true; do
# Do something
sleep 5;
done


You can create a my-task.sh file with the contents above and run it with sh my-task.sh. Optionally you can configure it with supervisor as a service so that it would start when the system boots, etc.



It really does sound like you're doing something that you probably shouldn't be doing though. This feels wrong.






share|improve this answer


























  • One can need a a cron running every 5 or even less seconds to be used in PHP based scrapers.

    – Ravish Kumar
    Dec 26 '17 at 11:57














60












60








60







Cron only allows for a minimum of one minute. What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 5 seconds. That way your task would be run more or less every 5 seconds, depending on how long the task itself takes.



#!/bin/bash

while true; do
# Do something
sleep 5;
done


You can create a my-task.sh file with the contents above and run it with sh my-task.sh. Optionally you can configure it with supervisor as a service so that it would start when the system boots, etc.



It really does sound like you're doing something that you probably shouldn't be doing though. This feels wrong.






share|improve this answer















Cron only allows for a minimum of one minute. What you could do is write a shell script with an infinite loop that runs your task, and then sleeps for 5 seconds. That way your task would be run more or less every 5 seconds, depending on how long the task itself takes.



#!/bin/bash

while true; do
# Do something
sleep 5;
done


You can create a my-task.sh file with the contents above and run it with sh my-task.sh. Optionally you can configure it with supervisor as a service so that it would start when the system boots, etc.



It really does sound like you're doing something that you probably shouldn't be doing though. This feels wrong.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 19 '18 at 10:48









Jigar Mehta

1054




1054










answered Aug 4 '10 at 19:07









Tommy BrunnTommy Brunn

6,58852737




6,58852737













  • One can need a a cron running every 5 or even less seconds to be used in PHP based scrapers.

    – Ravish Kumar
    Dec 26 '17 at 11:57



















  • One can need a a cron running every 5 or even less seconds to be used in PHP based scrapers.

    – Ravish Kumar
    Dec 26 '17 at 11:57

















One can need a a cron running every 5 or even less seconds to be used in PHP based scrapers.

– Ravish Kumar
Dec 26 '17 at 11:57





One can need a a cron running every 5 or even less seconds to be used in PHP based scrapers.

– Ravish Kumar
Dec 26 '17 at 11:57













30














You could have a cron job kick-off a script every minute that starts 12 backgrounded processes thusly:



* * * * * ~/dostuff.sh


dostuff.sh:



(sleep 5 && /path/to/task) &
(sleep 10 && /path/to/task) &
(sleep 15 && /path/to/task) &
(sleep 20 && /path/to/task) &
(sleep 25 && /path/to/task) &
(sleep 30 && /path/to/task) &
(sleep 35 && /path/to/task) &
(sleep 40 && /path/to/task) &
(sleep 45 && /path/to/task) &
(sleep 50 && /path/to/task) &
(sleep 55 && /path/to/task) &
(sleep 60 && /path/to/task) &




My question, though, is What on EARTH could you be doing that needs to run every 5 seconds?






share|improve this answer



















  • 1





    Well, this came in handy to me when I made a script that repeatedly checks the /media directory for a drive I plug in to usb for automatic backups...

    – VF1
    Aug 22 '13 at 2:52






  • 26





    What on EARTH - statistics, garbage collection, file sync, online status, you name it.

    – ruX
    Jul 16 '16 at 23:53






  • 2





    Referencing external API for near-realtime data. Running request every 5 sec is MUCH better than doing it on every pageview.

    – Sergey Kudriavtsev
    Jul 18 '16 at 21:41






  • 1





    What if crontab execute the dostuff.sh file twice? For example at 55th second, the script is executed but didn't finished yet, but the cron calls the script again, what'll happen?

    – TomSawyer
    Sep 14 '16 at 9:16






  • 2





    THIS IS BAD! It potentially runs the script more than once at a time (if it happens to take longer than 5 seconds) which could lead to a race condition in any (even temporary) files accessed. DO NOT DO THIS if doing the same thing twice at the same time could cause a problem! (And that usually will!)

    – Nonny Moose
    Jan 10 '18 at 1:52
















30














You could have a cron job kick-off a script every minute that starts 12 backgrounded processes thusly:



* * * * * ~/dostuff.sh


dostuff.sh:



(sleep 5 && /path/to/task) &
(sleep 10 && /path/to/task) &
(sleep 15 && /path/to/task) &
(sleep 20 && /path/to/task) &
(sleep 25 && /path/to/task) &
(sleep 30 && /path/to/task) &
(sleep 35 && /path/to/task) &
(sleep 40 && /path/to/task) &
(sleep 45 && /path/to/task) &
(sleep 50 && /path/to/task) &
(sleep 55 && /path/to/task) &
(sleep 60 && /path/to/task) &




My question, though, is What on EARTH could you be doing that needs to run every 5 seconds?






share|improve this answer



















  • 1





    Well, this came in handy to me when I made a script that repeatedly checks the /media directory for a drive I plug in to usb for automatic backups...

    – VF1
    Aug 22 '13 at 2:52






  • 26





    What on EARTH - statistics, garbage collection, file sync, online status, you name it.

    – ruX
    Jul 16 '16 at 23:53






  • 2





    Referencing external API for near-realtime data. Running request every 5 sec is MUCH better than doing it on every pageview.

    – Sergey Kudriavtsev
    Jul 18 '16 at 21:41






  • 1





    What if crontab execute the dostuff.sh file twice? For example at 55th second, the script is executed but didn't finished yet, but the cron calls the script again, what'll happen?

    – TomSawyer
    Sep 14 '16 at 9:16






  • 2





    THIS IS BAD! It potentially runs the script more than once at a time (if it happens to take longer than 5 seconds) which could lead to a race condition in any (even temporary) files accessed. DO NOT DO THIS if doing the same thing twice at the same time could cause a problem! (And that usually will!)

    – Nonny Moose
    Jan 10 '18 at 1:52














30












30








30







You could have a cron job kick-off a script every minute that starts 12 backgrounded processes thusly:



* * * * * ~/dostuff.sh


dostuff.sh:



(sleep 5 && /path/to/task) &
(sleep 10 && /path/to/task) &
(sleep 15 && /path/to/task) &
(sleep 20 && /path/to/task) &
(sleep 25 && /path/to/task) &
(sleep 30 && /path/to/task) &
(sleep 35 && /path/to/task) &
(sleep 40 && /path/to/task) &
(sleep 45 && /path/to/task) &
(sleep 50 && /path/to/task) &
(sleep 55 && /path/to/task) &
(sleep 60 && /path/to/task) &




My question, though, is What on EARTH could you be doing that needs to run every 5 seconds?






share|improve this answer













You could have a cron job kick-off a script every minute that starts 12 backgrounded processes thusly:



* * * * * ~/dostuff.sh


dostuff.sh:



(sleep 5 && /path/to/task) &
(sleep 10 && /path/to/task) &
(sleep 15 && /path/to/task) &
(sleep 20 && /path/to/task) &
(sleep 25 && /path/to/task) &
(sleep 30 && /path/to/task) &
(sleep 35 && /path/to/task) &
(sleep 40 && /path/to/task) &
(sleep 45 && /path/to/task) &
(sleep 50 && /path/to/task) &
(sleep 55 && /path/to/task) &
(sleep 60 && /path/to/task) &




My question, though, is What on EARTH could you be doing that needs to run every 5 seconds?







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 4 '10 at 19:24







warren















  • 1





    Well, this came in handy to me when I made a script that repeatedly checks the /media directory for a drive I plug in to usb for automatic backups...

    – VF1
    Aug 22 '13 at 2:52






  • 26





    What on EARTH - statistics, garbage collection, file sync, online status, you name it.

    – ruX
    Jul 16 '16 at 23:53






  • 2





    Referencing external API for near-realtime data. Running request every 5 sec is MUCH better than doing it on every pageview.

    – Sergey Kudriavtsev
    Jul 18 '16 at 21:41






  • 1





    What if crontab execute the dostuff.sh file twice? For example at 55th second, the script is executed but didn't finished yet, but the cron calls the script again, what'll happen?

    – TomSawyer
    Sep 14 '16 at 9:16






  • 2





    THIS IS BAD! It potentially runs the script more than once at a time (if it happens to take longer than 5 seconds) which could lead to a race condition in any (even temporary) files accessed. DO NOT DO THIS if doing the same thing twice at the same time could cause a problem! (And that usually will!)

    – Nonny Moose
    Jan 10 '18 at 1:52














  • 1





    Well, this came in handy to me when I made a script that repeatedly checks the /media directory for a drive I plug in to usb for automatic backups...

    – VF1
    Aug 22 '13 at 2:52






  • 26





    What on EARTH - statistics, garbage collection, file sync, online status, you name it.

    – ruX
    Jul 16 '16 at 23:53






  • 2





    Referencing external API for near-realtime data. Running request every 5 sec is MUCH better than doing it on every pageview.

    – Sergey Kudriavtsev
    Jul 18 '16 at 21:41






  • 1





    What if crontab execute the dostuff.sh file twice? For example at 55th second, the script is executed but didn't finished yet, but the cron calls the script again, what'll happen?

    – TomSawyer
    Sep 14 '16 at 9:16






  • 2





    THIS IS BAD! It potentially runs the script more than once at a time (if it happens to take longer than 5 seconds) which could lead to a race condition in any (even temporary) files accessed. DO NOT DO THIS if doing the same thing twice at the same time could cause a problem! (And that usually will!)

    – Nonny Moose
    Jan 10 '18 at 1:52








1




1





Well, this came in handy to me when I made a script that repeatedly checks the /media directory for a drive I plug in to usb for automatic backups...

– VF1
Aug 22 '13 at 2:52





Well, this came in handy to me when I made a script that repeatedly checks the /media directory for a drive I plug in to usb for automatic backups...

– VF1
Aug 22 '13 at 2:52




26




26





What on EARTH - statistics, garbage collection, file sync, online status, you name it.

– ruX
Jul 16 '16 at 23:53





What on EARTH - statistics, garbage collection, file sync, online status, you name it.

– ruX
Jul 16 '16 at 23:53




2




2





Referencing external API for near-realtime data. Running request every 5 sec is MUCH better than doing it on every pageview.

– Sergey Kudriavtsev
Jul 18 '16 at 21:41





Referencing external API for near-realtime data. Running request every 5 sec is MUCH better than doing it on every pageview.

– Sergey Kudriavtsev
Jul 18 '16 at 21:41




1




1





What if crontab execute the dostuff.sh file twice? For example at 55th second, the script is executed but didn't finished yet, but the cron calls the script again, what'll happen?

– TomSawyer
Sep 14 '16 at 9:16





What if crontab execute the dostuff.sh file twice? For example at 55th second, the script is executed but didn't finished yet, but the cron calls the script again, what'll happen?

– TomSawyer
Sep 14 '16 at 9:16




2




2





THIS IS BAD! It potentially runs the script more than once at a time (if it happens to take longer than 5 seconds) which could lead to a race condition in any (even temporary) files accessed. DO NOT DO THIS if doing the same thing twice at the same time could cause a problem! (And that usually will!)

– Nonny Moose
Jan 10 '18 at 1:52





THIS IS BAD! It potentially runs the script more than once at a time (if it happens to take longer than 5 seconds) which could lead to a race condition in any (even temporary) files accessed. DO NOT DO THIS if doing the same thing twice at the same time could cause a problem! (And that usually will!)

– Nonny Moose
Jan 10 '18 at 1:52











27














Just use a loop:



while true ; do ./your-script & sleep 5; done


This will start your-script as a background job, sleep for 5 seconds, then loop again.
You can use Ctrl-C to abort it, or use any other condition instead of true, e.g. ! test -f /tmp/stop-my-script to only loop while the file /tmp/stop-my-script does not exist.






share|improve this answer


























  • If I include the ampersand, it says bash: syntax error near unexpected token ';', so I took it out. I have bash 4.3.11. My command runs quickly so it's ok if it runs in the foreground.

    – Tyler Collier
    Dec 4 '16 at 4:48






  • 1





    @TylerCollier If you did need ./your-script to run in the background (during the 5-second sleep), you could keep & but drop the ;. As & serves the purpose of separating the commands, it's unnecessary (and apparently not allowed) to have ; after it on the same line. Another way is to write the loop in multiple lines (with a line break after & and, optionally, line breaks after do and before done as well). Since the ; after & appears to be a typo, I've removed it. blueyed: Please feel free to put the ; back if you really want it; if so, I suggest also adding an explanation.

    – Eliah Kagan
    Dec 30 '16 at 20:40











  • @EliahKagan FWIW, it works on Zsh (no syntax error), but it is not really necessary. Thanks for the edit!

    – blueyed
    Jan 12 '17 at 11:43
















27














Just use a loop:



while true ; do ./your-script & sleep 5; done


This will start your-script as a background job, sleep for 5 seconds, then loop again.
You can use Ctrl-C to abort it, or use any other condition instead of true, e.g. ! test -f /tmp/stop-my-script to only loop while the file /tmp/stop-my-script does not exist.






share|improve this answer


























  • If I include the ampersand, it says bash: syntax error near unexpected token ';', so I took it out. I have bash 4.3.11. My command runs quickly so it's ok if it runs in the foreground.

    – Tyler Collier
    Dec 4 '16 at 4:48






  • 1





    @TylerCollier If you did need ./your-script to run in the background (during the 5-second sleep), you could keep & but drop the ;. As & serves the purpose of separating the commands, it's unnecessary (and apparently not allowed) to have ; after it on the same line. Another way is to write the loop in multiple lines (with a line break after & and, optionally, line breaks after do and before done as well). Since the ; after & appears to be a typo, I've removed it. blueyed: Please feel free to put the ; back if you really want it; if so, I suggest also adding an explanation.

    – Eliah Kagan
    Dec 30 '16 at 20:40











  • @EliahKagan FWIW, it works on Zsh (no syntax error), but it is not really necessary. Thanks for the edit!

    – blueyed
    Jan 12 '17 at 11:43














27












27








27







Just use a loop:



while true ; do ./your-script & sleep 5; done


This will start your-script as a background job, sleep for 5 seconds, then loop again.
You can use Ctrl-C to abort it, or use any other condition instead of true, e.g. ! test -f /tmp/stop-my-script to only loop while the file /tmp/stop-my-script does not exist.






share|improve this answer















Just use a loop:



while true ; do ./your-script & sleep 5; done


This will start your-script as a background job, sleep for 5 seconds, then loop again.
You can use Ctrl-C to abort it, or use any other condition instead of true, e.g. ! test -f /tmp/stop-my-script to only loop while the file /tmp/stop-my-script does not exist.







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 30 '16 at 20:40









Eliah Kagan

81.7k21227364




81.7k21227364










answered Aug 4 '10 at 20:51









blueyedblueyed

6,17922231




6,17922231













  • If I include the ampersand, it says bash: syntax error near unexpected token ';', so I took it out. I have bash 4.3.11. My command runs quickly so it's ok if it runs in the foreground.

    – Tyler Collier
    Dec 4 '16 at 4:48






  • 1





    @TylerCollier If you did need ./your-script to run in the background (during the 5-second sleep), you could keep & but drop the ;. As & serves the purpose of separating the commands, it's unnecessary (and apparently not allowed) to have ; after it on the same line. Another way is to write the loop in multiple lines (with a line break after & and, optionally, line breaks after do and before done as well). Since the ; after & appears to be a typo, I've removed it. blueyed: Please feel free to put the ; back if you really want it; if so, I suggest also adding an explanation.

    – Eliah Kagan
    Dec 30 '16 at 20:40











  • @EliahKagan FWIW, it works on Zsh (no syntax error), but it is not really necessary. Thanks for the edit!

    – blueyed
    Jan 12 '17 at 11:43



















  • If I include the ampersand, it says bash: syntax error near unexpected token ';', so I took it out. I have bash 4.3.11. My command runs quickly so it's ok if it runs in the foreground.

    – Tyler Collier
    Dec 4 '16 at 4:48






  • 1





    @TylerCollier If you did need ./your-script to run in the background (during the 5-second sleep), you could keep & but drop the ;. As & serves the purpose of separating the commands, it's unnecessary (and apparently not allowed) to have ; after it on the same line. Another way is to write the loop in multiple lines (with a line break after & and, optionally, line breaks after do and before done as well). Since the ; after & appears to be a typo, I've removed it. blueyed: Please feel free to put the ; back if you really want it; if so, I suggest also adding an explanation.

    – Eliah Kagan
    Dec 30 '16 at 20:40











  • @EliahKagan FWIW, it works on Zsh (no syntax error), but it is not really necessary. Thanks for the edit!

    – blueyed
    Jan 12 '17 at 11:43

















If I include the ampersand, it says bash: syntax error near unexpected token ';', so I took it out. I have bash 4.3.11. My command runs quickly so it's ok if it runs in the foreground.

– Tyler Collier
Dec 4 '16 at 4:48





If I include the ampersand, it says bash: syntax error near unexpected token ';', so I took it out. I have bash 4.3.11. My command runs quickly so it's ok if it runs in the foreground.

– Tyler Collier
Dec 4 '16 at 4:48




1




1





@TylerCollier If you did need ./your-script to run in the background (during the 5-second sleep), you could keep & but drop the ;. As & serves the purpose of separating the commands, it's unnecessary (and apparently not allowed) to have ; after it on the same line. Another way is to write the loop in multiple lines (with a line break after & and, optionally, line breaks after do and before done as well). Since the ; after & appears to be a typo, I've removed it. blueyed: Please feel free to put the ; back if you really want it; if so, I suggest also adding an explanation.

– Eliah Kagan
Dec 30 '16 at 20:40





@TylerCollier If you did need ./your-script to run in the background (during the 5-second sleep), you could keep & but drop the ;. As & serves the purpose of separating the commands, it's unnecessary (and apparently not allowed) to have ; after it on the same line. Another way is to write the loop in multiple lines (with a line break after & and, optionally, line breaks after do and before done as well). Since the ; after & appears to be a typo, I've removed it. blueyed: Please feel free to put the ; back if you really want it; if so, I suggest also adding an explanation.

– Eliah Kagan
Dec 30 '16 at 20:40













@EliahKagan FWIW, it works on Zsh (no syntax error), but it is not really necessary. Thanks for the edit!

– blueyed
Jan 12 '17 at 11:43





@EliahKagan FWIW, it works on Zsh (no syntax error), but it is not really necessary. Thanks for the edit!

– blueyed
Jan 12 '17 at 11:43











10














You could use the GNU package mcron, a "Vixie cron" alternative.



http://www.gnu.org/software/mcron/manual/mcron.html#Top



"Can easily allow for finer time-points to be specified, i.e. seconds. In principle this could be extended to microseconds, but this is not implemented."






share|improve this answer
























  • That is exactly what I was looking for. Thank you!

    – SDsolar
    Jun 5 '17 at 9:44











  • Please post this as an answer to my question here: askubuntu.com/questions/922216/… so I can accept your answer.

    – SDsolar
    Jun 5 '17 at 9:47











  • stackoverflow.com/questions/44470965/…

    – SDsolar
    Jun 15 '17 at 2:37











  • askubuntu.com/questions/832072/…

    – SDsolar
    Jun 15 '17 at 2:38











  • mcron requires sendmail to be installed and activated by default. how to disable it?

    – ihsan
    Jul 11 '17 at 1:04
















10














You could use the GNU package mcron, a "Vixie cron" alternative.



http://www.gnu.org/software/mcron/manual/mcron.html#Top



"Can easily allow for finer time-points to be specified, i.e. seconds. In principle this could be extended to microseconds, but this is not implemented."






share|improve this answer
























  • That is exactly what I was looking for. Thank you!

    – SDsolar
    Jun 5 '17 at 9:44











  • Please post this as an answer to my question here: askubuntu.com/questions/922216/… so I can accept your answer.

    – SDsolar
    Jun 5 '17 at 9:47











  • stackoverflow.com/questions/44470965/…

    – SDsolar
    Jun 15 '17 at 2:37











  • askubuntu.com/questions/832072/…

    – SDsolar
    Jun 15 '17 at 2:38











  • mcron requires sendmail to be installed and activated by default. how to disable it?

    – ihsan
    Jul 11 '17 at 1:04














10












10








10







You could use the GNU package mcron, a "Vixie cron" alternative.



http://www.gnu.org/software/mcron/manual/mcron.html#Top



"Can easily allow for finer time-points to be specified, i.e. seconds. In principle this could be extended to microseconds, but this is not implemented."






share|improve this answer













You could use the GNU package mcron, a "Vixie cron" alternative.



http://www.gnu.org/software/mcron/manual/mcron.html#Top



"Can easily allow for finer time-points to be specified, i.e. seconds. In principle this could be extended to microseconds, but this is not implemented."







share|improve this answer












share|improve this answer



share|improve this answer










answered May 13 '14 at 15:24









DavidDavid

163210




163210













  • That is exactly what I was looking for. Thank you!

    – SDsolar
    Jun 5 '17 at 9:44











  • Please post this as an answer to my question here: askubuntu.com/questions/922216/… so I can accept your answer.

    – SDsolar
    Jun 5 '17 at 9:47











  • stackoverflow.com/questions/44470965/…

    – SDsolar
    Jun 15 '17 at 2:37











  • askubuntu.com/questions/832072/…

    – SDsolar
    Jun 15 '17 at 2:38











  • mcron requires sendmail to be installed and activated by default. how to disable it?

    – ihsan
    Jul 11 '17 at 1:04



















  • That is exactly what I was looking for. Thank you!

    – SDsolar
    Jun 5 '17 at 9:44











  • Please post this as an answer to my question here: askubuntu.com/questions/922216/… so I can accept your answer.

    – SDsolar
    Jun 5 '17 at 9:47











  • stackoverflow.com/questions/44470965/…

    – SDsolar
    Jun 15 '17 at 2:37











  • askubuntu.com/questions/832072/…

    – SDsolar
    Jun 15 '17 at 2:38











  • mcron requires sendmail to be installed and activated by default. how to disable it?

    – ihsan
    Jul 11 '17 at 1:04

















That is exactly what I was looking for. Thank you!

– SDsolar
Jun 5 '17 at 9:44





That is exactly what I was looking for. Thank you!

– SDsolar
Jun 5 '17 at 9:44













Please post this as an answer to my question here: askubuntu.com/questions/922216/… so I can accept your answer.

– SDsolar
Jun 5 '17 at 9:47





Please post this as an answer to my question here: askubuntu.com/questions/922216/… so I can accept your answer.

– SDsolar
Jun 5 '17 at 9:47













stackoverflow.com/questions/44470965/…

– SDsolar
Jun 15 '17 at 2:37





stackoverflow.com/questions/44470965/…

– SDsolar
Jun 15 '17 at 2:37













askubuntu.com/questions/832072/…

– SDsolar
Jun 15 '17 at 2:38





askubuntu.com/questions/832072/…

– SDsolar
Jun 15 '17 at 2:38













mcron requires sendmail to be installed and activated by default. how to disable it?

– ihsan
Jul 11 '17 at 1:04





mcron requires sendmail to be installed and activated by default. how to disable it?

– ihsan
Jul 11 '17 at 1:04











2














Minimum configuration in cron is minutes, you can't set it for 5 seconds. You could use Quartz which does allow seconds. http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html






share|improve this answer


























  • It seems Quartz is not open source. Is this correct?

    – txwikinger
    Aug 4 '10 at 19:24











  • It has an open source version. It doesn't have a page but just go to the download page. You don't have to fill out the form just click take me to the download.

    – Cody Harlow
    Aug 4 '10 at 19:27













  • seems to be open source as of at least 2018. github.com/quartz-scheduler/quartz

    – dogmatic69
    Feb 18 '18 at 16:39


















2














Minimum configuration in cron is minutes, you can't set it for 5 seconds. You could use Quartz which does allow seconds. http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html






share|improve this answer


























  • It seems Quartz is not open source. Is this correct?

    – txwikinger
    Aug 4 '10 at 19:24











  • It has an open source version. It doesn't have a page but just go to the download page. You don't have to fill out the form just click take me to the download.

    – Cody Harlow
    Aug 4 '10 at 19:27













  • seems to be open source as of at least 2018. github.com/quartz-scheduler/quartz

    – dogmatic69
    Feb 18 '18 at 16:39
















2












2








2







Minimum configuration in cron is minutes, you can't set it for 5 seconds. You could use Quartz which does allow seconds. http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html






share|improve this answer















Minimum configuration in cron is minutes, you can't set it for 5 seconds. You could use Quartz which does allow seconds. http://www.quartz-scheduler.org/docs/tutorials/crontrigger.html







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 4 '10 at 19:13

























answered Aug 4 '10 at 19:07









Cody HarlowCody Harlow

95911218




95911218













  • It seems Quartz is not open source. Is this correct?

    – txwikinger
    Aug 4 '10 at 19:24











  • It has an open source version. It doesn't have a page but just go to the download page. You don't have to fill out the form just click take me to the download.

    – Cody Harlow
    Aug 4 '10 at 19:27













  • seems to be open source as of at least 2018. github.com/quartz-scheduler/quartz

    – dogmatic69
    Feb 18 '18 at 16:39





















  • It seems Quartz is not open source. Is this correct?

    – txwikinger
    Aug 4 '10 at 19:24











  • It has an open source version. It doesn't have a page but just go to the download page. You don't have to fill out the form just click take me to the download.

    – Cody Harlow
    Aug 4 '10 at 19:27













  • seems to be open source as of at least 2018. github.com/quartz-scheduler/quartz

    – dogmatic69
    Feb 18 '18 at 16:39



















It seems Quartz is not open source. Is this correct?

– txwikinger
Aug 4 '10 at 19:24





It seems Quartz is not open source. Is this correct?

– txwikinger
Aug 4 '10 at 19:24













It has an open source version. It doesn't have a page but just go to the download page. You don't have to fill out the form just click take me to the download.

– Cody Harlow
Aug 4 '10 at 19:27







It has an open source version. It doesn't have a page but just go to the download page. You don't have to fill out the form just click take me to the download.

– Cody Harlow
Aug 4 '10 at 19:27















seems to be open source as of at least 2018. github.com/quartz-scheduler/quartz

– dogmatic69
Feb 18 '18 at 16:39







seems to be open source as of at least 2018. github.com/quartz-scheduler/quartz

– dogmatic69
Feb 18 '18 at 16:39













2














Use cacti to monitor router and switch,but Cron only allows for a minimum of one minute,so
if one port/device down,there is no warning until two minutes past.






share|improve this answer



















  • 1





    I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.)

    – David Foerster
    Feb 23 '16 at 8:51
















2














Use cacti to monitor router and switch,but Cron only allows for a minimum of one minute,so
if one port/device down,there is no warning until two minutes past.






share|improve this answer



















  • 1





    I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.)

    – David Foerster
    Feb 23 '16 at 8:51














2












2








2







Use cacti to monitor router and switch,but Cron only allows for a minimum of one minute,so
if one port/device down,there is no warning until two minutes past.






share|improve this answer













Use cacti to monitor router and switch,but Cron only allows for a minimum of one minute,so
if one port/device down,there is no warning until two minutes past.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '12 at 2:25









qtttyqttty

291




291








  • 1





    I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.)

    – David Foerster
    Feb 23 '16 at 8:51














  • 1





    I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.)

    – David Foerster
    Feb 23 '16 at 8:51








1




1





I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.)

– David Foerster
Feb 23 '16 at 8:51





I recommend editing this answer to expand it with specific details about how to do this. (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.)

– David Foerster
Feb 23 '16 at 8:51











1














I've done this sort of thing very successfully (and the end result rans weeks at a time, till the machine is rebooted). As for what I was doing right now, updating information and putting it into cache - updating every 10 seconds.



#!/bin/sh

SLEEP=5

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# echo and restart...
exec $0


The 'exec $0' restarts the script, but replacing the running script. It can be initially started with a crontab '@reboot' line.






share|improve this answer



















  • 7





    Why not use a while loop instead of repeatedly restarting the script?

    – David Z
    Aug 4 '10 at 19:56
















1














I've done this sort of thing very successfully (and the end result rans weeks at a time, till the machine is rebooted). As for what I was doing right now, updating information and putting it into cache - updating every 10 seconds.



#!/bin/sh

SLEEP=5

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# echo and restart...
exec $0


The 'exec $0' restarts the script, but replacing the running script. It can be initially started with a crontab '@reboot' line.






share|improve this answer



















  • 7





    Why not use a while loop instead of repeatedly restarting the script?

    – David Z
    Aug 4 '10 at 19:56














1












1








1







I've done this sort of thing very successfully (and the end result rans weeks at a time, till the machine is rebooted). As for what I was doing right now, updating information and putting it into cache - updating every 10 seconds.



#!/bin/sh

SLEEP=5

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# echo and restart...
exec $0


The 'exec $0' restarts the script, but replacing the running script. It can be initially started with a crontab '@reboot' line.






share|improve this answer













I've done this sort of thing very successfully (and the end result rans weeks at a time, till the machine is rebooted). As for what I was doing right now, updating information and putting it into cache - updating every 10 seconds.



#!/bin/sh

SLEEP=5

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# do stuff
sleep $SLEEP

# echo and restart...
exec $0


The 'exec $0' restarts the script, but replacing the running script. It can be initially started with a crontab '@reboot' line.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 4 '10 at 19:28









Alister BulmanAlister Bulman

1194




1194








  • 7





    Why not use a while loop instead of repeatedly restarting the script?

    – David Z
    Aug 4 '10 at 19:56














  • 7





    Why not use a while loop instead of repeatedly restarting the script?

    – David Z
    Aug 4 '10 at 19:56








7




7





Why not use a while loop instead of repeatedly restarting the script?

– David Z
Aug 4 '10 at 19:56





Why not use a while loop instead of repeatedly restarting the script?

– David Z
Aug 4 '10 at 19:56











1














You could use a SystemD timer unit, which will trigger a service - that you'd set up to do what you want - every 5 seconds.



Suppose your service unit is called mystuff.service and is installed in /etc/systemd/system (check out SystemD user services if you want to replace a user's crontab), then you can write a timer unit to run the service at boot time and then every 5 seconds, like this:



/etc/systemd/system/mystuff.timer



[Unit]
Description=my stuff's schedule
[Timer]
OnBootSec=5
OnUnitActiveSec=5
[Install]
WantedBy=timers.target


Then reload the systemd configuration, enable the timer unit and start it.






share|improve this answer





















  • 1





    It's the best solution, the only downside is that cron is a lot easier to overview and configure. SystemD is a pain and it starts with it's directory structure. Still the best for a 5 second interval

    – John
    Dec 17 '18 at 17:32











  • Wouldn't the above snippet go in /etc/systemd/system/mystuff.timer instead of mystuff.service?

    – Brooks
    7 hours ago











  • @Brooks: yes, my bad - bad copy & paste on my side. Fixed.

    – Guss
    7 hours ago











  • Thanks...glad to know I'm not crazy while I'm learning systemd :)

    – Brooks
    7 hours ago
















1














You could use a SystemD timer unit, which will trigger a service - that you'd set up to do what you want - every 5 seconds.



Suppose your service unit is called mystuff.service and is installed in /etc/systemd/system (check out SystemD user services if you want to replace a user's crontab), then you can write a timer unit to run the service at boot time and then every 5 seconds, like this:



/etc/systemd/system/mystuff.timer



[Unit]
Description=my stuff's schedule
[Timer]
OnBootSec=5
OnUnitActiveSec=5
[Install]
WantedBy=timers.target


Then reload the systemd configuration, enable the timer unit and start it.






share|improve this answer





















  • 1





    It's the best solution, the only downside is that cron is a lot easier to overview and configure. SystemD is a pain and it starts with it's directory structure. Still the best for a 5 second interval

    – John
    Dec 17 '18 at 17:32











  • Wouldn't the above snippet go in /etc/systemd/system/mystuff.timer instead of mystuff.service?

    – Brooks
    7 hours ago











  • @Brooks: yes, my bad - bad copy & paste on my side. Fixed.

    – Guss
    7 hours ago











  • Thanks...glad to know I'm not crazy while I'm learning systemd :)

    – Brooks
    7 hours ago














1












1








1







You could use a SystemD timer unit, which will trigger a service - that you'd set up to do what you want - every 5 seconds.



Suppose your service unit is called mystuff.service and is installed in /etc/systemd/system (check out SystemD user services if you want to replace a user's crontab), then you can write a timer unit to run the service at boot time and then every 5 seconds, like this:



/etc/systemd/system/mystuff.timer



[Unit]
Description=my stuff's schedule
[Timer]
OnBootSec=5
OnUnitActiveSec=5
[Install]
WantedBy=timers.target


Then reload the systemd configuration, enable the timer unit and start it.






share|improve this answer















You could use a SystemD timer unit, which will trigger a service - that you'd set up to do what you want - every 5 seconds.



Suppose your service unit is called mystuff.service and is installed in /etc/systemd/system (check out SystemD user services if you want to replace a user's crontab), then you can write a timer unit to run the service at boot time and then every 5 seconds, like this:



/etc/systemd/system/mystuff.timer



[Unit]
Description=my stuff's schedule
[Timer]
OnBootSec=5
OnUnitActiveSec=5
[Install]
WantedBy=timers.target


Then reload the systemd configuration, enable the timer unit and start it.







share|improve this answer














share|improve this answer



share|improve this answer








edited 7 hours ago

























answered Nov 30 '18 at 13:29









GussGuss

1,45811733




1,45811733








  • 1





    It's the best solution, the only downside is that cron is a lot easier to overview and configure. SystemD is a pain and it starts with it's directory structure. Still the best for a 5 second interval

    – John
    Dec 17 '18 at 17:32











  • Wouldn't the above snippet go in /etc/systemd/system/mystuff.timer instead of mystuff.service?

    – Brooks
    7 hours ago











  • @Brooks: yes, my bad - bad copy & paste on my side. Fixed.

    – Guss
    7 hours ago











  • Thanks...glad to know I'm not crazy while I'm learning systemd :)

    – Brooks
    7 hours ago














  • 1





    It's the best solution, the only downside is that cron is a lot easier to overview and configure. SystemD is a pain and it starts with it's directory structure. Still the best for a 5 second interval

    – John
    Dec 17 '18 at 17:32











  • Wouldn't the above snippet go in /etc/systemd/system/mystuff.timer instead of mystuff.service?

    – Brooks
    7 hours ago











  • @Brooks: yes, my bad - bad copy & paste on my side. Fixed.

    – Guss
    7 hours ago











  • Thanks...glad to know I'm not crazy while I'm learning systemd :)

    – Brooks
    7 hours ago








1




1





It's the best solution, the only downside is that cron is a lot easier to overview and configure. SystemD is a pain and it starts with it's directory structure. Still the best for a 5 second interval

– John
Dec 17 '18 at 17:32





It's the best solution, the only downside is that cron is a lot easier to overview and configure. SystemD is a pain and it starts with it's directory structure. Still the best for a 5 second interval

– John
Dec 17 '18 at 17:32













Wouldn't the above snippet go in /etc/systemd/system/mystuff.timer instead of mystuff.service?

– Brooks
7 hours ago





Wouldn't the above snippet go in /etc/systemd/system/mystuff.timer instead of mystuff.service?

– Brooks
7 hours ago













@Brooks: yes, my bad - bad copy & paste on my side. Fixed.

– Guss
7 hours ago





@Brooks: yes, my bad - bad copy & paste on my side. Fixed.

– Guss
7 hours ago













Thanks...glad to know I'm not crazy while I'm learning systemd :)

– Brooks
7 hours ago





Thanks...glad to know I'm not crazy while I'm learning systemd :)

– Brooks
7 hours ago





protected by Community Jun 7 '18 at 18:57



Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



Would you like to answer one of these unanswered questions instead?



Popular posts from this blog

GameSpot

日野市

Tu-95轟炸機