tags:

views:

28

answers:

2

Does anyone know how to write a daemon? I want to write a daemon which executes a script to move a file from one particular directory to another.

+5  A: 

Any reason to not just run a simple bash script via cron?

ErikA
Isn't running a cron job every 5 minutes considered a bad practice?
yogsma
No, why would it be bad practice? In many cases, it would be preferable to a long-running daemon. I have many cron jobs that run every minute - they're very short jobs (runtimes in the sub-second range), but there's nothing wrong with doing that. The only thing you have to be careful with is to make sure that your cron job doesn't last longer than the frequency you have it set to run.
ErikA
What happens in the case of system failure?
yogsma
"System failure"? Like the server crashes or hardware breaks? In that case, the cron job will obviously not run, but neither would the daemon you proposed.
ErikA
+1, Why reinvent the wheel when a quick script and cron will do it?
Chris S
@ErikA, @yogsma - in the "case of system failure", your crontab is still intact on reboot, and will resume.
warren
+1  A: 

the easiest way is to use nohup.

nohup your_command.sh &

And your_command run as a daemon.

yogsototh