Noob asks, "How do I get this cron job to work?"

March 25, 2016 3.2k views
Getting Started Arch Linux Python Configuration Management

I’ve done the tutorials and can’t seem to get this cronjob to work. Does anything jump out as incorrect? I believe the paths are correct since I was able to echo into a log file at one point when I replaced the script with echo. It was created by root user. The script writes out a json file that never shows as modified in Transmit. Any help? Thanks!

* * * * * /usr/bin/python2.7 /var/www/html/apps/dir/js/
1 Answer

Run it yourself (as the user the cron is under) to make sure it works. Also check /var/log/syslog.

  • Thanks for the tips. The syslog showed the cron was firing so that’s good. I ran the remote script from the terminal and it didn’t write either. It writes fine locally, but not when uploaded. What should I check to see why it won’t write when on the server?

    • Make sure the permissions on the json file are correct and the absolute path is correct.

      • Permissions of file and parent directory are 755.

        In python using…

        team = 1111111
        j = open( str(team) + ".js","w+")
        • Is the file owned by the user you’re running the cron as? And is “team” and absolute path? E.g. /var/www/data.js instead of just data.js

          • Cron is owned by root (I’m reading that’s not ideal)
            File is also owned by root.
            The link is to just “data.js” and not absolute like “/var/www/data.js”.

          • It should be an absolute path.

          • Updated to absolute and added echo to log file. Log says IOError: [Errno 2] No such file or directory: ‘var/www/html/apps/dir/js/18578.js’ but the file is clearly there. I can see it in Transmit.

          • Absolute paths start with /

Have another answer? Share your knowledge.