여러 대의 Liux 서버 파일 을 일괄 삭제 합 니 다.

다음으로 이동:http://17610376.blog.51cto.com/366886/718266
deletefile 
자동 삭제 / recordfile / 아래 디 렉 터 리 에 31 일 이전 파일 의 스 크 립 트 입 니 다.모 서버 에 놓다

  
  
  
  
  1. #!/bin/bash  
  2. #to delete files with is 30 day ago  
  3. cd /record_file/  
  4. for i in `ls`   
  5. do  
  6.     cd /record_file/$i  
  7.     echo `pwd`     
  8.     find ./ -mtime +31 > filelist  
  9.     sleep 2  
  10.     rm -rf `cat filelist`  
  11.     sleep 10  
  12. done 

expect_run.exp
한 서버 에서 deletefile 파일 을 원 격 서버 로 대량으로 복사 하고 실행 하 는 스 크 립 트 입 니 다.

  
  
  
  
  1. #!/usr/tcl/bin/expect  
  2. set timeout 2  
  3. set host [lindex $argv 0]  
  4. set user [lindex $argv 1]  
  5. set password [lindex $argv 2]    
  6. spawn ssh $user@$host  
  7. # Enable this and Disable the "spawn ssh ..." above if you are using ssh-key.  
  8. #spawn ssh -i ssh-key/Identity.ppk -p $port $user@$server  
  9. expect {  
  10.         "yes/no)?\ " {send "yes\r";exp_continue}  
  11.         "*assword:\ " {send "$password\r"}  
  12.         }  
  13. expect "]*"  
  14. send "scp [email protected]:/home/deletefile /home\r"  
  15. expect {  
  16.         "yes/no)?\ " {send "yes\r";exp_continue}  
  17.         "*assword:\ " {send "123456\r"}  
  18.         }  
  19. expect "]*"  
  20. send  "cd /home/\r"  
  21. send  "nohup ./deletefile &\r"  
  22. expect eof 

 run.sh   expect 호출run. exp 의 주 스 크 립 트

  
  
  
  
  1. #!/bin/sh  
  2. cat ip.txt | while read ip user password  
  3. do  
  4.           ./expect_run.exp $ip $user $password  
  5. done 

ip.txt   설명 하지 않 음, 호스트 목록

  
  
  
  
  1. 100.2.3.92  root   123456  
  2. 100.2.3.94  root    123456  
  3. 100.2.3.93  root    123456  
  4. 100.2.3.89  root    123456  
  5. 100.2.3.88  root    123456  
  6. 100.2.3.87  root    123456  
  7. 100.2.3.90  root    123456  
  8. 。。。。 

expect 의 설치 및 사용 (tcl 8.5.10 컴 파일 이 성공 하지 못 할 수도 있 음 을 알려 줍 니 다.
이 버 전
A. Tcl 설치 하 다.
홈 페이지: 
http://www.tcl.tk
다운로드 주소: 
http://www.tcl.tk/software/tcltk/downloadnow84.tml
1. 원본 패키지 다운로드
wget 
http://nchc.dl.sourceforge.net/sourceforge/tcl/tcl8.4.11-src.tar.gz
wget 
http://nchc.dl.sourceforge.net/sourceforge/tcl/tk8.4.11-src.tar.gz
2. 압축 해제 소스 패키지
tar xfvz tcl8.4.11-src.tar.gz
tar xfvz tk8.4.11-src.tar.gz
3. 설치 설정
cd tcl8.4.11
cd unix
./configure --prefix=/usr/tcl --enable-shared
make
make install
설치 가 끝 난 후 tcl 소스 코드 의 루트 디 렉 터 리 에 들 어가 하위 디 렉 터 리 유 닉 스 아래 tclUnixPort. h 하위 디 렉 터 리 generic 에 복사 합 니 다.
당분간 tcl 소스 코드 를 삭제 하지 마 십시오. expect 의 설치 과정 이 필요 하기 때 문 입 니 다.
B. expect 설치 하 다. (Tcl 라 이브 러 리 필요)
홈 페이지: 
http://expect.nist.gov/
1.
원본 패키지 다운로드
Wget
 
http://nchc.dl.sourceforge.net/project/expect/Expect/5.45/expect5.45.tar.gz
2. 압축 해제 소스 패키지
tar xfvz expect
5.45
.tar.gz
3. 설치 설정
cd expect-5.4
5
./configure --prefix=/usr/expect --with-tcl=/usr/tcl/lib  --with-tclinclude=
/ tcl 소스 코드 경로 / generic
make
make install

좋은 웹페이지 즐겨찾기