我正在编写代码以自动执行某些步骤。首先,需要切换用户然后运行perl脚本。这是我的代码
if [ -a /try/Test ]
then
su trial -c ". /try/.profile Test"
expect -c 'spawn try1;
send "3\r";
send "1\r";
send "show\r";
interact';
fi
try1是我试图调用的perl程序。这个脚本抛出了这个错误
couldn't execute "try1": no such file or directory
while executing
"spawn try1"
但是一旦我手动执行此步骤然后运行此脚本,则此脚本运行时不会发生任何错误。
答案 0 :(得分:1)
我想你已经问了这个问题(我确实回答了,不是吗?)
这是基本框架(确保添加错误/超时/意外输出处理):
# collect password
stty -echo
send_user -- "Password: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set pass $expect_out(1,string)
spawn sudo sh;
expect -re ": *$";
send -- "$pass\r"
expect -re "\$ *$";
send "echo SETTING PARAMS\r";
expect -re "\$ *$";
send "echo RUNNING MY COMMAND\r";
expect -re "\$ *$";
interact