1

我正在编写代码来自动化一些步骤。首先需要切换用户,然后运行 ​​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"

但是一旦我手动执行此步骤然后运行此脚本,则此脚本运行时不会出现任何错误。

4

1 回答 1

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
于 2013-10-08T13:54:05.430 回答