The driver has not received any packets form the server. 요류가 발생할 시 


 1) DB가 기동되어 있지않거나,

 2) MySQL 커녞터(JDBC 드라이버) 버전 문제,

 3) MySQL이 로컬호스트(120.0.01)로만 접속 허용,

 4) 톰캣의 보안설정 문제등 이라고 포스팅되어 있었습니다.


[출처 : https:open.egovframe.go.kr/nforges/qna/qna/7017/.do]


저 같은 경우는 3번이 문제 였습니다.


해결책

  vi /etc/mysql/mysql.conf.d/mysqld.cnf <-- 이 안으로 들어가서


# Instead of skip-networking the default is now to listen only on

# localhost which is more compatible and is not less secure.

#(요부분 주석처리)bind-address           = 127.0.0.1




  



'리눅스' 카테고리의 다른 글

쉘 레벨 및 변수  (0) 2017.06.09
Bash For Loop 예제  (0) 2017.06.05

쉘 스크립트 부분에 대한 전반적인 내용은 유닉스 리눅스 사용에서 프로그래밍까지(창병모 저)라는 책을 참조하며 작성하였다.

쉘 스크립트(shell script)는 쉘이나 명령 줄 인터프리터에서 돌아가도록 작성되었거나 한 운영 체제를 위해 쓰인 스크립트이다. 단순한 도메인 고유 언어로 여기기도 한다. 쉘 스크립트가 수행하는 일반 기능으로는 파일 이용, 프로그램 실행, 문자열 출력 등이 있다.1


장점

쉘 스크립트를 기록하는 것은 다른 프로그래밍 언어의 같은 코드로 쓰인 것보다 훨씬 더 빠른 경우가 많다. 다른 해석 언어에 비해, 쉘 스크립트는 컴파일 단계가 없기 때문에 스크립트는 디버깅을 하는 동안 빠르게 실행할 수 있다.

또한 Python과 같이 독립적으로 설치할 필요가 없기 때문에 쉘 자체가 프로그램 개발 툴로 사용할 수 있다.


단점

한 가지 단점으로는 실행되는 각 명령에 대한 잠재적으로 새로운 하부 프로세스의 수많은 필요에 따라 속도가 느려질 수 있다.

단순 sh 스크립트는 다양한 종류의 유닉스, 리눅스, BSD 운영 체제, therof 버전, 시스템 유틸리티와 잘 호환된다는 장점이 있지만 더 복잡한 쉘 스크립트는 쉘, 유틸리티, 다른 필수 요소 간의 약간의 차이가 많은 경우 실패할 가능성이 있다. 레리 월은 다음과 같은 유명한 말을 남겼다: “쉘 스크립트보다 쉘을 포팅하는 게 더 쉽다”

이와 비슷하게, 더 많은 복잡한 스크립트들은 쉘 스크립트 언어 자체의 제한 안에서 실행할 수 있다. 이러한 제한 때문에 다양한 쉘이 문제를 개선할 목적으로 고품질의 코드와 확장을 기록하기 힘들 수 있다.

01 쉘 레벨 및 변수

쉘에서 쉘을 재귀적으로 실행할 수 되며 이는 #echo $SHLVL이라는 명령어를 통해서 현재 쉘의 쉘 레벨을 확인할 수 있다.

screenshot screenshot

쉘의 변수는 환경변수와 지역변수 두 종류로 나눌 수 있는데 환경 변수는 값이 자식 프로세스에게 상속되며 지역변수는 그렇지 않다.

screenshot

#export [변수명]=[값]을 통해 변수를 선언하게 되면 쉘 레벨과 관계없이 변수 공유가 가능하다.

screenshot

쉘 스크립트의 변수는 다음과 같은 특징을 가진다.

  • 타입이 존재하지 않음 (문자열로 취급)
  • 대소문자 구별
  • 미리 선언할 필요가 없음
  • 변수 사용은 $[변수명]
  • 정의는 [변수명]=[값]

리스트 변수 (list varialbe)

