mysql - Why is Python not setting up my cron job's time properly?[Solved] -


i created python script adds data entry in mysql database every 1 minute. that, used cron inside python.here's code of script1.py:

import mysqldb mdb crontab import crontab  con=mdb.connect('localhost','prabakar','****','timedb'); con:     cur=con.cursor()     cur.execute("drop table if exists timer")     cur.execute("create table timer(time time)")     cur.execute("insert timer(time) values(current_timestamp)") cron= crontab(user=true) job=cron.new(command='/home/praba1110/delta_sysad_tasks/task  2/script2.py') job.minute.every(1) cron.write() 

where script2.py is,

    import mysqldb mdb     con=mdb.connect('localhost','prabakar','****','timedb');     con:           cur=con.cursor()           cur.execute("insert timer(time) values(current_timestamp)") 

when executed command 'crontab -e' command in terminal, showed entry of

    * * * * * /home/praba1110/delta_sysad_tasks/task  2/script2.py 

instead of,

    */1 * * * * /home/praba1110/delta_sysad_tasks/task  2/script2.py 

when made 2nd script run seperately, did run , appended current time in table.but when trying execute script1, isn't working.the script 2 not getting executed script 1. ps: did give rwx permissions script2.py

can tell why script1.py isn't working or problem is?

edit: works if give
job=cron.new(command='/user/bin/python2 "/home/praba1110/delta_sy sad_tasks/task 2/script2.py" ')

* * * * * /home/praba1110/delta_sysad_tasks/task  2/script2.py 

is equivalent

*/1 * * * * /home/praba1110/delta_sysad_tasks/task  2/script2.py 

neither of these crontab entries work however, since shell try execute

/home/praba1110/delta_sysad_tasks/task 

and pass argument 2/script2.py. instead, you'll need protect spaces in directory path enclosing command in quotes:

job=cron.new(command='/path/to/python "/home/praba1110/delta_sysad_tasks/task  2/script2.py"') 

so crontab entry becomes

* * * * * /path/to/python "/home/praba1110/delta_sysad_tasks/task  2/script2.py" 

note handling spaces correctly possible annoyance. might want avoid spaces in paths make life easier.

per moo's suggestion, i've added explicit absolute path python executable since default cron jobs not see same environment variables (such path) see when logged on.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -