0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Linux起動時にtmuxセッションを立ち上げてtmux上で何か実行する

Posted at

サンプル

例えば、起動時にrcloneのマウントをtmux上で実行したい場合は以下をcrontabに登録する。

@reboot /bin/bash -l -c 'tmux new -d -s rclone_session;tmux send-keys -t rclone_session "rclone mount remote:remote_path local_path" KPEnter'

解説

@reboot /bin/bash -l -c 'tmux new -d -s [セッション名];tmux send-keys -t [セッション名] "[セッションの中で実行したいこと]" KPEnter'

KPEnterとかがダサいけど、tmux自体が仮想スクリーンなのでキー送信をしてるのだという心構えは忘れずに。

なぜtmux?

  • 普通に実行したいだけならcronで直接実行すればいい
  • 標準出力を後追いで見たいのならログファイルとして出力すればいい
  • ログがたまりすぎるのが嫌ならローテートすればいい
  • だけどログローテートって忘れたころに失敗してることがわかる
  • だったら初回からtmuxで標準出力と標準エラー出力眺める方式に合わせておけばいいんじゃない?
  • 色付きでみやすいし
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?