0

Before of first, I'm a Linux (administrator|developer) newbie.

I need to run a bash script every 5 seconds, it's very simple; export service's information to text files.

I try to do this with cron daemon, but it's run every minute at least.

I'm discover Skeleton script and have many questions about this:

  • I need write some special code in my bash file?
  • How to run every 5 seconds?
  • There are a best practices manual?
Javier Valencia
  • 697
  • 7
  • 24
  • You cannot do this cron based, crons resolution is indeed limited to 1 minute. Instead you need to implement your own simply daemon that triggers the required action based on events generated by the systems clock. You want to take a look at the `sleep` commands and similar. – arkascha Apr 24 '14 at 11:48
  • I want to avoid cron @ElmoVanKielmo, and I want to do this as a daemon. – Javier Valencia Apr 24 '14 at 11:51
  • Then read the linked question and __especially__ the accepted answer. It's clearly said there that cron should not be used for this and bash code is posted as well. – ElmoVanKielmo Apr 24 '14 at 11:52
  • Ok @ElmoVanKielmo, now I understanding. I'm in debt with you. – Javier Valencia Apr 24 '14 at 12:05

1 Answers1

0

Yes its not possible through cron as daemon runs once in every minute. Or when job list is modified

Put whatever you want to run in a script inside infinite while loop and put sleep of 1 sec something like

while [ 1 ] do run_your_cmds here sleep 1 done

BUT I dont think anything need that kind of monitoring.

Best Practice!! Please dont try and do it with cron.

PradyJord
  • 2,136
  • 12
  • 19