1

I have an Ubuntu 14.04.5 installed and I'm trying to run a cron but it does not work.

$ whoami
root

$ crontab -e
#append at the end of the file
* * * * * env > /tmp/env_root.output
#save and quit :wq

$ less /var/log/cron.log
......
Sep 22 20:15:01 myserver CRON[2993]: (root) CMD (env > /tmp/env_root.output)

$ ls -la /tmp/env_root.output
ls: cannot access /tmp/env_root.output: No such file or directory

Why is this? I am root and I should be able to edit files, the Cron log shows it as being changed, but no file is there. If I run the command in the current GNU BASH shell or even in /bin/sh it works but not in Cron.

What am I doing wrong? Does Ubuntu have something like SELinux that I might have enabled by mistake? I provision my server with Ansible and I am not the only person working on the Ansible roles.

Thank you

EDIT: This is how my /etc/crontab looks and it runs /usr/bin/myscript.sh https://paste.fedoraproject.org/433591/74650461/

pa4080
  • 29,831
ddreian
  • 293
  • 1
    It's hard to differentiate where your formatted output, commandlines and content of your crontab file begins and ends. If you can edit your question and make this clearer I'm sure I could identify the problem. – L. D. James Sep 22 '16 at 17:29
  • 1
    Try * * * * * /usr/bin/env > /tmp/env_root.output – heemayl Sep 22 '16 at 17:29
  • Thank you. I tried:
    * * * * * env >> /tmp/env_root.output
    * * * * * /usr/bin/env > /tmp/env_root.output
    * * * * * /usr/bin/env 2&>1 /tmp/env_root.output
    
    

    None work :( > shoud work despite of the file not existing. I created the file and still no luck, it does not get populated. /usr/bin is in my path so adding full path does not help and sending stderr to the file does not work since env sends to stdout not stderr.

    – ddreian Sep 22 '16 at 20:12
  • Strangely it works if I put my script in /etc/crontab instead of using contab -e – ddreian Sep 23 '16 at 17:10
  • add the full path of env by getting the path of env by executing the command which env – Bidyut Aug 23 '17 at 15:51

1 Answers1

-1

The best way to troubleshoot cron jobs is to watch the cron output in near-real-time.

This Q&A describes the process of breaking out syslog to make the system create a cron.log and to monitor it:

16.04: How do I make cron create cron.log and monitor it in real time?

It is very helpful to change the log level to 15 so it not only shows start times but also errors and stop times:

How to change cron log level?

SDsolar
  • 3,169