한 변수에 여러 개의 값 (문자열)을 저장할 수 있는 변수

  # 이름=(단어리스트)
        ex) # cities=(서울 부산 인천)
리스트 사용의미
${name[i]}리스트 변수 name의 i번째 원소 (i=0, 1…)
${name[*]}“$1 $2 …” 리스트 변수 name의 모든 원소
${name[@]}“$1” “$2” … 리스트 변수 name의 모든 원소
${#name[*]}리스트 변수 name 내의 원소 개수
${#name[@]}리스트 변수 name 내의 원소 개수

표준 입력 읽기 (read 명령어)

표준입력에서 한 줄을 읽어서 단어들을 변수들에 순서대로 저장하며 남은 단어들은 마지막 변수에 모두 저장한다.

  # read 변수1, ...., 변수n
            ex) # read x y
                Merry Christmas!

사전 정의 환경변수 (의미가 정해진 환경변수)

이름의미
$USER사용자 이름
$TERM터미널 타입
$PATH명령어를 검색할 디렉터리들의 리스트
$HOME홈 디렉터리
$SHELL로그인 쉘의 경로명
$MAIL메일 박스의 경로명
$HOSTNAME호스트 이름

사전 정의 지역변수

이름의미
$$쉘의 프로세스 번호
$0쉘 스크립트 이름
$1 ~ $9명령줄 인수
$*모든 명령줄 인수 리스트
$# 명령줄인수의 개수

02 산술 연산

앞으로 나오는 연산이나 조건문, 반복문등, 앞선 변수 모두 띄어쓰기를 확실하게 구분하여야 오류가 발생하지 않는다.
그리고 쉘 스크립트에서는 일반적으로 인자나 변수는 문자열 취급하기 때문에 다른 방식으로 연산을 한다.

본 쉘의 산술 연산

$ a=2+3
$ echo $a
$ a=`expr 2 + 3` (반드시 빈칸)

콘 쉘의 let 명령어를 이용한 산술 연산

$ let 변수=수식
$ let a=2*3
$ echo $a
6

콘 쉘의 let “수식”을 이용한 산술 수식

((수식)) = let " 수식 "

if (( $# != 1 ))
then
fi

변수 타입 선언 (declare)

$ declare -i a (a는 정수형 변수)
$ a=12
$ a=a+1 (let 필요 없음)
$ echo $a
이름의미
declare -r 변수읽기 전용 변수로 선언
declare -i변수정수형 변수로 선언
declare -a 변수배열 변수로 선언
declare -f스크립트 안에정의된 모든 함수들을 보여준다.
declare -f 함수해당 함수 내용을 보여준다.
declare -x 변수환경변수로 export

03 비교 연산

산술 비교 연산

산술 비교 연산자의미
정수1 -eq정수2두 정수가 같으면 참 아니면 거짓
정수1 -ne 정수2두 정수가 다르면 참 아니면 거짓
정수1 -gt 정수2정수1이 정수2보다 크면 참 아니면 거짓
정수1 -ge 정수2정수1이 정수2보다 크거나 같으면 참 아니면 거짓
정수1 -lt 정수2정수1이 정수2보다 작으면 참 아니면 거짓
정수1 -le 정수2정수1이 정수2보다 작거나 같으면 참 아니면 거짓

문자열 비교 연산

문자열 비교 연산자의미
문자열1 == 문자열2두 문자열이 같으면 참 아니면 거짓
문자열1 != 문자열2두 문자열이 다르면 참 아니면 거짓
-n 문자열문자열이 null이 아니면 참
-z 문자열문자열이 null이면 참

파일 관련 연산

파일 관련 연산자의미
-a 파일해당 파일이 존재하면 참
-e 파일해당 파일이 존재하면 참
-r 파일사용자가 해당 파일을 읽을 수 있으면 참
-w 파일사용자가 해당 파일을 쓸 수 있으면 참
-x 파일사용자가 해당 파일을 실행할 수 있으면 참
-o 파일사용자가 해당 파일의 소유자이면 참
-z 파일해당 파일의 크기가 0이면 참
-f 파일해당 파일이 일반 파일이면 참
-d 파일해당 파일이 디렉터리이면 참

04 Bash 제어구조

조건문

                if 조건식
                then
                    명령어리스트
                else
                    명령어리스트
                fi

중첩 조건문

                if 조건식
                then
                    명령어리스트
                elfi
                then
                    명령어리스트
                else
                    명령어리스트
                fi

스위치

                case 단어 in
                    패턴1) 명령어리스트;;
                    패턴2) 명령어리스트;;
                    ......
                    *) 명령어리스트;;
                esac

