Crontab in Python (cx_oracle) script execution requires user environment variables, what to do??

Source: Internet
Author: User
Tags postgresql python script

Import Cx_oracle

Traceback (mostrecent ):

File "", line 1, in?

Importerror:libclntsh.so.10.1:cannot Open Shared object file:no such file or directory

See the following post to solve, the only better than his lucky is to see his posts, not spend half a day ~:) ~~~~~~~~~~~~crontab Python script execution failure resolution

Writing server programs inevitably have to deal with Crontab, timed to execute some scripts or something. Most of the cases are shell scripts from bash, but the shell is not very familiar to me, so in many cases I write Python scripts directly to fix it. Today, I wrote a Python script that operates the PostgreSQL database, and when it is executed in crontab, time arrives without any reflection. But if executed directly under the command line, there is no problem.

First look at the crontab log (/var/log/cron), the log shows that the script timed out. Then it must be an error when crontab runs the script. Write a large try module directly from the first line in the Python script and display the contents of the Exception. Sure enough, caught ... The error log shows that Python could not find a library for this PostgreSQL libpq.so.5.

The original crontab environment and the environment we logged in with Root are different, and we need to re-set the running environment variables such as Ld_library_path before running the Python script. This is better, just write a shell script, set the environment variables, and then call Python. Libpq.so.5 This library I was in the/usr/local/pgsql/lib. The final script is as follows:

Done, Crontab and ran again happy up.

Toss a morning, write down the memo.

Crontab in Python (cx_oracle) script execution requires user environment variables, what to do??

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.