6

SOLVED, see 'useless' answer.

I have a cronjob in my crontab.

When I specify the job to be executed in 2minutes, I wait, and then I can see files created by the job, I can see the process with ps. The job takes at least 10minutes to complete.

But, if I specify the job to be executed in 2minutes, and then I log out, I come back a few minutes thereafter, and it seems that the job has not been executed (no files created, and process not in ps).

When I look to the /var/log/syslog I can see that the job 'started', but immediately (at the same second) cron tries to send a mail. Probably the mail with the result. (well, sendmail is not correctly configured but this should not be the root cause).

Do you have any idea ?


Here are some concrete example : (python is the name of my machine)

I edit the crontab using crontab -e.
Here is the crontab :

user@python:~$ crontab -l
[...]
# m h  dom mon dow   command

50 9 * * * /home/user/scripts_automated/crontab1.sh

It should run at 9:50

Here is the content of the /var/log/syslog :

[...]
Nov  6 09:48:02 python crontab[30913]: (user) BEGIN EDIT (user)
Nov  6 09:48:18 python crontab[30913]: (user) REPLACE (user)
Nov  6 09:48:18 python crontab[30913]: (user) END EDIT (user)
Nov  6 09:50:01 python CRON[30936]: (user) CMD (/home/user/scripts_automated/crontab1.sh)
Nov  6 09:50:01 python sendmail[30938]: sA68o1a4030938: from=user, size=347, class=0, nrcpts=1, msgid=<201411060850.sA68o1a4030938@python>, relay=user@localhost
[...]

As you can see in the log, I edited the crontab at 09:48:02, then I logged out. I come back on the machine (with ssh), and the job did not produce any files it should have produced.

Here is the content of the script :

user@python:~$ cat scripts_automated/crontab1.sh


#  0  ------------------------------------------------------

datenow=`date +%F_%H-%M-%S`
/home/user/scripts_automated/script_1_cisco_grab.sh > /home/user/scripts_automated/crontab/run_${datenow}_.txt 2>&1 &
echo $! > /home/user/scripts_automated/crontab/pid_${datenow}.txt
ln -s /home/user/scripts_automated/crontab/pid_${datenow}.txt /home/user/scripts_automated/crontab/pid_last_run.txt

and no file is produced. I would at least expect the file pid_${datenow}.txt to exist with the pid of the background command. But nothing. If I don't log out, then scripts executes, produces output files, pid_${datenow} file, and so on ...

  • How do you specify the job to be executed? Please give concrete examples, do edit the crontab file and change the two fields? – Anthon Nov 6 '14 at 10:50
  • Could you add the script to your question? – garethTheRed Nov 6 '14 at 10:51
  • I edited my question with a concrete example – Stef Nov 6 '14 at 11:17
  • 3
    Does the user have an encrypted home directory? If so, it will be unmounted and unavailable when logged off. – Useless Nov 6 '14 at 11:18
  • 1
    @Stef You can use mount to see what is mounted /home/stef (e.g.) or /home. You don't need to decrypt your home directory, just copy the executable file somewhere that is not encrypted, as I indicated in my answer. Decrypting a home dir is possible, but you should make a new question for that, with details about your system (what Linux version, what encryption etc). – Anthon Nov 6 '14 at 13:44
6

You should put your script in a separate directory, that for sure is available while the cron job is running, e.g. /usr/local/bin/.

It is also good custom to write crontab entries like this:

M H * * *  test -x /usr/local/bin/myscript.sh || /usr/local/bin/myscript.sh

so the crontab doesn't even try to execute the script if it is not available.


You suspected the logout being the problem, what you should have tried as well is logging out and then back in in-time for the crontab to run and then observe. That way you could have narrowed down if the logging out was the problem or the being not logged in.

  • I tried this. I really made a lot of tries. Even unlogging after the scripts started, and I can see that the process stoped. – Stef Nov 6 '14 at 13:59

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.