title: Expect script does not work under crontab
body: <p>I have an <strong>expect script</strong> which I need to run every 3 mins on my management node to collect tx/rx values for each port attached to DCX Brocade SAN Switch using the command <code>#portperfshow#</code></p>
  
  <p>Each time I try to use <strong>crontab</strong> to execute the script every 3 mins, the script does not work!</p>
  
  <p>My expect script starts with <code>#!/usr/bin/expect -f</code>  and I am calling the script using the following syntax under cron:</p>
  
  <pre><code>3 * * * * /usr/bin/expect -f /root/portsperfDCX1/collect-all.exp sanswitchhostname 
  </code></pre>
  
  <p>However, when I execute the script (not under cron) it works as expected:</p>
  
  <pre><code>root# ./collect-all.exp sanswitchhostname
  </code></pre>
  
  <p>works just fine.</p>
  
  <p>Please Please can someone help! Thanks.</p>
  
  <hr>
  
  <p>The script collect-all.exp is:</p>
  
  <pre class="lang-tcl prettyprint-override"><code>#!/usr/bin/expect -f
  
  #Time and Date
  set day [timestamp -format %d%m%y]
  set time [timestamp -format %H%M]
  
  #logging
  set LogDir1 "/FPerf/PortsLogs"
  et timeout 5
  set ipaddr [lrange $argv 0 0]
  set passw "XXXXXXX"
  
  
  if { $ipaddr == "" } {
          puts "Usage: &lt;script.exp&gt; &lt;ip address&gt;\n"
          exit 1
  }
  
  
  spawn ssh admin@$ipaddr
  expect -re "password"
  send "$passw\r"
  
  expect -re "admin"
  
                  log_file "$LogDir1/$day-portsperfshow-$time"
                  send "portperfshow -tx -rx -t 10\r"
                  expect timeout "\n"
                  send \003
                  log_file
  
                  send -- "exit\r"
                  close
  </code></pre>