반복문 (for) : 리스트의 각 값에 대해서 명령어들을 반복

                for 변수 in 단어리스트 (모든 명령줄 인수 처리 : $*)
                do
                    명령어리스트
                done

반복문 (while) : 조건에 따라 명령어들을 반복 실행

                while 조건식
                do
                    명령어리스트
                done

반복문 (until) : 조건에 따라 명령어들을 반복 실행

                until 조건식 (조건식을 while문의 정반대로 넣어야 함)
                do
                    명령어리스트
                done

함수

                함수이름()
                {
                    명령어리스트
                }

05 쉘 스크립트 사용 예

#! /bin/bash

FCnt=0
LFlag=0
PFlag=0
IFlag=0
FFlag=0
trash=~/.trash

error ()
{
cat << END
echo 휴지통 관리 프로그램 사용법 :
echo   trash -p : "휴지통 비우기"
echo   trash -i : "휴지통 비우기(확인)"
echo   trash -l : "휴지통 확인"
echo   trash 파일* : "휴지통에 버리기"
END
exit 1
}

for list in $*
do
  case $list in
    "-p")
        PFlag=1
        ;;
    "-i")
    IFlag=1
    ;;
    "-l")
        LFlag=1
        ;;
    "-*")
        echo $list 는 잘못된 옵션
    error
        ;;
    *)
        FFlag=1
        fileList[$FCnt]=$list
        let FCnt=FCnt+1
        ;;
    esac
done

let total=$LFlag+$PFlag+$FFlag+$IFlag
if (( total != 1 ))
then
   error
fi

if [ ! -d $trash ]
then
    'mkdir' $trash
fi

if (( LFlag == 1 ))
then
   'ls' -lgF $trash
   exit 0
fi

