CRON and Script aren't working together.


  • QA Engineer

    I have a violin on a python that works at the corners in the consoles. Crypt in the console:

    cd /root/bill
    source bin/activate
    puthon filegen.py
    

    The violin itself has a logic: running on the table in the mongo, getting HTML, generating a PDF from it, and clicking the tape as completed:

    #!/root/bill/bin/python
    # coding: utf-8
    

    from future import unicode_literals
    from mongoengine import *
    import datetime
    import time
    import calendar

    from io import BytesIO as IO
    import gzip

    import pdfkit
    import pytils

    from bson import json_util
    from bson.json_util import dumps
    from bson.objectid import ObjectId

    import sys
    import random
    reload(sys) # Reload does the trick!
    sys.setdefaultencoding('UTF8')

    connect(host='mongodb://main:PWD@HOST/bill?ssl=true&ssl_cert_reqs=CERT_NONE')

    class Genq(Document):
    dokstring = StringField()
    outpdf = StringField()

    print ("started")

    foreva = True

    while foreva:
    print ("....")
    reqs = Genq.objects()
    for doc in reqs:
    print ("++++++")
    pdfkit.from_string(doc.dokstring, doc.outpdf)
    print (">>>>>>")
    doc.delete()
    print ("!!!!!!!")

    I'm trying to launch this eternal crypt in the crown by team:

    @reboot /root/bill/bin/python /root/bill/filegen.py >>/var/log/syslof

    I get the following message in the console:

    root@bill2:~# tail 50 /var/log/syslog
    tail: cannot open ‘50’ for reading: No such file or directory
    ==> /var/log/syslog <==
    started
    ....
    ++++++
    Jul 22 04:26:56 bill2 postfix/pickup[1115]: C16891600F3: uid=0 from=<root>
    Jul 22 04:26:56 bill2 postfix/cleanup[1263]: C16891600F3: message-id=<20160722082656.C16891600F3@bill2>
    Jul 22 04:26:56 bill2 postfix/qmgr[1116]: C16891600F3: from=<root@bill2>, size=1221, nrcpt=1 (queue active)
    Jul 22 04:26:56 bill2 postfix/local[1265]: C16891600F3: to=<root@bill2>, orig_to=<root>, relay=local, delay=0.02, delays=0.01/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
    Jul 22 04:26:56 bill2 postfix/qmgr[1116]: C16891600F3: removed
    Jul 22 04:27:00 bill2 ntpdate[603]: step time server 91.189.89.198 offset -0.344170 sec
    Jul 22 04:27:16 bill2 ntpdate[1281]: adjust time server 91.189.89.198 offset -0.000024 sec
    root@bill2:~#

    I understand the violin goes somewhere on the line:

    pdfkit.from_string(doc.dokstring, doc.outpdf)

    But why does the console do what you need?

    All I've learned is that the crown has some sort of environment that doesn't see the file system or the library. pdfkit, though I'm starting it from the mouth.



  • Based on the line source bin/activate - you're using. virtualenv Or his fork/clon. virtualenv - is a separate environment with other ways in which modules that are not available in a system-based python can be installed (cot is default for all UNIX users)

    So make wrapper-file, where the right environment can be established:

    run_me.sh:

    #!/bin/bash
    

    export VIRTUAL_ENV=/root/bill
    cd $VIRTUAL_ENV
    source $VIRTUAL_ENV/bin/activate
    $VIRTUAL_ENV/bin/python /path/to/filegen.py

    and start it out. CRONTABYeah.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2