| View previous topic :: View next topic |
| Author |
Message |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Wed Jun 06, 2018 4:20 am Post subject: Console eggdrop |
|
|
| How is it possible to give an eggdrop a command to execute a file in the shell (console) |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Jun 06, 2018 4:57 am Post subject: |
|
|
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 |
|
 |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Wed Jun 06, 2018 5:29 am Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Jun 06, 2018 6:12 am Post subject: |
|
|
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 |
|
 |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Wed Jun 06, 2018 8:38 am Post subject: |
|
|
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 |
|
 |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Wed Jun 06, 2018 10:05 am Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Jun 06, 2018 10:16 am Post subject: |
|
|
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 |
|
 |
l.kleijn Voice
Joined: 18 May 2014 Posts: 33
|
Posted: Wed Jun 06, 2018 10:27 am Post subject: |
|
|
| yes it's a bash script to autologin by ssh |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
|
| Back to top |
|
 |
|