egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

wget and dccsend trouble

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Sat Jun 14, 2008 12:15 pm    Post subject: wget and dccsend trouble Reply with quote

Hello. I`m having some trouble with this part of my code:
Code:
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/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
strikelight
Owner


Joined: 07 Oct 2002
Posts: 708

PostPosted: Sat Jun 14, 2008 3:56 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Sun Jun 15, 2008 12:40 pm    Post subject: Reply with quote

Thank you for reply.
The next step:
Code:
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:
dccsend /home/bots/mybot/scripts/files/$unick/$filename $unick
with this
Code:
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/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
strikelight
Owner


Joined: 07 Oct 2002
Posts: 708

PostPosted: Sun Jun 15, 2008 3:41 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
username
Op


Joined: 06 Oct 2005
Posts: 196
Location: Russian Federation, Podolsk

PostPosted: Tue Jun 17, 2008 6:17 am    Post subject: Reply with quote

It seems to me this code works fine:
Code:

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/
Back to top
View user's profile Send private message Send e-mail Visit poster's website
strikelight
Owner


Joined: 07 Oct 2002
Posts: 708

PostPosted: Tue Jun 17, 2008 7:39 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber