SSHスクリプトの作成とコマンドの実行

SSHスクリプトの作成とコマンドの実行

毎日SSHを介してサーバーに接続し、ログを表示するスクリプトを作成しました。

これは私のコードです。

#!/bin/bash

A=`date +%Y`
M=`date +%m`
D=`date +%d`

gnome-terminal --geometry=82x11 \
--tab --title "NAMEServer" -e "sshpass -p P4ssw0rd ssh [email protected] 'tail -f /opt/logs/example.$A-$M-$D.log'" \
--tab --title "NAMEServer" -e "sshpass -p P4ssw0rd ssh [email protected] 'tail -f /opt/logs/example.$A-$M-$D.log'"

しかし、grepで単語をフィルタリングしようとするとうまくいきません。例:

-e "sshpass -p P4ssw0rd ssh [email protected] 'tail -f /opt/logs/example.$A-$M-$D.log | grep 'not fetch''" \

または

-e "sshpass -p P4ssw0rd ssh [email protected] 'cat /opt/logs/exaple.log | grep 'any problem''" \

問題は引用符のようですが、どのようなものを使用する必要がありますか? 、以前に試したことがあります´´ ' ' " "

ベストアンサー1

あなたは正しいです、それはあなたの引用です。一重引用符をエスケープせずに入れ子にしています。この試み:

-e "sshpass -p P4ssw0rd ssh [email protected] 'cat /opt/logs/exaple.log | grep \'any problem\''" \

おすすめ記事