반응형



아직 포스팅할 내용들이 많지만..

db 연결 방법이 궁금해서 아주 간단한 mysql 연결 shell script 를 찾았습니다.


음.. 일단 mysql 서비스가 실행 한다는 가정하에.. dbtest.sh 라는 파일을 만듭니다.


vim dbtest.sh

 + dbtest.sh                                                                      

  1 #!/bin/bash

  2 mysql -u root redCat<<EOFMYSQL

  3 select * from MenuItem;

  4 EOFMYSQL


스크립트를 작성 후, 내용을 저장 한 뒤 권한을 바꿔줍니다. 

좀더 편리하게 만들 예정입니다만, 일단 가장 간단한 스크립드를 먼저 공유합니다.


chmod 700 dbtest.sh


제 맥에서 돌고 있는 mysql 서비스엔 redCat 이라는 데이터베이스가 있습니다. redCat 데이터 베이스 안에 있는 MenuItem 테이블의 내용을 모두 성공적으로 화면에 보여주었네요.


이상입니다. 

반응형
반응형

Shell Script 의 기본


bash-4.1$ x=3
bash-4.1$ echo $x
3


bash-4.1$ echo "hello     there"
hello     there

bash-4.1$ echo 'hello     there'
hello     there
bash-4.1$ echo hello      there
hello there


bash-4.1$ echo "the value of x:     $x"
the value of x:     3
bash-4.1$ echo 'the value of x:     $x'
the value of x:     $x
bash-4.1$ echo 'I have $10000'
I have $10000


bash-4.1$ echo Today is `date`
Today is Wed Aug 6 12:50:46 EST 2014
bash-4.1$ echo "Today is `date`"
Today is Wed Aug  6 12:51:00 EST 2014




permission

bash-4.1$ ls -l
total 2
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

bash-4.1$ chmod 600 a.txt
bash-4.1$ ls -l
total 2
-rw-------+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

bash-4.1$ chmod 644 a.txt
bash-4.1$ ls -l
total 2
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 a.txt
-rw-r--r--+ 1 11776352 Students   0 Jul 30 13:06 c.txt
-rw-r--r--+ 1 11776352 Students 334 Aug  6 12:40 hello.txt

first --- user (u)
second --- group (g)
third --- other (o)

0 000
1 001 * execute = 1
2 010 * write = 2
3 011
4 100 * read = 4
5 101
6 110
7 111

readable, writable, executable = 4+2+1 = 7 (rwx)

chmod 755 myfile
chmog o+x myfile
chmog o-x myfile



Script 실행


bash-4.1$ hello.sh
bash: hello.sh: command not found
bash-4.1$ pwd
/home/11776352/usp/2
bash-4.1$ /home/11776352/usp/2/hello.sh
hello world
bash-4.1$ cd ..
bash-4.1$ 2/hello.sh
hello world
bash-4.1$ cd 2/
bash-4.1$ ls
a.txt  c.txt  hello.sh    hello.txt
bash-4.1$ ../2/hello.sh
hello world
bash-4.1$ ./hello.sh
hello world


 Script 응용




반응형

+ Recent posts