0

My script which starts a process and writes the PID of that process to file. This works as it's supposed to when I execute it from shell:

process & echo $! > /home/xxx/PIDs/process.pid

But when I let cron do that, the process is executed but the PID file is missing. This is weird to me. What could be wrong?

The cronjob is a simple @reboot trigger. I tried, as Jeff Schaller mentioned,

*/10 * * * * /home/xxx/bin/process & echo $! > /home/xxx/PIDs/process.pid

but this does not work.

  • Are you running the command on the command line with the same user whose crontab should execute the job? Do the owner of the crontab get any error messages in their email from cron? – Kusalananda Dec 17 '18 at 15:11
0

To me it sounds like the user your cron job runs as, does not have permission to write the PID-file to /home/xxx/PIDs/.

This could be the case if e.g. /home is mounted over NFS for example, or perhaps due to things like SELinux.

Try checking local e-mail. In most setup's cron sends error to the local root user by e-mail.

It may also be worth to try running the command as user account xxx by specifying this in the crontab, or login as user xxx and run crontab -e to edit the 'personal' crontab of user xxx.

  • On most systems, cron would send an email to the owner of the crontab. If the owner is root, then there should be no permission problem. Also, the user mentions that they are able to run the command on the command line. You answer has merit if it mentions the fact that it's the user that owns the crontab that has to have write permission in the destination directory (the cron daemon itself will not try to write anything). – Kusalananda Dec 17 '18 at 15:09
  • I use sudo crontab -e for editing so it's roots cron. I think something is going on with the external hdd. when i reboot i get a unmount fail and system hangs until it fully reboots. that's only the case when a process writes to file when it reboots. I could swear normally it rebooted without this unmount failure. – diggidre Dec 17 '18 at 15:21
  • @Kusalananda : point taken: cron daemon iself does not try to write to /home/... Edited my answer. – Hkoof Dec 17 '18 at 15:30
  • Not /home is directly mounted as NFS but a subfolder on exHDD is mounted under /home. And that is also the place where the scripts stored. Even tried with users cron but same. I reinstalled cron with purge but old crontab was still there after reinstall. Anyways I'll test now if that helped. – diggidre Dec 17 '18 at 15:31
0

Sry I said scripts are at subfolder on exHDD thats not correct, they are stored in /home/subfolder but doesn't matter anymore. reinstalling cron does it. Can't figure out why...

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.