-
Notifications
You must be signed in to change notification settings - Fork 0
/
cron-python-virtualenv.html
218 lines (207 loc) · 12.2 KB
/
cron-python-virtualenv.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html lang="ja">
<head>
<title>virtualenv環境のpythonをcronで呼ぶ - pLog</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=1">
<meta http-equiv="X-UA-Compatible" content="IE=11">
<meta name="author" content="pman0214">
<meta name="keywords" content="python,cron,virtualenv">
<meta name="description" content="virtualenv環境のpythonスクリプトをcronから呼び出す方法。">
<link rel="stylesheet" href="http://pman0214.github.io/blog/theme/css/pure-min.css">
<link rel="stylesheet" href="http://pman0214.github.io/blog/theme/css/ext-pure.css">
<link rel="stylesheet" href="http://pman0214.github.io/blog/theme/css/style.css">
<link rel="stylesheet" href="http://pman0214.github.io/blog/theme/css/pygments/github.css">
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://pman0214.github.io/blog/theme/css/grids-responsive-old-ie-min.css">
<![endif]-->
<!--[if gt IE 8]><!-->
<link rel="stylesheet" href="http://pman0214.github.io/blog/theme/css/grids-responsive-min.css">
<!--<![endif]-->
<!--[if lt IE 9]>
<script src="http://pman0214.github.io/blog/theme/js/html5shiv.js"></script>
<![endif]-->
<link href="http://pman0214.github.io/blog/feeds/atom.xml" type="application/atom+xml" rel="alternate" title="pLog Full Atom Feed">
<link href="http://pman0214.github.io/blog/feeds/rss.xml" type="application/rss+xml" rel="alternate" title="pLog Full RSS Feed">
<!-- open graph tags -->
<meta property="og:site_name" content="pLog">
<meta property="og:type" content="article">
<meta property="og:title" content="virtualenv環境のpythonをcronで呼ぶ">
<meta property="og:url" content="http://pman0214.github.io/blog/cron-python-virtualenv.html">
<meta property="og:description" content="virtualenv環境のpythonスクリプトをcronから呼び出す方法。">
<meta property="article:published_time" content="2015-05-06">
<meta property="article:section" content="python">
<meta property="article:tag" content="python">
<meta property="article:tag" content="cron">
<meta property="article:tag" content="virtualenv">
</head>
<body>
<header>
<nav id="menu">
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
<li class="pure-menu-item"><a href="http://pman0214.github.io/blog" class="pure-menu-heading pure-menu-link">pLog</a></li>
<li class="pure-menu-item pure-menu-has-children pure-menu-allow-hover">
<a href="#" class="pure-menu-link">Categories</a>
<ul class="pure-menu-children">
<li class="pure-menu-item"><a href="http://pman0214.github.io/blog/category/devel.html" class="pure-menu-link">devel</a></li>
<li class="pure-menu-item"><a href="http://pman0214.github.io/blog/category/info.html" class="pure-menu-link">info</a></li>
<li class="pure-menu-item"><a href="http://pman0214.github.io/blog/category/linux.html" class="pure-menu-link">linux</a></li>
<li class="pure-menu-item"><a href="http://pman0214.github.io/blog/category/osx.html" class="pure-menu-link">osx</a></li>
<li class="pure-menu-item pure-menu-selected"><a href="http://pman0214.github.io/blog/category/python.html" class="pure-menu-link">python</a></li>
<li class="pure-menu-item"><a href="http://pman0214.github.io/blog/category/tex.html" class="pure-menu-link">tex</a></li>
<li class="pure-menu-item menu-item-divided"><a href="http://pman0214.github.io/blog/categories.html" class="pure-menu-link">See all...</a></li>
</ul>
</li>
<li class="pure-menu-item"><a href="http://pman0214.github.io/blog/archives.html" class="pure-menu-link">Archives</a></li>
</ul>
</div>
</nav>
</header>
<div id="layout" class="pure-g">
<div class="pure-u-1 pure-u-lg-3-4">
<main id="main">
<article>
<header>
<h1><a href="http://pman0214.github.io/blog/cron-python-virtualenv.html" rel="bookmark" title="Permalink to virtualenv環境のpythonをcronで呼ぶ">virtualenv環境のpythonをcronで呼ぶ</a></h1>
<div class="article-info">
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-2 on-create"><time datetime="2015-05-06T18:58:00+09:00">2015年05月06日 18:58</time></div>
</div>
<div class="category">Category: <a class="pure-button" href="http://pman0214.github.io/blog/category/python.html">python</a></div>
<div class="tags">Tags:
<a class="pure-button" href="http://pman0214.github.io/blog/tag/python.html">python</a>
<a class="pure-button" href="http://pman0214.github.io/blog/tag/cron.html">cron</a>
<a class="pure-button" href="http://pman0214.github.io/blog/tag/virtualenv.html">virtualenv</a>
</div>
</div>
</header>
<section class="contents">
<h2>概要</h2>
<p>virtualenv環境で開発したPythonスクリプトをcronで呼び出したいとき、ライブラリとかをどうやって指定するのか分からなかったので考えてみた。</p>
<h2>結論</h2>
<p>以下のようなスクリプトを作っておき、これを呼び出せばOK。</p>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
<span class="nv">PROG_DIR</span><span class="o">=</span>/usr/local/hoge
<span class="nb">source</span> <span class="nv">$PROG_DIR</span>/bin/activate
python <span class="nv">$PROG_DIR</span>/hoge.pyc
</pre></div>
<h2>解説というほどでもないけど</h2>
<p>要するに、普段やっている<code>source bin/activate</code>を呼んでおけばいいという話。</p>
<p>なので上記のようなスクリプトを書いておけば対応できる。
引数がある場合にはスクリプトに引数を付ければOK。</p>
<p><code>crontab -e</code>で上記スクリプトの呼び出しを追加すれば試合終了。</p>
<div class="highlight"><pre><span></span># m h dom mon dow command
10 4 * * * /usr/local/bin/hoge
</pre></div>
</section>
<section id="comments">
<!-- Disqus -->
<div id="disqus_thread"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE
* SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT:
* https://disqus.com/admin/universalcode/#configuration-variables
*/
var disqus_config = function () {
this.language = 'ja';
this.page.url = 'http://pman0214.github.io/blog/cron-python-virtualenv.html';
this.page.identifier = 'cron-python-virtualenv';
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = '//pman0214-plog.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
</section>
</article>
</main>
</div>
<div class="pure-u-1 pure-u-lg-1-4">
<aside id="sidebar">
<section>
<h1>About pman0214</h1>
<p>ハードからソフトまで分かる研究者。そういうものに私はなりたい。</p>
</section>
<section>
<h1>Links</h1>
<ul class="links">
<li><a href="https://www.f.ait.kyushu-u.ac.jp/~ishida/">Research</a></li>
</ul>
</section>
<section>
<h1>Social Links</h1>
<ul class="links">
<li><a href="https://www.facebook.com/pman0214">facebook</a></li>
<li><a href="https://twitter.com/pman0214">twitter</a></li>
<li><a href="https://github.com/pman0214">github</a></li>
</ul>
</section>
<section class="tags">
<h1>Tags</h1>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/autofs.html">autofs</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/backlogs.html">backlogs</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/bios.html">bios</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/blog.html">blog</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/category.html">category</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/chrome.html">chrome</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/chromium.html">chromium</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/cron.html">cron</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/css-framework.html">css framework</a>
<a class="tag tag-1" href="http://pman0214.github.io/blog/tag/debian.html">debian</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/dpkg.html">dpkg</a>
<a class="tag tag-2" href="http://pman0214.github.io/blog/tag/efi.html">efi</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/emacs.html">emacs</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/fft.html">fft</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/format.html">format</a>
<a class="tag tag-2" href="http://pman0214.github.io/blog/tag/github.html">github</a>
<a class="tag tag-2" href="http://pman0214.github.io/blog/tag/gitlab.html">gitlab</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/gnuplot.html">gnuplot</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/html.html">html</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/ieice.html">ieice</a>
<a class="tag tag-2" href="http://pman0214.github.io/blog/tag/info.html">info</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/install.html">install</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/latex.html">latex</a>
<a class="tag tag-2" href="http://pman0214.github.io/blog/tag/ldap.html">ldap</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/line-style.html">line style</a>
<a class="tag tag-1" href="http://pman0214.github.io/blog/tag/linux.html">linux</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/numpy.html">numpy</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/openwrt.html">openwrt</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/openwrt-package.html">openwrt package</a>
<a class="tag tag-2" href="http://pman0214.github.io/blog/tag/osx.html">osx</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/pandas.html">pandas</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/pelican.html">pelican</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/pl2303.html">pl2303</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/prolific.html">prolific</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/pthread.html">pthread</a>
<a class="tag tag-1" href="http://pman0214.github.io/blog/tag/python.html">python</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/raid.html">raid</a>
<a class="tag tag-2" href="http://pman0214.github.io/blog/tag/raspberry-pi.html">raspberry pi</a>
<a class="tag tag-2" href="http://pman0214.github.io/blog/tag/redmine.html">redmine</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/rfft.html">rfft</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/tex.html">tex</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/thin-client.html">thin client</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/timezone.html">timezone</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/usbserial.html">usbserial</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/valgrind.html">valgrind</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/virtualenv.html">virtualenv</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/windows.html">windows</a>
<a class="tag tag-4" href="http://pman0214.github.io/blog/tag/yatex.html">yatex</a>
<p><a href="http://pman0214.github.io/blog/tags.html">See all...</a></p>
</section>
</aside>
</div>
<!-- #layout --></div>
<footer id="footer">
© 2018 pman0214
|
Powered by <a href="http://docs.getpelican.com/" target="_blank">Pelican</a>
with <a href="https://github.com/pman0214/pelican-pure" target="_blank">Pure theme</a>
</footer>
</body>
</html>