2011-05-16 2 views
0
내가 전에 그러나 기계
  • 스와로

    은 뿌리와 수행 SU로 스크립트를 기대 나오지

    • SSH를 근절하기 위해 많은 호스트 목록은 다음을 수행하는 스크립트를 필요로 기대하는 사용한 적이

      및 루트 암호를 입력

    • 이 예제 그냥 원래의 텍스트가

    를 newText

  • 텍스트로 대체 할 텍스트입니다 말할 수를 위해, 다른 텍스트와 텍스트를 대체하기 위해/etc/passwd에있는 파일을 나오지도 누구든지 도와 줄 수 있습니까?

    답변

    2

    분명히 명령을 루트로 처리하는 스크립트를 실행하는 것은 큰 보안 문제이며 일반적으로 허용되지 않습니다.

    그러나, Expect은 가상 터미널을 실행할 수 있으므로 사람이 키보드로 타이핑 할 때처럼 행동 할 수 있습니다.

    이 질문은 다소 질문했지만 테스트되지 않았습니다. 그것은 나를라면

    #!/bin/sh 
    # if run from shell, restart with wish \ 
    exec wish "$0" "[email protected]" 
    
    package require Expect 
    
    proc fix_a_host {host usrname password root_password} { 
         # open session to host, wait for a username prompt 
         spawn ssh $host 
         expect "username:" 
    
         # send username, wait for a password prompt 
         send "$usrname\r" 
         expect "password:" 
    
         # send password, wait for shell prompt 
         send "$password\r" 
         expect "%" 
    
         # become root, wait for prompt 
         send "su\r" 
         expect "#" 
    
         # change TEXT to NEWTEXT in password file 
         send "sed 's/TEXT/NEWTEXT'" /etc/passwd 
         expect "#" 
    
         # exit root, exit host connection 
         send "exit\r" 
         expect "%" 
    
         send "exit\r" 
         expect eof 
    }  
    
    fix_a_host {"host1" "someuser" "user_password" "root_password"} 
    fix_a_host {"host2" "someuser" "user_password" "root_password"} 
    

    , 나는 그것이 잘 작동 확신 할 때까지 훨씬 덜 파괴, grep TEXT /etc/passwd 같은에 나오지 명령을 변경할 것입니다. 보고 싶은 출력을 표시하는 원격 명령의 경우

    set results $expect_out(buffer) 
    send "some_command\r" 
    expect "#" # use the command prompt to indicate output is complete 
    puts "command output is got `$buffer`" 
    
    +0

    감사합니다. – jaxxstorm

    관련 문제