FrontPage / Ubuntu

[[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

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

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

- (エラー)
  (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


** cronの使い方 まとめ [#hacea8b1]
cronのディレクトリ/etc/cron.d/の中に、自分の定期実行の設定ファイルを入れる。例えば、/etc/cron.d/usercronみたいな。
パスは絶対パスでかく。

usercron
 SHELL=/bin/sh
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
 HOME=/home/fifi/Temp
 SCRIPT=/home/fifi/Temp/task
 CLOG=/home/fifi/Temp/task/log
 
 # Copy ENV
 */1 * * * * root env $SCRIPT/cron_env
 # Cron exe log
 */1 * * * * root date >> /home/fifi/Temp/task/log/bashdate.log
# Cron Python Script
 */1 * * * * root /bin/bash /home/fifi/Temp/task/crontest.sh
 */1 * * * * root python /home/fifi/Temp/task/crontest.py

** CRON -> Pythonスクリプト [#fae2692b]
パーミッションは適当でいい。オーナーはrootする必要もない。
--crontest.py
 import datetime
 LOG_DIR = "/home/fifi/Temp/task/log/crontestpy.log"
 with open(LOG_DIR, "a") as fp:
	fp.write(str(datetime.datetime.today()))
	fp.write(" : crontest.py¥n")


** CRON -> シェルスクリプト -> Pythonスクリプト [#m967ca13]
パスは絶対パスでかく。

--crontest.sh
 python /home/fifi/Temp/task/crontest_bash.py

--Permission (必要か分からない)
 sudo chmod 700 crontest_bash.py
 sudo chown root:root crontest_bash.py

--crontest_bash.py
 import datetime
 LOG_DIR = "/home/fifi/Temp/task/log/crontestpy.log"
 with open(LOG_DIR, "a") as fp:
	fp.write(str(datetime.datetime.today()))
	fp.write(" : crontest_bash.py¥n")


* Sample [#x0936c05]

#prettify{{
# /etc/cron.d/usercron

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin


# ---------------------------------------------------
#
# How To
#
# Use Python
# * * * * * root  $HOME/anaconda3/bin/python $HOME/cron-script/crontest/crontest.py
# Use SHell
# */1 * * * * root  $SHELL $HOME/cron-script/crontest/crontest.sh
# ---------------------------------------------------

# ---------------------------------------------------
#
# User Script
#
# ---------------------------------------------------
HOME=/home/fifi
CRONSCRIPT = /home/fifi/cron-script/mydns
CLOG = /home/fifi/cron-script/mydns/log

# Always TEST SCRIPT
* 0 * * * root date >> $CLOG/cron-always.log

# Your Python Script
* 0 * * * root  $HOME/anaconda3/bin/python $CRONSCRIPT/update_mydns.py

}}
トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS