This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
программирование_диалогов_expect [2020/12/04 19:26] val |
программирование_диалогов_expect [2021/06/15 12:44] val [Communigate CLI] |
||
---|---|---|---|
Line 53: | Line 53: | ||
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> | ||