0
votes

i have this error Tcl error : extra characters after close-brace

proc exact {nick host handle channel text} {
global db_handle network;

set size exec curl -3 --ftp-ssl -k ftp://xxx:[email protected]:2300/source/ | grep \\.r | awk '{print $5}'| awk '{ SUM += $1} END { print SUM/1024/1024 }'

putnow "PRIVMSG #chnnel :source has $size"
}
1
That set line is not correct. I think you need to wrap the exec and command (in []) to evaluate it and quote the command as a string ({}). - Etan Reisner
set size [exec curl -3 --ftp-ssl -k xxx:[email protected]:2300/source {| grep \\.r | awk '{print $5}'| awk '{ SUM += $1} END { print SUM/1024/1024 }'}] so do you mean? - user4457475
This is not your problem but your grep+awk set of pipelines should be reduced to just awk '/\.r/{ SUM += $5} END { print SUM/1024/1024 }' - Ed Morton
now have this error: Tcl error [exact]: can't read "5": no such variable - user4457475
To emphasize the point, single quotes have no special meaning in Tcl. Tcl's {braces} have the same functionality as the shell's 'single quotes' - glenn jackman

1 Answers

3
votes

Per the exec(n) man page you need to replace single quotes with curly braces. You also need [] around exec to invoke it:

    set size [exec curl -s -3 --ftp-ssl -k {ftp://xxx:[email protected]:2300/source/} | grep \\.r | awk {{print $5}} | awk {{ SUM += $1} END { print SUM/1024/1024 }}]

That said, you don't need to invoke grep or awk at all. Everything you do with them here can be accomplished within the Tcl code:

proc exact {nick host handle channel text} {
    global db_handle network;

    set status 0
    set error [catch {
        set resp [exec curl -s -3 --ftp-ssl -k {ftp://xxx:[email protected]:2300/source/}]
    } results options]
    if {$error} {
        set details [dict get $options -errorcode]
        if {[lindex $details 0] eq "CHILDSTATUS"} {
             set status [lindex $details 2]
             putnow "PRIVMSG $channel :curl error $status"
        }
    }
    set size 0
    foreach line [split $resp \n] {
        if {[string match {*\\.r*} $line]} {
            incr size [lindex $line 4]
        }
    }

    putnow "PRIVMSG $channel :source has [expr {$size/1024/1024}]"
}

(I assume you've meant $channel rather than #chnnel.)