﻿{"id":749,"date":"2020-12-15T08:18:34","date_gmt":"2020-12-15T00:18:34","guid":{"rendered":"https:\/\/byy3.com\/?p=749"},"modified":"2021-02-08T19:00:56","modified_gmt":"2021-02-08T11:00:56","slug":"run-crontab-with-python-selenium-tor-browser-display-in-linux","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=749","title":{"rendered":"run crontab with python selenium tor browser display in linux"},"content":{"rendered":"<p><em>\/5 <\/em> <em> <\/em> * \/bin\/php \/home\/project\/hello.php<br \/>\n5\u5206\u949f\u6267\u884c\u4e00\u6b215minute run<\/p>\n<p>\u6709\u663e\u793a\u6267\u884c\u4efb\u52a1 run python display<br \/>\n30 5 <em> <\/em> * export DISPLAY=:0; \/home\/me\/good_morning.sh<\/p>\n<p>\u6211\u7684\u7535\u8111\u4efb\u52a1 my serveur linux<br \/>\n5 8 <em>\/1 <\/em> * \/usr\/bin\/python3 \/root\/guo\/caiji_wordpress_chinanews_ok.py &gt;&gt; \/root\/guo\/cron-caiji.log 2&gt;&amp;1<\/p>\n<p>\u5408\u6210\u4efb\u52a1 cron.sh is ok<br \/>\n<em>\/5 <\/em> <em> <\/em> * export DISPLAY=:0; \/usr\/bin\/python3 \/root\/tor.py &gt;&gt; \/root\/tor.log 2&gt;&amp;1<\/p>\n<p>==========================================<br \/>\n\u521b\u5efa\u811a\u672c \u5b89\u88c5python3 -m pip install pyvirtualdisplay<\/p>\n<p>This issue has bugged me for near 6 hours.<\/p>\n<p>So if I write \/usr\/bin\/python3 -u \/root\/apps\/bridge\/cinkselenium.py in terminal it is working fine.<\/p>\n<p>But it doesn't work for crontab. Right?<\/p>\n<p>Adding for tor.py<\/p>\n<p>from pyvirtualdisplay import Display<br \/>\ndisplay = Display(visible=0, size=(800, 600))<br \/>\ndisplay.start()<br \/>\nwill not help.<\/p>\n<p>What you need is to make a shell script and write the following -<\/p>\n<p>cron.sh = chmod +x cron.sh<\/p>\n<h1>!\/usr\/bin\/env bash<\/h1>\n<p>export DISPLAY=:0<br \/>\nexport PATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin<br \/>\nnohup \/usr\/bin\/python3 -u \/root\/tor.py &gt; \/root\/tor.log &amp;y<\/p>\n<p>Now run the shell script from Crontab -e<\/p>\n<ul>\n<li>\n<ul>\n<li>\n<ul>\n<li>\n<ul>\n<li>\n<ul>\n<li>\/root\/cron.sh<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>This is what works properly for selenium in crontab without headache in DigitalOcean servers. The paths will be different based on your server and program location.<\/p>\n<p>share improve this answer follow<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-750\" data-original=\"https:\/\/byy3.com\/wp-content\/uploads\/2020\/12\/2020121500182462.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"800\" height=\"500\" title=\"run crontab with python selenium tor browser display in linux\u63d2\u56fe\" alt=\"run crontab with python selenium tor browser display in linux\u63d2\u56fe\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/5 * \/bin\/php \/home\/project\/hello.php 5\u5206\u949f\u6267\u884c\u4e00\u6b215minute ru [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,20,21],"tags":[220,219,471,353,218,223,224,222,352,221,225,199],"class_list":["post-749","post","type-post","status-publish","format-standard","hentry","category-linux","category-python","category-script","tag-cron-sh","tag-crontab","tag-js-bat","tag-linux","tag-python-cron","tag-python-crontab","tag-python-crontab-display","tag-python-display","tag-python","tag-shell-crontab","tag-tor","tag-tor-browser"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=749"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/749\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}