This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

wget and dccsend trouble

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

wget and dccsend trouble

Post by username »

Hello. I`m having some trouble with this part of my code:

Code: Select all

if {[string match {*-get*} $ustr]} {
                  [exec /usr/bin/wget -P /home/bots/mybot/scripts/files/$unick/ $wwwlink]
                  regexp -all -nocase -- {httpcode(.*?)here} $wwwlink - filename
                  dccsend /home/bots/mybot/scripts/files/$unick/$filename $unick
}
It works this way: if in my pub cmd bot find word -get he download file from $wwwlink using wget and after that send it to me using dccsend command.
But when bot begin dccsend the file from wget didnt already downloaded.
How can I scan if wget command is successfully finished and only after that begin dccsend to me?
Thank you.
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

For starters, your [exec...] line will most certainly cause an error, and nothing else will be processed after that.

You only use []'s around a command when you are setting a variable and/or doing something with the results of that command. Remove the []'s around your exec line. Secondly, since you are not launching wget into the background, exec will not return control back to the script until wget completes. This by itself will accomplish what you ask of, however it can also cause your bot to timeout if the download is a long one.
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

Thank you for reply.
The next step:

Code: Select all

if {[string match {*-get*} $ustr]} {
                  set status [catch {exec /usr/bin/wget -b -P /home/bots/mybot/scripts/files/$unick/ $wwwlink} result]
                  if {$status == 0} {
                  regexp -all -nocase -- {httpcode(.*?)here} $wwwlink - filename
                  dccsend /home/bots/mybot/scripts/files/$unick/$filename $unick
}
And I try to replace

Code: Select all

dccsend /home/bots/mybot/scripts/files/$unick/$filename $unick
with this

Code: Select all

switch -- [dccsend /home/bots/mybot/scripts/files/$unick/$filename $unick] {
    0 {
      puthelp "NOTICE $unick :sending $filename to you."
      dccsend /home/bots/mybot/scripts/files/$unick/$filename $unick
    }
    1 { puthelp "NOTICE $unick :dcc table is full (too many connections), try to get $filename later." }
    2 { puthelp "NOTICE $unick :can't open a socket for the transfer of $filename." }
    3 { puthelp "NOTICE $unick :$filename doesn't exist." }
    4 { puthelp "NOTICE $unick :$filename was queued for later transfer." }
    }
## dcc sends/recieves por Marco Ferra aka nXistence
and always get "filename doesn't exist."
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Now you are using -b with wget to cause wget to return right away, meaning the script will continue on immediately WHILE wget downloads the file. You will need to remove the -b switch. Alternatively to exec, you can use open with the |, or use a script that already does this, such as bgexec.tcl which will execute a command in non-blocking mode, and then call a procedure once the command has completed.
User avatar
username
Op
Posts: 196
Joined: Thu Oct 06, 2005 9:20 am
Location: Russian Federation, Podolsk
Contact:

Post by username »

It seems to me this code works fine:

Code: Select all

if {[string match {*-get*} $ustr]} {
set fp [open "| /usr/bin/wget -P /home/bots/mybot/scripts/files/$unick/ $wwwlink"]
if {[catch {close $fp} err]} {
regexp -all -nocase -- {httpcode(.*?)here} $wwwlink - filename
dccsend /home/bots/mybot/scripts/files/$unick/$filename $unick
return
}
Архив TCL скриптов для ботов Eggdrop/Windrop:
http://egghelp.ru/
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Yes, because you are not using the -b flag with wget, which you could have done with exec as well. However, you will most likely get incomplete dccsends, especially if the download host is slower than the bot's dcc transfer, since you are not waiting for the download to finish before sending.
Post Reply