Esperar script não está funcionando

0

Oi Durante a execução espere arquivo estou recebendo abaixo mensagem de erro:

charanjit@charanjit-Inspiron-N5110:~$ expect copy_file1.exp charanjit pa$$w0rd
spawn /usr/bin/ssh [email protected]
[email protected]'s password: 
Last login: Wed Nov 29 03:49:13 2017 from 192.168.122.1
[charanjit@centos7srv1 ~]$ spawn /usr/bin/sudo /bin/su -
[sudo] password for charanjit: pa$$w0rd
can't read "pass": no such variable
    while executing
"send "$pass\r""
    (procedure "dostuff" line 8)
    invoked from within
"dostuff { $host }"
    invoked from within
"expect {

        "no)? " {
           send -- "yes\r"
        }

        "password: " {
            send -- "$password\r"
        }
        ..."
    ("foreach" body line 6)
    invoked from within
"foreach host [split $hosts "\n" ] {

    spawn /usr/bin/ssh $user@$host

    while (1) {
        expect {

        "no)? " {
           send -- "ye..."
    (file "copy_file1.exp" line 33)
charanjit@charanjit-Inspiron-N5110:~$ pa$$w0rd
pa$$w0rd: command not found
charanjit@charanjit-Inspiron-N5110:~$ 

Abaixo está minha saída de script esperada:

    #!/usr/bin/expect -f   
    set timeout 20 
    set user [lindex $argv 0] 
    set password [lindex $argv 1] 
    set prompt "$ "   ;
    # -- main activity   proc dostuff {currenthost} {
         ;# do something with currenthost
         spawn /usr/bin/sudo /bin/su -

       expect "password:"    
     send "$pass\r"    
     interact    
     send -- "cp -v /tmp/http_proxy.sh /etc/profile.d/ && chown root:root /etc/profile.d/http_proxy.sh && chmod +x /etc/profile.d/http_proxy.sh \r"    
    return



    }   

;# -- start of task   
set fd [open ./hostlist r] set hosts [read
    -nonewline $fd] close $fd
        foreach host [split $hosts "\n" ] {

        spawn /usr/bin/ssh $user@$host

        while (1) {
            expect {

            "no)? " {
               send -- "yes\r"
            }

            "password: " {
                send -- "$password\r"
            }

            "$prompt" {
               dostuff { $host }
               break
            }
          }    }
         expect "$prompt"    
  send -- "exit\r"   
}   
expect eof

Eu quero usar este script para colocar o arquivo http_proxy.sh no diretório /etc/profile.d/ em todos os 300 servidores Linux.

Obrigado & amp; Saudações CJ

    
por Charanjit Cheema 28.11.2017 / 22:35

0 respostas