1

所以我有 NVIDIA 的 CUDA API 的三个安装程序——第一个是一个驱动程序,带有很好的静默安装标志选项(但你必须是 root 并且必须有运行级别 3)。

下面显示了下面的后两个手动安装(为简洁起见,省略了之后安装的冗长混乱)

[root]# sh cudatoolkit_4.1.28_linux_64_rhel5.x.run 验证存档完整性...一切都很好。解压缩 NVIDIA CUDA................................................................. ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ………………………………………………………………………………………………………………………………………………
Enter install path (default /usr/local/cuda, '/cuda' will be appended):
A previous version of CUDA was found in /usr/local/cuda/bin
你想卸载吗?(是/否/中止):是

换句话说,我需要识别:“输入安装路径”并输出一个 '\n'

现在棘手的部分是卸载可能并不总是存在。如果不是,我只需等待安装完成,但如果我看到“你想卸载吗?” 我需要输出“是”才能完成。

第三个也是最后一个安装程序的输出如下所示....

[root]# sh gpucomputingsdk_4.1.28_linux.run
验证存档完整性...一切都好。
解压缩 NVIDIA GPU 计算

开发工具包.................................................. ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ................................................................ ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ........................................................................................................ ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... …………..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... …………..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... …………..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... …………..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... …………..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... …………..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... …………..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... …………..................................................... …………..................................................... …………

输入安装路径(默认 ~/NVIDIA_GPU_Computing_SDK): /usr/local/CUDA_SDK

CUDA 位于 /usr/local/cuda
如果正确,请选择下面的默认值。
如果不正确,输入正确的CUDA

路径输入CUDA安装路径(默认/usr/local/cuda):

对于这个,没有卸载操作,所以看起来有点简单。

我只需要检测“输入安装路径”并输出“/usr/local/CUDA_SDK\n”,然后检测“输入CUDA安装路径”并输出“\n”

我的想法是使用一对期望脚本——每个安装程序一个——但由于命令的双引号内嵌套切换到 root,我在这方面遇到了一些困难。我目前拥有的是:

#!/bin/bash
CR="\"\n\""
YES="\"Yes\""
INSTALL_PATH_REQUEST="\"Enter install path\""
CUDA_PATH_REQUEST="\"Enter CUDA install path\""
UNINSTALL_REQUEST="\"Would you like to uninstall?\""
TOOLKIT=`ls -t cudatoolkit* | head -n 1`
TOOLKIT_EXPECT="sh $TOOLKIT"
SDK=`ls -t gpucomputingsdk* | head -n 1`
SDK_INSTALL_PATH="\"/usr/local/CUDA_SDK\n\""
SDK_EXPECT="sh $SDK"
/bin/su root -c "yum -q -y install expect expectk;
/sbin/init 3; sh `ls -t NVIDIA*|head -n 1` -s --update -a -X;
/usr/bin/expect <<EOF;
spawn $TOOLKIT_EXPECT
expect $INSTALL_PATH_REQUEST
send $CR
expect $UNINSTALL_REQUEST
send $YES
EOF
/usr/bin/expect <<EOF;
spawn $SDK_EXPECT
expect $INSTALL_PATH_REQUEST
send $SDK_INSTALL_PATH
expect $CUDA_PATH_REQUEST
send $CR
EOF
/sbin/init 5"

这将正确切换到 root(一旦输入密码)并正确安装带有内置选项的驱动程序。然后它似乎产生了第二个安装过程并输入第一个参数(回车),但似乎过早地退出了第二个安装程序(例如,我没有看到“是”选项。)。

我觉得我已经很接近了,希望有人能指出我出错的地方并建议正确的语法。

注意: 我添加了 yum install 命令,因为我正在安装的一些机器没有预料到(库存CentOS 6),这样我就省去了那里的麻烦......

4

1 回答 1

3

此处可能是超时问题...不确定安装程序需要多长时间。
默认的预期超时为 10 秒,如果在该时间内没有看到预期的文本,它将继续进行,您可以像这样更改超时值:

expect -timeout 100 $INSTALL_PATH_REQUEST

也改变你的 $YES 从

YES="\"Yes\""

到:

YES="\"Yes\r\""

(最好在 $CR 中也使用 \r 而不是 \n)

在安装结束时期待一些“安全字符串”也是一个好主意,例如:

 expect -timeout 320 "Install Complete."

因此,在生成的进程完成之前,expect 脚本不会终止。

于 2012-04-14T05:29:23.730 回答