| View previous topic :: View next topic |
| Author |
Message |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Sat Jun 14, 2008 12:15 pm Post subject: wget and dccsend trouble |
|
|
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 |
|
 |
strikelight Owner

Joined: 07 Oct 2002 Posts: 708
|
Posted: Sat Jun 14, 2008 3:56 pm Post subject: |
|
|
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 |
|
 |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Sun Jun 15, 2008 12:40 pm Post subject: |
|
|
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 |
|
 |
strikelight Owner

Joined: 07 Oct 2002 Posts: 708
|
Posted: Sun Jun 15, 2008 3:41 pm Post subject: |
|
|
| 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 |
|
 |
username Op

Joined: 06 Oct 2005 Posts: 196 Location: Russian Federation, Podolsk
|
Posted: Tue Jun 17, 2008 6:17 am Post subject: |
|
|
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 |
|
 |
strikelight Owner

Joined: 07 Oct 2002 Posts: 708
|
Posted: Tue Jun 17, 2008 7:39 am Post subject: |
|
|
| 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 |
|
 |
|