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.

Console eggdrop

Help for those learning Tcl or writing their own scripts.
Post Reply
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Console eggdrop

Post by l.kleijn »

How is it possible to give an eggdrop a command to execute a file in the shell (console)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Hello l.kleijn,
There's some good reading here regarding running other processes from tcl-scripts.

One thing to keep in mind, though, is that eggdrop is a single-threaded process, and using "exec" will prevent your eggdrop from taking any other actions until the child process returns. If the program you are executing is guarantee'd to return immediately, that should not pose a problem. Otherwise, I'd suggest you launch it as a background process (using the & suffix).
Using "open" on the other hand does not have these issues, but you'll be tasked with reading/closing the file-handle as the process completes, or you'll run out of resources...
NML_375
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

I want to execute a file named login.

But i don't no how i can tell the eggdrop to exec him.
I tried it in a script but gives an error.

Code: Select all

proc pub:test {nick host hand chan arg} {
  global botnick outputchan filename
  set io [open "[info ./login] $filename" r+]
  set invert [exec [info ./login] $filename << \]
  puts "Test \n $invert"
  putserv "PRIVMSG $outputchan :Mission Accomplished"
}
This is the script

and the file is existing in the dir /home/lckleijn
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Lets see what we've got here...
First off, you invoke the tcl-command "info" with invalid parameters; and to be honest, I'm not sure what you actually intend to do here... For reference, the manpage for the "info" command can be found here: https://www.tcl.tk/man/tcl/TclCmd/info.htm

Next, you make a call to "open" with the result from that "info"-command combined with the value of $filename. If you are actually trying to invoke a local executable named "login", passing $filename as the first parameter to it; you'd have to use the pipe-prefix:

Code: Select all

set io [open "|./login $filename" r+]
Unfortunately, you never read nor close $io, and hence you are now leaking file descriptors. Very bad! At a minimum, you should have a "fileevent" for "readable"; making sure to close the file once EOF is reached (process has ended)

Code: Select all

proc loginHandler {fileId} {
  global outputchan
  if {[gets $chan line] >= 0} {
    putserv "PRIVMSG $outputchan :$line"
  }
  if {[eof $chan]} {
    close $chan
  }
}
...
set io [open "|./login $filename" r+]
fconfigure $io -blocking 0 -buffering line
fileevent $io read [list loginHandler $io]
Moving on, you now try to do the very same thing usin exec instead. If "login" is guarantee'd to return immediately, this would probably be safe; however, you've escaped the closing brace, which would result in a parser error. Further, you fail to add a value to the << operator leading to a syntax error.
In it's most simplest form, it'd be done like this:

Code: Select all

set invert [exec ./login $filename]
Keep in mind though, there'd be no point in doing both "open" and "exec"; that would result in your executable being invoked twice. Use the one approach that best suits your needs.

Next, using the "puts" command would print output to stdout; normally, eggdrops "fork into background", and thus have no access to neither stdin or stdout. Unless you've explicitly started your eggdrop to run in your console, you won't be seeing any output.
NML_375
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

Sorry i don't understand it.

Can you write one for me ? i have a little bit learned about eggdrop but not very much. So it must exec a file from the dir /home/lckleijn called login.
The file login is a bash script.
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

i have now this error

Code: Select all

<IRCop-Bot> [16:04:15] Tcl error [pub:test]: Pseudo-terminal will not be allocated because stdin is not a terminal.
How can i fix this ?

And the script is:

Code: Select all

bind pub - ${trigger}test pub:test

proc pub:test {nick host hand chan arg} {
  global botnick outputchan filename
  set invert [exec $filename]
  putserv "PRIVMSG $outputchan :Mission Accomplished"
}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I'd believe that error comes from your bash-script...
Does it use ssh to connect/execute commands on a remote server?
NML_375
l
l.kleijn
Voice
Posts: 33
Joined: Sun May 18, 2014 10:02 am

Post by l.kleijn »

yes it's a bash script to autologin by ssh
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Then you'll have to modify your bash-script to either disable allocation of a pseudo-terminal, or force it regardless of that your eggdrop does not run on a terminal.
A quick search on Google should provide a fair bit of information, as this is not an unusual issue with ssh. https://stackoverflow.com/questions/711 ... a-terminal might be worth a check.
NML_375
Post Reply