{"id":546,"date":"2009-10-08T10:21:14","date_gmt":"2009-10-08T15:21:14","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=546"},"modified":"2011-07-06T10:36:26","modified_gmt":"2011-07-06T15:36:26","slug":"sudo-and-ld_library_pathnever-the-twain-shall-meet","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2009\/10\/08\/sudo-and-ld_library_pathnever-the-twain-shall-meet\/","title":{"rendered":"sudo and LD_LIBRARY_PATH \u2026 never the twain shall meet"},"content":{"rendered":"<p>While writing something for our operations support team to use when running a particular process, I found that sudo does not recognize a previously exported value for LD_LIBRARY_PATH.  It also won&#8217;t use what is in the .bashrc or .profile for the user that owns the script being sudo&#8217;d.  You also can&#8217;t use os.environ in python to set it, as that only affects processes spawned in python after startup, but not the parent process itself.<\/p>\n<p>It looks like this is due to a security setting in sudo that strips LD_LIBRARY_PATH out of the environment.<\/p>\n<p>Unless you want to set it system wide as in \/etc\/profile, or change \/etc\/ld.so.conf, you can write a here document for the python code inside a shell script that exports LD_LIBRARY_PATH first.  This is what I did.<\/p>\n<p>While not enormously inconvenient, the process of discovering this took me a couple of hours to track down.<\/p>\n<p>Below is an example that will fail in sudo&#8230;<\/p>\n<pre lang=\"python\" line=\"1\">\r\n#!\/home\/oracle\/local\/bin\r\n\r\nimport cx_Oracle\r\n\r\n<\/pre>\n<p>&#8230;and one that will work&#8230;<\/p>\n<pre lang=\"python\" line=\"1\">\r\n#!\/bin\/sh\r\n\r\n. \/home\/oracle\/.bashrc #which contains an LD_LIBRARY_PATH export\r\n\/home\/oracle\/local\/bin\/python <<HERE\r\nimport cx_Oracle\r\nHERE<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>While writing something for our operations support team to use when running a particular process, I found that sudo does not recognize a previously exported value for LD_LIBRARY_PATH. It also won&#8217;t use what is in the .bashrc or .profile for&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2009\/10\/08\/sudo-and-ld_library_pathnever-the-twain-shall-meet\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[19,24,28,27,22,26],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/546"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=546"}],"version-history":[{"count":15,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/546\/revisions"}],"predecessor-version":[{"id":560,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/546\/revisions\/560"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=546"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}