if (( PFlag == 1 ))
then
   'rm' $trash/*
   exit 0
fi

if (( IFlag == 1 ))
then
   'rm' -i $trash/*
   exit 0
fi


if ((FFlag == 1 ))
then
   'mv' ${fileList[*]} $trash
   exit 0
fi
exit 0


출처 : http://egaoneko.github.io/os/2015/05/24/linux-starter-guide-8.html by:

Donghyun Seo


'리눅스' 카테고리의 다른 글

mysql 원격접속 오류  (0) 2017.08.26
Bash For Loop 예제  (0) 2017.06.05
예전엔 1부터 10까지 expr를 이용해서 for문 같이 구현했었는데... 이외의 방법들도 많군요~


Bash For Loop Examples

by VIVEK GITE on OCTOBER 31, 2008 · 190 COMMENTS

How do I use bash for loop to repeat certain task under Linux / UNIX operating system? How do I set infinite loops using for statement? How do I use three-parameter for loop control expression?

A 'for loop' is a bash programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement i.e. it is the repetition of a process within a bash script.

For example, you can run UNIX command or task 5 times or read and process list of files using a for loop. A for loop can be used at a shell prompt or within a shell script itself.

for loop syntax

Numeric ranges for syntax is as follows:

for VARIABLE in 1 2 3 4 5 .. N
do
	command1
	command2
	commandN
done

This type of for loop is characterized by counting. The range is specified by a beginning (#1) and ending number (#5). The for loop executes a sequence of commands for each member in a list of items. A representative example in BASH is as follows to display welcome message 5 times with for loop:

#!/bin/bash
for i in 1 2 3 4 5
do
   echo "Welcome $i times"
done

Sometimes you may need to set a step value (allowing one to count by two's or to count backwards for instance). Latest bash version 3.0+ has inbuilt support for setting up ranges:

#!/bin/bash
for i in {1..5}
do
   echo "Welcome $i times"
done

Bash v4.0+ has inbuilt support for setting up a step value using {START..END..INCREMENT} syntax:

#!/bin/bash
echo "Bash version ${BASH_VERSION}..."
for i in {0..10..2}
  do
     echo "Welcome $i times"
 done

Sample outputs:

Bash version 4.0.33(0)-release...
Welcome 0 times
Welcome 2 times
Welcome 4 times
Welcome 6 times
Welcome 8 times
Welcome 10 times

The seq command (outdated)

WARNING! The seq command print a sequence of numbers and it is here due to historical reasons. The following examples is only recommend for older bash version. All users (bash v3.x+) are recommended to use the above syntax.

The seq command can be used as follows. A representative example in seq is as follows:

#!/bin/bash
for i in $(seq 1 2 20)
do
   echo "Welcome $i times"
done

There is no good reason to use an external command such as seq to count and increment numbers in the for loop, hence it is recommend that you avoid using seq. The builtin command are fast.

Three-expression bash for loops syntax

This type of for loop share a common heritage with the C programming language. It is characterized by a three-parameter loop control expression; consisting of an initializer (EXP1), a loop-test or condition (EXP2), and a counting expression (EXP3).

for (( EXP1; EXP2; EXP3 ))
do
	command1
	command2
	command3
done

A representative three-expression example in bash as follows:

#!/bin/bash
for (( c=1; c<=5; c++ ))
do
	echo "Welcome $c times..."
done

Sample output:

Welcome 1 times
Welcome 2 times
Welcome 3 times
Welcome 4 times
Welcome 5 times

How do I use for as infinite loops?

Infinite for loop can be created with empty expressions, such as:

#!/bin/bash
for (( ; ; ))
do
   echo "infinite loops [ hit CTRL+C to stop]"
done

Conditional exit with break

You can do early exit with break statement inside the for loop. You can exit from within a FOR, WHILE or UNTIL loop using break. General break statement inside the for loop:

for I in 1 2 3 4 5
do
  statements1      #Executed for all values of ''I'', up to a disaster-condition if any.
  statements2
  if (disaster-condition)
  then
	break       	   #Abandon the loop.
  fi
  statements3          #While good and, no disaster-condition.
done

Following shell script will go though all files stored in /etc directory. The for loop will be abandon when /etc/resolv.conf file found.

#!/bin/bash
for file in /etc/*
do
	if [ "${file}" == "/etc/resolv.conf" ]
	then
		countNameservers=$(grep -c nameserver /etc/resolv.conf)
		echo "Total  ${countNameservers} nameservers defined in ${file}"
		break
	fi
done

Early continuation with continue statement

To resume the next iteration of the enclosing FOR, WHILE or UNTIL loop use continue statement.

for I in 1 2 3 4 5
do
  statements1      #Executed for all values of ''I'', up to a disaster-condition if any.
  statements2
  if (condition)
  then
	continue   #Go to next iteration of I in the loop and skip statements3
  fi
  statements3
done

This script make backup of all file names specified on command line. If .bak file exists, it will skip the cp command.

#!/bin/bash
FILES="$@"
for f in $FILES
do
        # if .bak backup file exists, read next file
	if [ -f ${f}.bak ]
	then
		echo "Skiping $f file..."
		continue  # read next file and skip cp command
	fi
        # we are hear means no backup file exists, just use cp command to copy file
	/bin/cp $f $f.bak
done

Recommended readings:

  • See all sample for loop shell script in our bash shell directory.
  • man bash
  • help for
  • help {
  • help break
  • help continue

Updated for accuracy!

크리에이티브 커먼즈 라이센스
Creative Commons License


'리눅스' 카테고리의 다른 글

mysql 원격접속 오류  (0) 2017.08.26
쉘 레벨 및 변수  (0) 2017.06.09

+ Recent posts