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 

Adding multiple commands to Exec

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


Joined: 05 Nov 2009
Posts: 2

PostPosted: Thu Nov 05, 2009 10:56 am    Post subject: Adding multiple commands to Exec Reply with quote

I am trying to create a url catcher for my eggdrop that not only stores the url, but also grabs the title of the page. Now, I have been able to achieve this goal by having tcl call an external bash script of the follow:

the tcl part:
Code:

  set fd [open $urllogfile a+]
  set title [exec gettitle.sh $i]
  puts $fd "$i;[ctime [unixtime]];$title;$nick;$chan"
  close $fd


the bash part:
Code:

#!/bin/sh
TITLE=`lynx -source $1 | grep -i "<title>" | awk -F "<title>" '{print $2}' | awk -F "</title>" '{print $1}'`
if [ "$TITLE" = "" ]; then
  echo No Title Found
else
  echo $TITLE
fi


Now, while this is working, it is messy to call an external script like this, so, I was wondering if it was possible to translate this into TCL so its all in the same script?

Thanks in advance for any help or tips.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Thu Nov 05, 2009 9:06 pm    Post subject: Re: Adding multiple commands to Exec Reply with quote

Code:
#put the line below at the very top of your script
package require http

# then change your code to look like this
   if {![string match "http://*" $i]} { set i "http://$i" }
   catch {set http [::http::geturl "$i" -timeout 5000]} error
   if {![string match -nocase "::http::*" $error]} {
     putserv "privmsg $chan :[string totitle [string map {"\n" " | "} $error]] \( $i \)"
     return 0
   }
   if {![string equal -nocase [::http::status $http] "ok"]} {
     putserv "privmsg $chan :[string totitle [::http::status $http]] \( $i \)"
     return 0
   }
   set html [::http::data $http]
   ::http::cleanup
   if {![regexp -nocase -- {<title>(.*?)<title>} $html - title]} { set title "No Title Found" }
   set fd [open $urllogfile a+]
   puts $fd "$i;[ctime [unixtime]];$title;$nick;$chan"
   close $fd

_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
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