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 

Console eggdrop

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


Joined: 18 May 2014
Posts: 15

PostPosted: Wed Jun 06, 2018 4:20 am    Post subject: Console eggdrop Reply with quote

How is it possible to give an eggdrop a command to execute a file in the shell (console)
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2835

PostPosted: Wed Jun 06, 2018 4:57 am    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
l.kleijn
Voice


Joined: 18 May 2014
Posts: 15

PostPosted: Wed Jun 06, 2018 5:29 am    Post subject: Reply with quote

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:
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
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2835

PostPosted: Wed Jun 06, 2018 6:12 am    Post subject: Reply with quote

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:
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:
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:
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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
l.kleijn
Voice


Joined: 18 May 2014
Posts: 15

PostPosted: Wed Jun 06, 2018 8:38 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
l.kleijn
Voice


Joined: 18 May 2014
Posts: 15

PostPosted: Wed Jun 06, 2018 10:05 am    Post subject: Reply with quote

i have now this error

Code:
<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:
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"
}
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2835

PostPosted: Wed Jun 06, 2018 10:16 am    Post subject: Reply with quote

I'd believe that error comes from your bash-script...
Does it use ssh to connect/execute commands on a remote server?
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
l.kleijn
Voice


Joined: 18 May 2014
Posts: 15

PostPosted: Wed Jun 06, 2018 10:27 am    Post subject: Reply with quote

yes it's a bash script to autologin by ssh
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2835

PostPosted: Wed Jun 06, 2018 11:14 am    Post subject: Reply with quote

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/7114990/pseudo-terminal-will-not-be-allocated-because-stdin-is-not-a-terminal might be worth a check.
_________________
NML_375, idling at #eggdrop@IrcNET
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