| View previous topic :: View next topic |
| Author |
Message |
onesikgypo Voice
Joined: 14 Jun 2008 Posts: 4
|
Posted: Sat Jan 10, 2009 2:31 am Post subject: Getting a bash script to communicate with an eggdrop |
|
|
Hi,
I have a bash script already made, however a new addition id like to make, is that whent he script is executed, my eggdrop msg's a channel with such details. I have already installed and setup my eggdrop, however i have no idea how i can get bash to talk with the eggdrop in order to perform what i require.
Any assistance will be greatly appreciated.
Thankyou. |
|
| Back to top |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
|
| Back to top |
|
 |
onesikgypo Voice
Joined: 14 Jun 2008 Posts: 4
|
Posted: Sat Jan 10, 2009 2:51 am Post subject: |
|
|
could you give a bit more detail on how to do this/how this works - ie. if i had a bash script with
#!/bin/bash
find *.txt >> fils.lst
rm -f *.txt
dir=`pwd`
;;MSG HERE- Msg #chan Cleaning $dir;;
as an example, how would i go about it - and if eggdrop needs to execute the script, im guessing then if executing via ssh then no msges will occur - if this is the case, is there a way i can write an ssh script, which will force the eggdrop to execute the said script (the point of which is that i can continue using ssh?)
Thanks. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Jan 10, 2009 8:41 am Post subject: |
|
|
I guess you could consider using named pipes to communicate with your eggdrop that way.
In that case, you'd have to set up a "listener" within your eggdrop (open, fconfigure, fileevent, gets, eof) to listen at the pipe, and take appropriate actions upon incoming transmissions.
In order to transmit to your eggdrop, it would be a mere matter of
| Code: | | echo write #chan Clearing $dir >> /path/to/the/pipe |
Also see the manpage for mkfifo for further information on named pipes. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
Posted: Sat Jan 10, 2009 9:48 am Post subject: |
|
|
I was thinking just returning certain codes from the shell script. If you return 1... well. Let's put it this way:
| Code: | #!/bin/sh
find *.txt >> fils.lst
rm -f *.txt
dir=`pwd`
return 1 |
| Code: | | set foo [exec maihappyness.sh] .. if {[info exists foo]} { putserv hi2u }} |
_________________ ; Answer a few unanswered posts! |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Jan 10, 2009 9:50 am Post subject: |
|
|
@incith: Wouldn't foo always exist in that example? _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
incith Master

Joined: 23 Apr 2005 Posts: 275 Location: Canada
|
Posted: Sat Jan 10, 2009 10:52 am Post subject: |
|
|
Well, I didn't test that and had posted it roughly 0.34 seconds after waking up, but...
| Code: | % set foo [exec lalala]
couldn't execute "lalala": no such file or directory
% set foo
can't read "foo": no such variable |
Nevermind I think I know what you are getting at.. as long as it execs something, it should return 0 or 1, ya. And so you'd want to use if {$foo == x}.. or just if {[exec] == x}
I guess my method won't work anyway without some modification to make it a function.. | Code: | % set foo [exec ./test.sh]
./test.sh: line 2: return: can only `return' from a function or sourced script |
_________________ ; Answer a few unanswered posts! |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Sat Jan 10, 2009 11:45 am Post subject: |
|
|
Rather than using return, I'd make use of the fact that it's just an anonymous pipe... Hence anything sent to stdout would be returned by exec.
Still, this leaves the issue of being able to do this directly from the shell environment. I guess you could telnet into the eggdrop from the shell and do it that way... _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
karrde Voice
Joined: 21 Jan 2009 Posts: 2
|
Posted: Wed Jan 21, 2009 11:18 pm Post subject: |
|
|
| nml375 wrote: | I guess you could consider using named pipes to communicate with your eggdrop that way.
In that case, you'd have to set up a "listener" within your eggdrop (open, fconfigure, fileevent, gets, eof) to listen at the pipe, and take appropriate actions upon incoming transmissions.
In order to transmit to your eggdrop, it would be a mere matter of
| Code: | | echo write #chan Clearing $dir >> /path/to/the/pipe |
Also see the manpage for mkfifo for further information on named pipes. |
Could you possibly describe how to set up the listener within eggdrop in a bit more detail? I'm new to the whole eggdrop thing. I'm trying to get a script to notify a channel when something external happens, if there's a better way to handle this then please let me know. Much appreciated.  |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Jan 22, 2009 3:24 pm Post subject: |
|
|
One thing I did forget, is that opening a pipe in RDONLY-mode will block until another process opens the pipe in RWONLY-mode. With normal tcl-scripting this would probably not be such a big issue, as this would probably be some server-like application. With eggdrops however, this would prevent your eggdrop from performing it's normal tasks.
One option still would be using tcp-sockets, and use nc (if available). This however has the downside that anyone who knows the listening-port could connect there and send arbitrary data. You would thus have to implement some kind of safety-mechanism.
To achieve something like this however, you'd do something like this:
| Code: | listen 12345 script IncomingConnection
proc IncomingConnection {idx} {
#We've got a new incoming connection, hand it over to our "handler"
control $idx IncomingTransmission
}
proc IncomingTransmission {idx text} {
#Did we recieve a new line, or did the remote end close the connection?
if {$text != ""} {
#Slit the text into a list and retrieve the command..
set data [split $text]
set command [lindex $data 0]
#.. and see what we're supposed to do.
#Hint: this would be a nice place to add a command for authentication...
switch $command {
write {
#Use list-element 1 as channel, and the rest as the message to be sent
#Considder adding a check whether the connection has authenticated or not yet.
#Atleast we do check that it's a valid channel..
if {[validchan [set chan [lindex $data 1]]]} {
puthelp "PRIVMSG $chan :[join [lrange $data 2 end]]"
}
}
}
} else {
#remote connection closed, do some cleanup here if needed
#Hint: here you would un-authenticate the idx (connection identifier)
#For now tho, we'll just do a putlog for fun
putlog "Remote connection $idx dropped"
}
} |
This is a very, very crude example, and does no authentication whatsoever. You should thus extend this with some kind of protection/authentication/etc to prevent sending arbitrary messages to your channels.
To send a message from your bash-script, do something like this:
| Code: | #simple case, where we have no authentication or such:
echo "write #mychan Cleaning $dir" | nc localhost 12345
#Lets imagine we've implemented an authenticate-command that has to be issued before write...
#Send multiple commands like this:
nc localhost 12345 <<EOF
authenticate mysecretpassword
write #mychan Clearing $dir
EOF |
edit: fixing minor typos _________________ NML_375, idling at #eggdrop@IrcNET
Last edited by nml375 on Fri Jan 23, 2009 9:39 am; edited 1 time in total |
|
| Back to top |
|
 |
karrde Voice
Joined: 21 Jan 2009 Posts: 2
|
Posted: Fri Jan 23, 2009 4:06 am Post subject: |
|
|
Perfect! Thanks to your code, I'm a lot closer than I was before. Thanks for your help!
I did notice though that I can't actually do "echo write #mychan blah" because echo interprets the # as the start of a remark Oh, and I had to change
| Code: | | listen 12345 IncomingConnection |
to
| Code: | | listen 12345 script IncomingConnection |
because otherwise it'd complain about an invalid type.
But anyway, thanks again! |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Jan 23, 2009 9:46 am Post subject: |
|
|
Sorry for that, two of those nasty typos that just slip through no matter how many times you re-read your post before submitting. Updated previous post to correct both issues. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|