Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 similiar to do that? I looked at cronjobs, but the minimum intervall seems to be 1 minute. Any advice is apperciated ;)

Fedora is the system.

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

share|improve this question

3 Answers 3

up vote 3 down vote accepted
(
  while true
  do
    your-command-here
    sleep 5
  done
) &
disown
share|improve this answer
    
what is disown for? what if I run without it? –  Marcel 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? –  Marcel 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
#!/bin/bash
echo $(date)
$ chmod +x periodic.sh

$ watch -n 5 ./periodic.sh
share|improve this answer
    
what if I log out? the script should continue running. –  Marcel 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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