Note that there are some explanatory texts on larger screens.

plurals
  1. POFormatting Expect Script Inside of User Command in Bash Script
    text
    copied!<p>So I have three installers for NVIDIA's CUDA API -- the first is a driver and comes with nice silent install flag options (but you have to be root and have to have run level 3).</p> <p>The second two follow are shown manually installing below (cut out the long mess of install afterwards for brevity)</p> <blockquote> <p>[root]# sh cudatoolkit_4.1.28_linux_64_rhel5.x.run Verifying archive integrity... All good. Uncompressing NVIDIA CUDA.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................<br/> Enter install path (default /usr/local/cuda, '/cuda' will be appended):<br/> A previous version of CUDA was found in /usr/local/cuda/bin<br/> Would you like to uninstall? (yes/no/abort): yes</p> </blockquote> <p>In other words, I need to recognize: "Enter install path" and output a '\n'</p> <p>Now the tricky part is the uninstall may not be always be there. If it's not I need to simply wait for the install to finish, but if I see "Would you like to uninstall?" I need to output "yes" to complete.</p> <p>The third and final installer's output is shown below....</p> <blockquote> <p>[root]# sh gpucomputingsdk_4.1.28_linux.run<br/> Verifying archive integrity... All good.<br/> Uncompressing NVIDIA GPU Computing <br/><br/>SDK............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................<br/> <br/> Enter install path (default ~/NVIDIA_GPU_Computing_SDK): /usr/local/CUDA_SDK<br/> <br/> Located CUDA at /usr/local/cuda<br/> If this is correct, choose the default below.<br/> If it is not correct, enter the correct path to CUDA<br/> <br/> Enter CUDA install path (default /usr/local/cuda):<br/></p> </blockquote> <p>For this one, there is no uninstall action so it's seemingly a bit simpler.</p> <p>I just need to detect "Enter install path" and output "/usr/local/CUDA_SDK\n" and then detect "Enter CUDA install path" and output "\n"</p> <p>My idea was to use a pair of expect scripts -- one for each installer -- but due to the nesting within the double quotes of the command to switch to root, I'm having some difficulties with this. What I currently have is:</p> <pre><code>#!/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 &lt;&lt;EOF; spawn $TOOLKIT_EXPECT expect $INSTALL_PATH_REQUEST send $CR expect $UNINSTALL_REQUEST send $YES EOF /usr/bin/expect &lt;&lt;EOF; spawn $SDK_EXPECT expect $INSTALL_PATH_REQUEST send $SDK_INSTALL_PATH expect $CUDA_PATH_REQUEST send $CR EOF /sbin/init 5" </code></pre> <p>This switches to root properly (once the password is entered) and installs the driver with the built in options correctly. It then appears to spawn the second install process and enter the first argument (a carriage return), but seems to exit the second installer prematurely (e.g. I don't see the "yes" option.).</p> <p>I feel like I'm pretty close, hopefully somebody can point me to where I'm going wrong and suggest the correct syntax.</p> <p><strong>NOTES:</strong> I added the yum install command, as some of the machines I'm installing on didn't have expect (stock <code>CentOS 6</code>), so that saves me the trouble there....</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload