WebFaction
Community site: login faq

Hi

I've got a python3 routine in the following location:

/home/myusername/public_html/cgi-bin/routine.py

I've then uploaded a file called crontab.txt to the same directory with the code:

*/10 * * * */usr/local/bin/python3 /home/myusername/public_html/cgi-bin/routine.py

If I then go to the cgi-bin directory using SSH and run the command

crontab crontab.txt

I get the response:

"crontab.txt":1: premature EOF errors in crontab file, can't install.

Where am I going wrong please?

Also, with the above timings I hope to run the routine at 0,10,20.... mins past the hour. Will this happen or might it run at 02,12,22... mins past the hour?

thanks John

asked 26 Feb '16, 19:19

santon
114
accept rate: 0%


Where am I going wrong please?

I see a couple of problems:

  1. You're missing a space between the final asterisk in the schedule and the first character of the command
  2. Your file is has no line endings.

You can fix both problems with the following command:

echo "`sed 's/\*\/u/\* \/u/' crontab.txt`" > crontab.txt

Also, with the above timings I hope to run the routine at 0,10,20.... mins past the hour. Will this happen or might it run at 02,12,22... mins past the hour?

The schedule above will run at 10 minute intervals, starting at :00 and every 10 minutes thereafter.

permanent link

answered 27 Feb '16, 00:53

seanf
12.2k41836
accept rate: 37%

Hi I still cannot get the cron job to run. I have discovered that python3 was in a different folder to that which I had thought. I have also set the routine to run every minute but it does not seem to be running and logs are not being created. I have the following code in my crontab file.

* * * * * /usr/bin/python3 /home/myusername/public_html/cgi-bin/routine.py >> ~myusername/logs/user/cron.log 2>&1

I am assuming that the command to get the cronjob (named crontab.txt) to run is:

crontab crontab.txt

The weird things is that if I type the following into putty:

python3 /usr/bin/python3 /home/myusername/public_html/cgi-bin/routine.py

then the routine runs. This seems to prove that my path is correct. The only difference between doing it manually and using the cron routine is that doing it manually I start with python3 ... Does this suggest that my cron code is not forcing it to run using python3 but that it is trying to use python2 and failing?

Any ideas as to how to troubleshoot please?

permanent link

answered 29 Feb '16, 11:44

santon
114
accept rate: 0%

edited 29 Feb '16, 12:33

Can you please open a support ticket from your WebFaction hosting control panel, so that we can check this further?

You can create the ticket using the following URL:

https://my.webfaction.com/open-support-ticket

(29 Feb '16, 13:00) dimitari

I had a similar issue running in 2.7 from crontab: ended calling a script in the same directory as my app. This is what I'm doing (mostly unoriginal work which I probably I cobbled together from answers here on stackexchange).


#!/bin/bash
#set env variables
export ENV_VAR={{whatever}}

mkdir -p "$HOME/tmp"
PIDFILE="$HOME/webapps/{{app_folder}}/{{app_name}}.pid"

if [ -e "${PIDFILE}" ] && (ps -u $(whoami) -opid= |
                           grep -P "^\s*$(cat ${PIDFILE})$" &> /dev/null); then
  echo "Already running."
  exit 99
fi

#now call the actual app
$HOME/webapps/{{app_folder}}/{{app}}.py

echo $! > "${PIDFILE}"
chmod 644 "${PIDFILE}"

I then call the script from crotab thusly:


0 /3 *  * $HOME/webapps/{{app_folder}}/{{shell_script}}.sh > $HOME/logs/user/comm.log 2>&1

Ended up working out better because with the limited env run by cron I needed to initiate some env vars before i called python anyway. hope this helps

permanent link

answered 01 Mar '16, 15:15

spam
112
accept rate: 0%

edited 01 Mar '16, 15:16

Hi

Thanks for the input. Eventually Webfaction support found some spurious characters that had been generated by notepad but which were not visible. After they fixed it I needed to alter the frequency of the cron job and had the same issue again.

I fixed it by running dos2nux myroutine.py

This sorted it out.

permanent link

answered 01 Mar '16, 16:58

santon
114
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×81
×50

question asked: 26 Feb '16, 19:19

question was seen: 2,356 times

last updated: 01 Mar '16, 16:58

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM