全体的な目標は:シャットダウン中にSync with Cloudを使用rclone
し、出力を少し変更します。私はシステムユニットを作りました。
[Unit]
Description=Syncing with MEGA cloud storage v78
After=network-online.target
[Service]
User=yevhenii
Type=oneshot
ExecStart=/bin/true
ExecStop=/usr/local/sbin/auto-sync.sh
RemainAfterExit=true
TimeoutStopSec=0
TTYPath=/dev/console
StandardOutput=tty
StandardError=inherit
[Install]
WantedBy=multi-user.target
auto-sync.sh
終了後に再起動します。スクリプトはスクリプトを区別し、シャットダウン中にのみ同期を実行できます。さて、rcloneの出力を修正する方法は?最も簡単な方法は次のとおりです。rclone
出力がコンソールではないため、フォーマットを指定したANSIコードを印刷しないため、機能しません。
# doesn't work well, formatting is ugly without ANSI codes
# prints in terminal emulator, prints in TTY during shutdown
rclone sync "$FROM" "$TO" --progress | while read line;
do
echo "[rclone] $line"
done
script
そのため、コマンド出力ロギングを実行し、コンソールをエミュレート(!)してコマンドを実行するユーティリティを使用します(rclone
ANSIコードを印刷し続けます)。私にぴったりのもの!
# works like a charm
# prints in terminal emulator, does NOT print in TTY during shutdown
script --return --quiet --command "rclone sync $FROM $TO --progress" /dev/null | while read line;
do
echo "[rclone] $line" #works like a charm
done
問題はUbuntu端末エミュレータでは動作しますが、シャットダウン中に表示されるTTYでは動作しません。この問題を解決する方法を知っている人はいますか?ありがとうございます!