以下のshell(
tweepy_perf.sh)をcronをトリガとして実行させる
#!/bin/bash ####################################################################### # # Monitoring of the resource information # ####################################################################### # Environment variable ####################################################################### WORKDIR=/opt/tweepy_monitor LOG=$WORKDIR/monitoring.log echo "`date '+%Y/%m/%d %R'` [`hostname`][ALL][INFO] Monitoring of the resource information Starting..." >> $LOG echo "`date '+%Y/%m/%d %R'` [`hostname`][CPU][INFO] CPU cheaker Starting..." >> $LOG $WORKDIR/bin/tweepy_cpu.sh $WORKDIR >> $LOG echo "`date '+%Y/%m/%d %R'` [`hostname`][MEM][INFO] MEM cheaker Starting..." >> $LOG $WORKDIR/bin/tweepy_mem.sh $WORKDIR >> $LOG echo "`date '+%Y/%m/%d %R'` [`hostname`][FSD][INFO] Filesystem cheaker Starting..." >> $LOG $WORKDIR/bin/tweepy_fsd.sh $WORKDIR >> $LOG echo "`date '+%Y/%m/%d %R'` [`hostname`][ALL][INFO] Monitoring of the resource information End." >> $LOG
ちなみに、ツイッターのDMに送るpyスクリプト(
tweepy_dm_line.py)は以下のようにした。
#!/usr/bin/python # -*- coding: utf-8 -*- import tweepy, sys # Auth KEY = "***************************" SECRET = "*****************************************" ATOKEN = "******************************************" ASECRET = "***********************************************" auth = tweepy.OAuthHandler(KEY, SECRET) auth.set_access_token(ATOKEN, ASECRET) # How to # ./tweepy_dm_line.py <string> api = tweepy.API(auth) line = sys.argv[1] api.send_direct_message(user="<ツイッターアカウント名>", text=line)
たとえば、以下のようにすると、「テストダイレクトメールです![ ]<-半角スペースあり」を送っています。
$ ./tweepy_dm_line.py "テストダイレクトメールです![ ]<-半角スペースあり"