Tags: args, body, connect, folks, forsome, guidence, hit, proc, program, programming, ssh, tcl, telnet, wrong

wrong # args: should be "proc name args body"

On Programmer » TCL

3,837 words with 3 Comments; publish: Sun, 18 May 2008 19:45:00 GMT; (200220.70, « »)

Hi Folks,

I'm very new to tcl programming and hit with a problem. Hoping for

some guidence.

The program is to use ssh / telnet to connect to a host based on

command line args. When this is run as a script it gives below error,

but same work fine when invoked through tclsh shell.

Kindly help me.

"wrong # args: should be "proc name args body"

while executing

"proc ssh_login {userid _host _pass} {

spawn ssh -l $userid $_host

expect {

timeout {

"

++++++++++ ACTUAL SCRIPT+++++++++

#!/usr/bin/expect -d

proc ssh_login {userid _host _pass} {

spawn ssh -l $userid $_host

expect {

timeout {

puts "ssh session timed out"

exit 1

}

-re "Are you sure you want to continue connecting" {

send -- "yes \r"

exp_continue

}

-re "(?i)password: " {

}

}

sleep 1

send -- "$_pass\r"

} # end of proc ssh_login

proc telnet_login { userid _host _pass } {

spawn telnet

expect {

timeout {

puts "telnet timed out"

exit 2

}

-re "(?i)login" {

send -- "$userid\r"

exp_continue

}

-re "(?i)password" {

sleep 1

send -- "$_pass\r"

}

}

} #end of telnet_login

global _host

global userid

global _pass

global RDA_PATH

global sess

set timeout 19

if { [llength $argv ] < 4 } {

puts " pass the command argument"

exit 1

} else {

set _host [lindex $argv 0]

set userid [lindex $argv 1]

set _pass [ lindex $argv 2]

set RDA_PATH [lindex $argv 3]

set sess [lindex $argv 4]

puts " Connecting to Host $_host with $sess "

}

if { $sess = "ssh" } {

ssh_login $userid $_host $_pass

} else {

telnet_login $userid $_host $_pass

}

if { $sess_r != 0 } {

puts "failed to establish a session with $_host"

exit 3

}

expect -regexp "(\$|\#|\> )" {

sleep 2

exp_send {PS1='RDA>'}

send -- "\r"

send -- "cd $RDA_PATH \r"

}

interact

==========================

All Comments

Leave a comment...

  • 3 Comments
    • amarnath.mohan.tcl-program.todaysummary.com.gmail.com a =E9crit :

      > Hi Folks,

      > I'm very new to tcl programming and hit with a problem. Hoping for

      > some guidence.

      > The program is to use ssh / telnet to connect to a host based on

      > command line args. When this is run as a script it gives below error,

      > but same work fine when invoked through tclsh shell.

      > Kindly help me.

      > "wrong # args: should be "proc name args body"

      > while executing

      > "proc ssh_login {userid _host _pass} {

      > spawn ssh -l $userid $_host

      > expect {

      > timeout {

      > "

      You have at the last lign:

      > } # end of proc ssh_login

      A comment must start, either at the beginning of a line,

      either after the end of a command after a semicolon.

      So you need :

      }; # end of proc ssh_login

      Regards,

      Stephane

      #1; Sun, 18 May 2008 19:46:00 GMT
    • Hi Stephane,

      Your explanation did the miracle.

      Thanks a lot for your help.

      Regards,

      Amar

      St=E9phane A. wrote:

      > amarnath.mohan.tcl-program.todaysummary.com.gmail.com a =E9crit :

      >

      > You have at the last lign:

      > A comment must start, either at the beginning of a line,

      > either after the end of a command after a semicolon.

      > So you need :

      >=20

      > }; # end of proc ssh_login

      >=20

      > Regards,

      > Stephane

      #2; Sun, 18 May 2008 19:47:00 GMT
    • In article <1165306339.228539.274700.tcl-program.todaysummary.com.80g2000cwy.googlegroups.com>,

      <amarnath.mohan.tcl-program.todaysummary.com.gmail.com> wrote:

      >Hi Stephane,

      > Your explanation did the miracle.

      >Thanks a lot for your help.

      #3; Sun, 18 May 2008 19:48:00 GMT