[[FrontPage]]

* Ubuntu [#tdcc2daa]

* Virtual Box [#m2a07013]
** 共有フォルダ [#l42adc95]
 # Windows Share Dr 
 alias share='cd $SHARE'
 sudo mount.vboxsf share ~/share
 export SHARE=~/share/

* python path [#qd42f416]

 $ which python
 /usr/bin/python

* cron [#o945ca7c]
http://qiita.com/gano/items/802519add83c524e3019

テストスクリプト
crontest.py
 # -*- coding: utf-8 -*-
 import sys
 with open("hoge.txt", "w") as f:
    f.write("hello python")
    f.write(str(sys.version))

-cronの編集
 crontab -e (編集)
 crontab -r (リセットされる)

-cronの安全な編集
 crontab -l > ~/crontab #バックアップ
 vim ~/crontab        #バックアップを編集
 crontab < ~/crontab  #本体に上書き

-crontabへの書き込み
 * * * * * /<path_to_python>/python3 /<path_to_file>/test.py 
 * * * * * <path_to_python>/python3 /<path_to_file/test.py >> /<path_to_log>/test.log 2>>&1

-pythonパスの確認
 ※ python path
 which python3
 
-実行権限付加
 chmod 700 test.py
 chown root:root test.py

- (エラー)
  (CRON) info (No MTA installed, discarding output)
 解決
 $ sudo apt-get install postfix

- cronの再起動
 sudo service cron status
 sudo service cron start
 sudo service cron start

-実行ログ
 /var/log/syslog

** 結局 [#q715a499]

 /etc/cron.d/usercron

 # /etc/cron.d/usercron
 
 SHELL=/bin/bash
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 HOME=/home/fifi
 
 # m h dom mon dow user  command
 # * * * * * root  $HOME/anaconda3/bin/python $HOME/cron-script/crontest/crontest.py
 # */1 * * * * root  $SHELL $HOME/cron-script/crontest/crontest.sh
 
 # TEST SCRIPT
 CRONSCRIPT = /home/fifi/cron-script/crontest
 CLOG = /home/fifi/cron-script/crontest/log
 */1 * * * * root which python >> $CLOG/whichpython.log
 */1 * * * * root echo "echo log" >> $CLOG/cron-echo.log
 
 */1 * * * * root python $CRONSCRIPT/crontest.sh

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS