I need to call a specific command in an interval of about 5 sec. How would I setup a daemon/process running in the background or something similar to do that? I looked at cronjobs, but the minimum interval seems to be 1 minute. Any advice is appreciated ;)

Fedora is the system.

EDIT the command would be a bashscript, so "watch" wouldn´t do it I think.

  while true
    sleep 5
) &
  • what is disown for? what if I run without it? – Hans Jan 19 '11 at 15:09
  • @Marcel, disown removes the last job from the shell job table, making it sort of a daemon, like you asked. It is not a real daemon because it is still attached to terminal and is in the same process group, but it will keep running after you close the shell. – Juliano Jan 19 '11 at 15:14
  • okay great, that would work :D Just for curiosity how would i "make" a daemon? – Hans Jan 19 '11 at 15:24
  • @Marcel the simple way is to call daemon(3) from C or other language with library access (not from a shell script). This is the hard way. – Juliano Jan 19 '11 at 15:35

Why do you think 'watch' will not work?

$ cat periodic.sh
echo $(date)
$ chmod +x periodic.sh

$ watch -n 5 ./periodic.sh
  • what if I log out? the script should continue running. – Hans Jan 19 '11 at 15:13
  • It will stop, but you can use nohup watch -n 5 ./periodic.sh > periodic.log & and store the output. – naufraghi Apr 28 '11 at 10:07
  • for piping use the '' quoting because th "command is given to "sh -c" which means that you may need to use extra quoting to get the desired effect" – andrej Mar 22 '13 at 10:00

Maybe with nohup? It's designed to let a job run after the shell is closed.

You can also use screens.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.