如何使用expect
和title
执行命令文件(macOS)或类似命令(GNU / Linux)?
现在我用它:
#!/usr/bin/expect -f
set timeout -1
spawn rm -rf /path/to/.ssh/known_hosts
spawn ssh username@IP
expect "?"
send "yes\r"
expect "assword:"
send "thepassword\r"
expect "thenamemachine:~#"
send "bash <(curl -s aFile.sh)\r"
interact
但是如何添加此
title='My first title'
echo -n -e "\033]0;$title\007"
因为这不起作用
#!/usr/bin/expect -f
title='My first title'
echo -n -e "\033]0;$title\007"
set timeout -1
spawn rm -rf /path/to/.ssh/known_hosts
spawn ssh username@IP
expect "?"
send "yes\r"
expect "assword:"
send "thepassword\r"
expect "thenamemachine:~#"
send "bash <(curl -s aFile.sh)\r"
interact
答案 0 :(得分:1)
您需要在expect脚本中使用tcl语法,而不是shell。你想要:
set title "My first title"
send_user "\033]0;$title\007"
此外,您无需与rm -rf
进行任何互动,因此请使用exec
代替spawn
:
exec rm -rf /path/to/.ssh/known_hosts