질문&답변
클라우드/리눅스에 관한 질문과 답변을 주고 받는 곳입니다.
리눅스 분류

쉘스크립트 실행시 에러 관련

작성자 정보

  • 쉼쉼이 작성
  • 작성일

컨텐츠 정보

본문

무상이~ 님의 글

안녕하세요.

분명 책하고 다른 부분이 거의 없는데 다음과 같은 에러가 뜹니다.

이해를 할 수가 없습니다. 왜 그런가요?

=================================소스===============================

#!/bin/bash

GuGu()
{
        echo " $1  dan"
        echo "====================================="

        num=1
        while [ $num -lt 10 ]
        do
                answer='expr $1 + $num'

                if [ $answer -lt "10" ]
                then
                        answer=" $answer"
                fi
                echo "$1"
                echo "$1  X  $num    =   $answer"

                num='expr $num + 1'
        done
        echo ""
        echo ""
        echo ""
}

        GuGu 1

==============================에러 메세지============================

[root@song shell]# ./gugugu.sh
 1  dan
./gugugu.sh: line 13: [: too many arguments
1
1  X  1    =   expr $1 + $num
./gugugu.sh: line 9: [: too many arguments

소스에서 expr구문 쓰실때 '로 되어있는데요. `로 바꿔주시면 되네요.

answer='expr $1 + $num' 을 answer=`expr $1 + $num`

num='expr $num + 1' 을 num=`expr $num + 1`

그리고요 또 하나 있습니다.

 

#!/bin/bash

while (:)
do

echo "$ftpcount_a"

ftpcount_a='ps -ef | grep vsftpd | wc -l'

$ftpcount_a

if [ $ftpcount -le "1" ]

then


        echo "Vsftpd is restarted."
        echo $ftpcount
        /etc/rc.d/init.d/vsftpd restart
        logger "Vsftpd Restated..."
fi

sleep 5
done

 

 

 

다음은 결과 입니다.

[root@song shell]# ./ftp_check.sh

ERROR: Garbage option.
********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders         -g by session OR by effective group name
-e all processes                      -p by process ID
T  all processes on this terminal     -s processes in the sessions given
a  all w/ tty, including other users  -t by tty
g  OBSOLETE -- DO NOT USE             -u by effective user ID (supports names)
r  only running processes             U  processes for specified users
x  processes w/o controlling ttys     t  by tty
*********** output format **********  *********** long options ***********
-o,o user-defined  -f full            --Group --User --pid --cols --ppid
-j,j job control   s  signal          --group --user --sid --rows --info
-O,O preloaded -o  v  virtual memory  --cumulative --format --deselect
-l,l long          u  user-oriented   --sort --tty --forest --version
-F   extra full    X  registers       --heading --no-heading --context
                    ********* misc options *********
-V,V  show version      L  list format codes  f  ASCII art forest
-m,m,-L,-T,H  threads   S  children in sum    -y change -l format
-M,Z  security data     c  true command name  -c scheduling class
-w,w  wide output       n  numeric WCHAN,UID  -H process hierarchy
./ftp_check.sh: line 12: [: -le: unary operator expected
ps -ef | grep vsftpd | wc -l

 

 

이리 저리 해봐도 찾아봐도 해결을 못해 이렇게 질문 드립니다.

꼭 답변 부탁드립니다^^

ftpcount_a='ps -ef | grep vsftpd | wc -l' 을 ftpcount_a=`ps -ef | grep vsftpd | wc -l` 로 바꿔주세요


에러 대부분이 '와 `을 잘못 써줘서 그런것 같습니다.

두번째 같은경우는 어떤 동작을 하는지 말씀하셔야

좀더 정확하게 에러를 봐드릴수 있어요;


 

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,138 명
  • 현재 강좌수 :  36,196 개
  • 현재 접속자 :  811 명