0

I'm attempting to run a shell script from TCL. I'm having a bit of trouble though as it's not working or giving me an error to troubleshoot. I'm pretty sure my issue is coming from not having "run" formatted properly. Any help is appreciated.

set run "sshpass -p 'password' ssh user@ip 'bash -s' <"
set sh "test.sh"
set cmd [list $run $sh $arg1 $arg2]

if {[catch {eval [linsert $cmd 0 "exec"]} status]} {
  foreach line [split $status "\n"] {
    if {[string match *text* $line]} {
       //do something
    }
  }
}
2
  • I'm on another platform so I can't test this properly (especially since arg1 and arg2 are unknown), but try exec $run $sh $arg1 $arg2 instead of eval [linsert $cmd 0 "exec"]. Commented Oct 3, 2015 at 8:17
  • Share the error message as well. Commented Oct 3, 2015 at 8:35

1 Answer 1

2

Ended up removing the run variable and adding it directly. Works fine now.

set sh "test.sh"
set cmd [list sshpass -p 'password' ssh user@ip 'bash -s' \< $sh $arg1 $arg2]

if {[catch {eval [linsert $cmd 0 "exec"]} status]} {
  foreach line [split $status "\n"] {
    if {[string match *text* $line]} {
       //do something
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Correct. That's because unlike bash or other languages, exec in tcl operates on a list (or arguments) instead of a string. Therefore the original command was trying to execute a program named sshpass -p 'password' ssh user@ip 'bash -s' < instead of sshpass
Those single quotes… they will cause confusion. ' is a special character to bash, but not at all to Tcl (which uses {} for the same job, except they're nestable).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.