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\''" \

답변2

다음과 같이 마지막에 bash를 추가해 보세요.

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

관련 정보