teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

shellの追加

2016/08/28 18:55

投稿

twin_bird
twin_bird

スコア230

title CHANGED
File without changes
body CHANGED
@@ -44,4 +44,9 @@
44
44
  msg.send error if error?
45
45
  msg.send stdout if stdout?
46
46
  msg.send stderr if stderr?
47
+ ```
48
+
49
+ 追記2:shell(hoge.sh)については以下のとおりです。
50
+ ```
51
+ logwatch --print
47
52
  ```

1

コードの追加

2016/08/28 18:55

投稿

twin_bird
twin_bird

スコア230

title CHANGED
File without changes
body CHANGED
@@ -16,4 +16,32 @@
16
16
  ```
17
17
 
18
18
  こんな感じでかいたみたのですが、実行されていないようでどこか間違っているような気がします。
19
- アドバイスお願い致します。。
19
+ アドバイスお願い致します。。
20
+
21
+ 追記: coffee scriptを書き換えてみました。
22
+ ```
23
+ cron = require('cron').CronJob
24
+
25
+ module.exports = (robot) ->
26
+ new cron '*/1 * * * *', () =>
27
+ @exec = require('child_process').exec
28
+ command = "/hoge_hubot/scripts/shell/hoge.sh"
29
+ @exec command, (error, stdout, stderr) ->
30
+ robot.send {room: "#general"}, "stdout"
31
+ , null, true, "Asia/Tokyo"
32
+ ```
33
+
34
+ これでshellの実行結果がslackに投稿されれば良いのですが、stdoutの部分が展開されず、文字列として表示されてしまいます。。。
35
+ (error,stdout,stderr)の部分がどういうものなのか理解しきれていないのですが、以下のようなコードの場合は動作するので、参考にしてみたもののも上手くいきません_| ̄|○
36
+
37
+ ```
38
+ module.exports = (robot) ->
39
+ robot.respond /artisan_up/, (msg) ->
40
+ @exec = require('child_process').exec
41
+ command = "/hoge_hubot/scripts/shell/hoge.sh"
42
+ msg.send "Command: #{command}"
43
+ @exec command, (error, stdout, stderr) ->
44
+ msg.send error if error?
45
+ msg.send stdout if stdout?
46
+ msg.send stderr if stderr?
47
+ ```