User Tools

Site Tools


программирование_диалогов_expect

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
программирование_диалогов_expect [2020/01/16 10:34]
val
программирование_диалогов_expect [2022/03/09 12:49] (current)
val [Вариант использования с элементами конфигурации в коде скрипта]
Line 9: Line 9:
  
 ==== Вариант использования с элементами конфигурации в коде скрипта ==== ==== Вариант использования с элементами конфигурации в коде скрипта ====
 +
 +!!! Не обрабатывается ситуация первого подключения (подтверждения ключа)
 +
 <​code>​ <​code>​
 +server# ssh switchN
 +
 server# cat cisco_change_conf.exp server# cat cisco_change_conf.exp
 </​code><​code>​ </​code><​code>​
Line 23: Line 28:
 expect "#"​ { send "ip scp server enable\n"​ } expect "#"​ { send "ip scp server enable\n"​ }
 expect "#"​ { send "​end\n"​ } expect "#"​ { send "​end\n"​ }
 +
 +#expect "#"​ { send "vlan database\n"​ }
 +#expect "#"​ { send "vtp transparent\n"​ }
 +#expect "#"​ { send "vlan 2 name LAN2\n"​ }
 +#expect "#"​ { send "​exit\n"​ }
  
 expect "#"​ { send "​write\n"​ } expect "#"​ { send "​write\n"​ }
Line 48: Line 58:
 send "​\n"​ send "​\n"​
 ... ...
 +</​code>​
 +
 +===== Communigate CLI =====
 +
 +<​code>​
 +mail# cat cgp_cli.exp
 +</​code><​code>​
 +#​!/​usr/​bin/​expect
 +
 +set cmd [lindex $argv 0];
 +
 +spawn telnet localhost 106
 +
 +expect "​200"​ {
 +        send "USER postmaster\n"​
 +}
 +
 +expect "​300"​ {
 +        send "PASS Pa\$\$w0rd\n"​
 +}
 +
 +expect "​200"​ {
 +        send "​$cmd\n\n"​
 +}
 +
 +expect "​200"​ {}
 +
 +sleep 1
 +send "​QUIT\n"​
 +send_user "​\n"​
 +exit 0
 +</​code><​code>​
 +mail# chmod +x cgp_cli.exp
 +
 +mail# ./​cgp_cli.exp '​CREATEACCOUNT user2 {Password = "​password2";​RealName = "​Петр Петрович Петров";​}'​
 +
 +mail# ./​cgp_cli.exp '​GETACCOUNTSETTINGS user2'
 </​code>​ </​code>​
  
 ===== Asterisk AMI ===== ===== Asterisk AMI =====
 +
 +  * [[http://​the-asterisk-book.com/​1.6/​asterisk-manager-api.html#​manager-interface-beispiel-expect|Example:​ Getting the number of voicemail messages with expect]]
 <​code>​ <​code>​
 # cat /​usr/​share/​originate_ami.exp # cat /​usr/​share/​originate_ami.exp
Line 69: Line 118:
 spawn telnet $host $port spawn telnet $host $port
  
-expect "​Manager"​ { send "​Action:​ Login\nUsername: $username\nSecret: $secret\n\n"​ }+expect "​Manager"​ { 
 +        ​send "​Action:​ Login\n" 
 +        send "​Username: $username\n" 
 +        send "​Secret: $secret\n\n"​ 
 +}
  
 expect "​Response:​ Success"​ { expect "​Response:​ Success"​ {
-        send "​Action:​ Originate\nChannel: SIP/​$channel\nContext: default\nExten: $num\nCallerid: $name<​$num>​\nPriority: 1\n\n"+        send "​Action:​ Originate\n" 
 +        send "​Channel: SIP/​$channel\n" 
 +        send "​Context: default\n" 
 +        send "Exten: $num\n" 
 +        send "​Callerid: $name<​$num>​\n" 
 +        send "​Priority: 1\n\n"
 } }
  
-sleep 5+sleep 1
  
 send "​Action:​ Logoff\n\n"​ send "​Action:​ Logoff\n\n"​
Line 82: Line 140:
 </​code><​code>​ </​code><​code>​
 # /​usr/​share/​originate_ami.exp 403 301 "Hello World" # /​usr/​share/​originate_ami.exp 403 301 "Hello World"
 +</​code>​
 +
 +===== Docker ======
 +<​code>​
 +webinar BBB# cat /​root/​scripts/​ch_web_pass.exp
 +</​code><​code>​
 +#​!/​usr/​bin/​expect
 +
 +set email [lindex $argv 0];
 +set password [lindex $argv 1];
 +
 +spawn docker exec -it greenlight-v2 bash
 +send "​\n"​
 +expect "​bash*#"​ {send "​bundle exec rails c\n"}
 +expect "​irb*>"​ { send "​User.find_by(email:​ \"​$email\"​).update_attribute(:​password,​\"​$password\"​)\n"​ }
 +expect "​irb*>"​ { send "​exit\n"​ }
 +expect "​bash*#"​ { send "​exit\n"​ }
 +send_user "​\n"​
 +exit 0
 </​code>​ </​code>​
программирование_диалогов_expect.1579160049.txt.gz · Last modified: 2020/01/16 10:34 by val