如何在使用'script'命令后继续执行脚本

问题描述 投票:1回答:2

所以我正在写一个bash脚本来创建一些虚拟机,我需要记录我的命令行的输出,所以在某一点我试图使用script命令,但它切断我的脚本,直到我退出命令,有没有办法继续执行我的脚本并记录我的命令行?

该脚本如下所示:

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

我需要在退出时切断它。

linux bash
2个回答
0
投票

只是script开始一个新的外壳。要让script运行命令,请使用script -c命令。这都记录在manual page中。

你可能想尝试:

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

export需要在CUSER运行的shell中提供变量CENDPOINTscript。)


0
投票

如果我使用-c选项,我该怎么做呢,因为如果我使用它就像

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

它说 - 用户是无法识别的选项

© www.soinside.com 2019 - 2024. All rights reserved.