how to make a new Cron job for python scripts to update mysql?












0















I'm a newbie to setup a Cron jobs.



i have a prefix directory for my application python on /usr/local/lib/python2.7/dist-packages/prewikka and i already to new environment for my application python as PYTHONPATH=$prefix/lib/python2.7/dist-packages/prewikka:$prefix/bin/prewikka-httpd



i already a database MySQL manually :



mysql> DESC Prewikka_Crontab;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | varchar(255) | YES | | NULL | |
| name | varchar(255) | NO | PRI | NULL | |
| userid | varchar(255) | YES | | NULL | |
| ext_type | varchar(255) | NO | | NULL | |
| ext_id | varchar(255) | YES | | NULL | |
| base | varchar(255) | NO | | NULL | |
| runcnt | varchar(255) | YES | | NULL | |
| schedule | varchar(255) | NO | | NULL | |
| enabled | tinyint(11) | YES | | 1 | |
| error | varchar(255) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
10 rows in set (0.00 sec)


if i launch prewikka-crontab, no output appears. when i launch prewikka-httpd, i always get the output :



...
File "/usr/local/lib/python2.7/dist-packages/prewikka/history.py", line 102, in <module>
crontab.schedule("search_history", N_("Search history deletion"), "0 * * * *", _regfunc=history._history_cron, enabled=True)
File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 240, in schedule
self._init_system_job(ext_type, name, schedule, enabled, _regfunc)
File "/usr/local/lib/python2.7/dist-packages/prewikka/database.py", line 91, in inner
ret = func(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 154, in _init_system_job
self.add(name, schedule, ext_type=ext_type, enabled=enabled)
File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 219, in add
return self.update(None, name=name, schedule=schedule, user=user, ext_type=ext_type, ext_id=ext_id, enabled=enabled)
File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 209, in update
return env.db.getLastInsertIdent()
RuntimeError: could not retrieve last insert ID


cause i don't have a event scheduler for my client to server side, how i can getting started it with Cron jobs?



Thanks in advance.










share|improve this question



























    0















    I'm a newbie to setup a Cron jobs.



    i have a prefix directory for my application python on /usr/local/lib/python2.7/dist-packages/prewikka and i already to new environment for my application python as PYTHONPATH=$prefix/lib/python2.7/dist-packages/prewikka:$prefix/bin/prewikka-httpd



    i already a database MySQL manually :



    mysql> DESC Prewikka_Crontab;
    +----------+--------------+------+-----+---------+-------+
    | Field | Type | Null | Key | Default | Extra |
    +----------+--------------+------+-----+---------+-------+
    | id | varchar(255) | YES | | NULL | |
    | name | varchar(255) | NO | PRI | NULL | |
    | userid | varchar(255) | YES | | NULL | |
    | ext_type | varchar(255) | NO | | NULL | |
    | ext_id | varchar(255) | YES | | NULL | |
    | base | varchar(255) | NO | | NULL | |
    | runcnt | varchar(255) | YES | | NULL | |
    | schedule | varchar(255) | NO | | NULL | |
    | enabled | tinyint(11) | YES | | 1 | |
    | error | varchar(255) | YES | | NULL | |
    +----------+--------------+------+-----+---------+-------+
    10 rows in set (0.00 sec)


    if i launch prewikka-crontab, no output appears. when i launch prewikka-httpd, i always get the output :



    ...
    File "/usr/local/lib/python2.7/dist-packages/prewikka/history.py", line 102, in <module>
    crontab.schedule("search_history", N_("Search history deletion"), "0 * * * *", _regfunc=history._history_cron, enabled=True)
    File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 240, in schedule
    self._init_system_job(ext_type, name, schedule, enabled, _regfunc)
    File "/usr/local/lib/python2.7/dist-packages/prewikka/database.py", line 91, in inner
    ret = func(self, *args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 154, in _init_system_job
    self.add(name, schedule, ext_type=ext_type, enabled=enabled)
    File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 219, in add
    return self.update(None, name=name, schedule=schedule, user=user, ext_type=ext_type, ext_id=ext_id, enabled=enabled)
    File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 209, in update
    return env.db.getLastInsertIdent()
    RuntimeError: could not retrieve last insert ID


    cause i don't have a event scheduler for my client to server side, how i can getting started it with Cron jobs?



    Thanks in advance.










    share|improve this question

























      0












      0








      0








      I'm a newbie to setup a Cron jobs.



      i have a prefix directory for my application python on /usr/local/lib/python2.7/dist-packages/prewikka and i already to new environment for my application python as PYTHONPATH=$prefix/lib/python2.7/dist-packages/prewikka:$prefix/bin/prewikka-httpd



      i already a database MySQL manually :



      mysql> DESC Prewikka_Crontab;
      +----------+--------------+------+-----+---------+-------+
      | Field | Type | Null | Key | Default | Extra |
      +----------+--------------+------+-----+---------+-------+
      | id | varchar(255) | YES | | NULL | |
      | name | varchar(255) | NO | PRI | NULL | |
      | userid | varchar(255) | YES | | NULL | |
      | ext_type | varchar(255) | NO | | NULL | |
      | ext_id | varchar(255) | YES | | NULL | |
      | base | varchar(255) | NO | | NULL | |
      | runcnt | varchar(255) | YES | | NULL | |
      | schedule | varchar(255) | NO | | NULL | |
      | enabled | tinyint(11) | YES | | 1 | |
      | error | varchar(255) | YES | | NULL | |
      +----------+--------------+------+-----+---------+-------+
      10 rows in set (0.00 sec)


      if i launch prewikka-crontab, no output appears. when i launch prewikka-httpd, i always get the output :



      ...
      File "/usr/local/lib/python2.7/dist-packages/prewikka/history.py", line 102, in <module>
      crontab.schedule("search_history", N_("Search history deletion"), "0 * * * *", _regfunc=history._history_cron, enabled=True)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 240, in schedule
      self._init_system_job(ext_type, name, schedule, enabled, _regfunc)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/database.py", line 91, in inner
      ret = func(self, *args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 154, in _init_system_job
      self.add(name, schedule, ext_type=ext_type, enabled=enabled)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 219, in add
      return self.update(None, name=name, schedule=schedule, user=user, ext_type=ext_type, ext_id=ext_id, enabled=enabled)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 209, in update
      return env.db.getLastInsertIdent()
      RuntimeError: could not retrieve last insert ID


      cause i don't have a event scheduler for my client to server side, how i can getting started it with Cron jobs?



      Thanks in advance.










      share|improve this question














      I'm a newbie to setup a Cron jobs.



      i have a prefix directory for my application python on /usr/local/lib/python2.7/dist-packages/prewikka and i already to new environment for my application python as PYTHONPATH=$prefix/lib/python2.7/dist-packages/prewikka:$prefix/bin/prewikka-httpd



      i already a database MySQL manually :



      mysql> DESC Prewikka_Crontab;
      +----------+--------------+------+-----+---------+-------+
      | Field | Type | Null | Key | Default | Extra |
      +----------+--------------+------+-----+---------+-------+
      | id | varchar(255) | YES | | NULL | |
      | name | varchar(255) | NO | PRI | NULL | |
      | userid | varchar(255) | YES | | NULL | |
      | ext_type | varchar(255) | NO | | NULL | |
      | ext_id | varchar(255) | YES | | NULL | |
      | base | varchar(255) | NO | | NULL | |
      | runcnt | varchar(255) | YES | | NULL | |
      | schedule | varchar(255) | NO | | NULL | |
      | enabled | tinyint(11) | YES | | 1 | |
      | error | varchar(255) | YES | | NULL | |
      +----------+--------------+------+-----+---------+-------+
      10 rows in set (0.00 sec)


      if i launch prewikka-crontab, no output appears. when i launch prewikka-httpd, i always get the output :



      ...
      File "/usr/local/lib/python2.7/dist-packages/prewikka/history.py", line 102, in <module>
      crontab.schedule("search_history", N_("Search history deletion"), "0 * * * *", _regfunc=history._history_cron, enabled=True)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 240, in schedule
      self._init_system_job(ext_type, name, schedule, enabled, _regfunc)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/database.py", line 91, in inner
      ret = func(self, *args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 154, in _init_system_job
      self.add(name, schedule, ext_type=ext_type, enabled=enabled)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 219, in add
      return self.update(None, name=name, schedule=schedule, user=user, ext_type=ext_type, ext_id=ext_id, enabled=enabled)
      File "/usr/local/lib/python2.7/dist-packages/prewikka/crontab.py", line 209, in update
      return env.db.getLastInsertIdent()
      RuntimeError: could not retrieve last insert ID


      cause i don't have a event scheduler for my client to server side, how i can getting started it with Cron jobs?



      Thanks in advance.







      python mysql cron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 25 '18 at 10:05









      abu-ahmed al-khatiriabu-ahmed al-khatiri

      91715




      91715






















          1 Answer
          1






          active

          oldest

          votes


















          0














          i figure it out on this link. a based of the Remove Heartbeats section on that link.



          Step #1 make a .sh script :



          #!/bin/sh

          set -e

          DB_TYPE="mysql"
          DB_HOST="localhost"
          DB_USER="xxxxxx"
          DB_PASS="xxxxxx"

          KEEP_INTERVAL="2 month"

          DATE=$(date -d "now - $KEEP_INTERVAL" +%Y-%m-%d)

          preludedb-admin delete heartbeat --criteria "heartbeat.create_time <= $DATE" "type=$DB_TYPE host=$DB_HOST user=$DB_USER pass=$DB_PASS"


          and make .sh as executable.



          Step #2 make a cron job



          sudo crontab -e


          add a event scheduler,



          */2 * * * * /usr/local/lib/python2.7/dist-packages/prewikka/crontab.py
          */2 * * * * /path/to/sripts/prewikka.sh


          restart using sudo init 6.



          Hope this helps.






          share|improve this answer

























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "89"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1104416%2fhow-to-make-a-new-cron-job-for-python-scripts-to-update-mysql%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            i figure it out on this link. a based of the Remove Heartbeats section on that link.



            Step #1 make a .sh script :



            #!/bin/sh

            set -e

            DB_TYPE="mysql"
            DB_HOST="localhost"
            DB_USER="xxxxxx"
            DB_PASS="xxxxxx"

            KEEP_INTERVAL="2 month"

            DATE=$(date -d "now - $KEEP_INTERVAL" +%Y-%m-%d)

            preludedb-admin delete heartbeat --criteria "heartbeat.create_time <= $DATE" "type=$DB_TYPE host=$DB_HOST user=$DB_USER pass=$DB_PASS"


            and make .sh as executable.



            Step #2 make a cron job



            sudo crontab -e


            add a event scheduler,



            */2 * * * * /usr/local/lib/python2.7/dist-packages/prewikka/crontab.py
            */2 * * * * /path/to/sripts/prewikka.sh


            restart using sudo init 6.



            Hope this helps.






            share|improve this answer






























              0














              i figure it out on this link. a based of the Remove Heartbeats section on that link.



              Step #1 make a .sh script :



              #!/bin/sh

              set -e

              DB_TYPE="mysql"
              DB_HOST="localhost"
              DB_USER="xxxxxx"
              DB_PASS="xxxxxx"

              KEEP_INTERVAL="2 month"

              DATE=$(date -d "now - $KEEP_INTERVAL" +%Y-%m-%d)

              preludedb-admin delete heartbeat --criteria "heartbeat.create_time <= $DATE" "type=$DB_TYPE host=$DB_HOST user=$DB_USER pass=$DB_PASS"


              and make .sh as executable.



              Step #2 make a cron job



              sudo crontab -e


              add a event scheduler,



              */2 * * * * /usr/local/lib/python2.7/dist-packages/prewikka/crontab.py
              */2 * * * * /path/to/sripts/prewikka.sh


              restart using sudo init 6.



              Hope this helps.






              share|improve this answer




























                0












                0








                0







                i figure it out on this link. a based of the Remove Heartbeats section on that link.



                Step #1 make a .sh script :



                #!/bin/sh

                set -e

                DB_TYPE="mysql"
                DB_HOST="localhost"
                DB_USER="xxxxxx"
                DB_PASS="xxxxxx"

                KEEP_INTERVAL="2 month"

                DATE=$(date -d "now - $KEEP_INTERVAL" +%Y-%m-%d)

                preludedb-admin delete heartbeat --criteria "heartbeat.create_time <= $DATE" "type=$DB_TYPE host=$DB_HOST user=$DB_USER pass=$DB_PASS"


                and make .sh as executable.



                Step #2 make a cron job



                sudo crontab -e


                add a event scheduler,



                */2 * * * * /usr/local/lib/python2.7/dist-packages/prewikka/crontab.py
                */2 * * * * /path/to/sripts/prewikka.sh


                restart using sudo init 6.



                Hope this helps.






                share|improve this answer















                i figure it out on this link. a based of the Remove Heartbeats section on that link.



                Step #1 make a .sh script :



                #!/bin/sh

                set -e

                DB_TYPE="mysql"
                DB_HOST="localhost"
                DB_USER="xxxxxx"
                DB_PASS="xxxxxx"

                KEEP_INTERVAL="2 month"

                DATE=$(date -d "now - $KEEP_INTERVAL" +%Y-%m-%d)

                preludedb-admin delete heartbeat --criteria "heartbeat.create_time <= $DATE" "type=$DB_TYPE host=$DB_HOST user=$DB_USER pass=$DB_PASS"


                and make .sh as executable.



                Step #2 make a cron job



                sudo crontab -e


                add a event scheduler,



                */2 * * * * /usr/local/lib/python2.7/dist-packages/prewikka/crontab.py
                */2 * * * * /path/to/sripts/prewikka.sh


                restart using sudo init 6.



                Hope this helps.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 26 '18 at 8:29

























                answered Dec 25 '18 at 13:01









                abu-ahmed al-khatiriabu-ahmed al-khatiri

                91715




                91715






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Ask Ubuntu!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1104416%2fhow-to-make-a-new-cron-job-for-python-scripts-to-update-mysql%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Quarter-circle Tiles

                    build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                    Mont Emei