스크립트 질문이 처음 임 : BASH 스크립트에서 'else'가 필요하지 않음


1

가능하면 누군가 도울 수 있습니다. 이 스크립트에있는 문제를 해결하려고합니다. 나는 '그렇지 않다'고 기대하지 않지만 논리는 의미가있는 것 같습니다.

스크립팅은 모두 새로운 것이지만 CPU가 과도하게 실행되는 문제를 해결하려고합니다.

오류:

Do you want to set global CPU limitations y or n : y
./LIMIT A SINGLE PROCESS.sh: line 28: syntax error near unexpected token `elif'
./LIMIT A SINGLE PROCESS.sh: line 28: `elif test "$y" = "n" ; then'

스크립트:

#!/bin/bash
# CPU limit of a process of one application or set global limit
#
# 
DAEMON_INTERVAL=3   # Daemon check interval in seconds

# gnome-terminal -x top

read -p "Do you want to set global CPU limitations y or n : " y

if test "$y" = "y" ; then

    read -p "Enter Global CPU limit :" CPU_LIMIT_ALL 
    echo $'\nAll Processes shall be limited to:' $CPU_LIMIT_ALL 

 while true
      do
       PID_1="top -b -n1 -c | awk 'NR>6 && \$9>CPU_LIMIT_ALL {print \$1}' CPU_LIMIT_ALL=$CPU_LIMIT_ALL"       # Set global CPU limit reads TOP list 
       NEW_PIDS=$(eval "$PID_1")                                                                               # Violating PIDs
       LIMITED_PIDS=$(ps -eo args | gawk '$1=="cpulimit" {print $3}')       
                                          # Already limited PIDs                                                   
       QUEUE_PIDS=$(comm -23 <(echo "$NEW_PIDS" | sort -u) <(echo "$LIMITED_PIDS" | sort -u) | grep -v '^$')   # PIDs in queue

   for i in $QUEUE_PIDS
      do
       cpulimit -p "$i" -l "$CPU_LIMIT_ALL" -z &   # Limit new violating processe 
done

elif test "$y" = "n" ; then

    read -p  "Enter process to be restricted or press enter :" r
    read -p  "Enter value of CPU limit or press enter :" l

   while true
    do
     echo $'\nProcess Entry Found' 
     echo $'CPU Entry Found\n'

     echo "Limit the Process of: $r to $l"  

     cpulimit --exe "$r" -b -l "$l" -z &                    # Set CPU limit for process
     sleep 60
done

else
  echo "No input found" 
  exit 1
fi

답변:


3

done28 번 줄에서 elif 앞에 누락 된 부분이 있다고 생각합니다 done. for루프에는 하나 있지만 donewhile 루프 에는 없습니다 .


0

완료하는 동안 "while"주기를 닫지 않았습니다. 거기에 또 다른 "for"가 있습니다.

들여 쓰기를 올바르게하지 않으면 이러한 오류가 발생합니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.