Question : expect: timeout for pattern action block only?

Is there a way to set a timeout for just a pattern action block independent of (or maybe subordinate to) the global timeout parameter?

set timeout 15

spawn telnet $target

send "\r"
expect {
      "login:"      { send "$AUTOUSER\r" ; exp_continue }
      "ssword:"        { send "$PASSWORD\r"; exp_continue }
      "$->"            { grab_stats }
      timeout            { send_log -- "GARBAGE OR CANNOT CONNECT\n"; exit }  ## Can the  timeout for this default be set up less than the global timeout set above?
      }


Answer : expect: timeout for pattern action block only?

Sure, that would be fine as far as timeouts go. But it's an unfortunate example - when you spawn telnet you get a login: prompt without sending anything. The extra \r elicits another login: prompt. This might confuse your script. Of course, your target system may be different - worth checking.
Double quotes are only for preserving spaces in strings - strings with any other special characters need braces. Also, rather than do mainline code in the expect loop, I would let it finish and do the code afterwards.
Unlike with shell scripting, you don't have to guard against the possibility that the value of an argument contains spaces (i.e. if the argument name does not contain a space then it does not have to be quoted).
I left the quotes around login: and ssword: to match the following space
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
set timeout 15

spawn telnet $target

set timeout 5
expect {
      "login: "    {send $AUTOUSER\r; exp_continue}
      "ssword: "       {send $PASSWORD\r; exp_continue}
      {$->}            {}
      default          {send_log -- "GARBAGE OR CANNOT CONNECT\n"; exit }
      }

set timeout 15

# grab_stats
Random Solutions  
 
programming4us programming4us