나는이없는 tr
및 cut
사용에 가능합니다. 이 (추출)은 Linux 서버에서 작동합니다.
disk_avail=$(df -k /var/tmp | tail -1 | tr -s ' ' | cut -d' ' -f4)
pids=$(cat /var/tmp/$0.pid | tr -s ' ' | cut -d ' ' -f 2)
while [ $count -le 4 ]
..하지만 장치에서 구현하려고하면 다음과 같이 표시됩니다.
tr: not found
cut: not found
tr: not found
cut: not found
[: -lt: unexpected operator
누구든지이 문제를 해결할 수 있습니까?
방금 확인했고 sed와 awk를 사용할 수 있습니다.
장치는 JunOS를 실행하는 주니퍼 라우터입니다.
요청 된 출력 :
% ls / bin / cut
ls : / bin / cut : 해당 파일 또는 디렉토리 없음
% ls / usr / bin / cut
ls : / usr / bin / cut : 해당 파일 또는 디렉토리 없음
%
아래 awk 제안에 감사드립니다. 조만간 시도해 보겠습니다.
awk 솔루션은 감사합니다 !!
awk
is normally available, so supposing you have it in your machine, this approach can help you solve the problem:
df -k /var/tmp | tail -1 | tr -s ' ' | cut -d' ' -f4
This means you want to get, from the last line of df -k
, the 4th field.
This is a equivalent:
disk_avail=$(df -k /var/tmp | awk 'END {print $4}')
We are taking advantage of awk
being able to access to the last line when processing the END
block. This way, you can print the last 4th field. Also, there is no need to combine tr -s' '
and cut
, because awk
does handle multiple spaces as one.
Regarding this one:
pids=$(cat /var/tmp/$0.pid | tr -s ' ' | cut -d ' ' -f 2)
this gets the 2nd field from /var/tmp/$0.pid
. Similarly, you can use this awk:
pids=$(awk '{print $2}' /var/tmp/$0.pid)
Regarding the problem with while [ $count -le 4 ]
, take into account what Keith Thompson comments:
이
[: -lt: unexpected operator
있기 때문에 아마$count
때문에 이전 오류로 비어 있습니다. 주장을 인용하면 다음을 피할 수 있습니다.while [ "$count" -le 4 ]
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다