简体   繁体   English

使用“脚本”命令后如何继续执行脚本

[英]How to continue execution of a script after using 'script' command

so I am writing a bash script to create some VMs and I need to log my command line's output so at a certain point I am trying to use script command, but it cuts my script off until i exit the command, is there a way to continue execution of my script and log my command line?所以我正在编写一个 bash 脚本来创建一些虚拟机,我需要记录我的命令行的输出,所以在某个时候我试图使用script命令,但它会切断我的脚本,直到我退出命令,有没有办法继续执行我的脚本并记录我的命令行?

The script looks like:该脚本如下所示:

script screen.log
for i in 1 2 3
do
onetemplate instantiate "mano"  --user $CUSER --endpoint $CENDPOINT
done
exit

and i need to cut it at exit.我需要在退出时剪掉它。

Just script starts a new shell.只是script启动一个新的shell。 To have script run a command use script -c command .要让script运行命令,请使用script -c command This is all documented in the manual page .这一切都记录在 手册页中

You may want to try:您可能想尝试:

export CUSER=...
export CENDPOINT=...
script screen.log <<\EOF
for i in 1 2 3
do
  onetemplate instantiate "mano"  --user $CUSER --endpoint $CENDPOINT
done
EOF

(The export is required to make the variables CUSER and CENDPOINT available in the shell run by script .) (需要export以使变量CUSERCENDPOINTscript运行的 shell 中可用。)

What if I used the -c option, how would i do it, because if i use it like 如果我使用了-c选项,该怎么办,因为如果我像这样使用它

 script -c onetemplate instantiate "mano" --user xxxxxx --endpoint xxxxxx

it says that --user is unrecognized option 它说--user是无法识别的选项

What if I used the -c option, how would i do it, because if i use it like如果我使用 -c 选项,我会怎么做,因为如果我像这样使用它

script -c onetemplate instantiate "mano" --user xxxxxx --endpoint xxxxxx

it says that --user is unrecognized option它说 --user 是无法识别的选项

You'd have to quote the entire command, eg你必须引用整个命令,例如

script -c "onetemplate instantiate mano --user xxxxxx --endpoint xxxxxx"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM