Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-21-2009, 04:24 PM   #1
LQ Newbie
Registered: Sep 2009
Posts: 2

Rep: Reputation: 1
Handling events over ssh


I have probably a little odd question, but hope I've chosen the most appropriate forum and I would get some advice here.

I have an access to a remote machine which runs FreeBSD. I connect there via ssh and run there some program (instant messenger). IM can run and execute any python script except script opening a new socket.

And here is my problem. I want to run some script on my local machine (e.g. play a sound) when some event occur on the remote machine (new message arrival). And the only connection which I have is the ssh connection (cant open new socket on remote machine and my local one is behind NAT). Is there any way to handle such event?

Alternatively I was looking how to stream audio over ssh what would also solve my problem but I don't think it's a best and most effective solution (while I could get the same result by sending only a few bytes instead of many kilobytes).

Thanks in advance,

Last edited by murky_; 09-21-2009 at 04:29 PM.
Old 09-21-2009, 05:34 PM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
Try getting your IM client to run a simple Python script that just logs a message to standard out. Hopefully, that message should get sent to the standard output of the IM client, which in turn will be passed over SSH - then it's just a matter of parsing the SSH client's standard output client-side.

If the IM client redirects the script's output, then you may have to do something else to pass the message along. You can create a named pipe on the BSD machine, then when you connect, run the IM client in the background (add an "&" to the end of the command-line). Then cat the named pipe in the ssh session. You can then have your python script write a line of text to the named pipe when the message arrives.

The client-side processing should be fairly easy. Once you have the message-sending working, you can just pipe the output of ssh into a python script (add "|/path/to/script" to the command-line), and then use that to play your sound when a message arrives.

Hope that helps,

–Robert J Lee
Old 09-21-2009, 08:21 PM   #3
Senior Member
Registered: Sep 2009
Location: Srbobran, Serbia
Distribution: CentOS 5.5 i386 & x86_64
Posts: 1,118
Blog Entries: 1

Rep: Reputation: 129Reputation: 129
If you are running same script on your local machine, maybe you can send a message from remote IM to local IM, bypassing ssh session all together?

Also, if I rememmber correctly, SSH can redirect/forward desired ports so you can have something like mini network inside SSH tunnel. If I do rememmber correctly, then maybe you could create server-client connection between local and remote host (maybe even direct IM?)
Old 09-21-2009, 08:51 PM   #4
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Are you able to tunnel X via ssh? At least then you could open multiple terminals. Can you ssh back to your own machine.
Kevin Barry

Last edited by ta0kira; 09-21-2009 at 08:53 PM.
Old 09-22-2009, 06:39 AM   #5
LQ Newbie
Registered: Sep 2009
Posts: 2

Original Poster
Rep: Reputation: 1
Thank you a lot for all answers. I think port forwarding is exactly what I was looking for. Now I just need to write a program listening on a given port on my local machine and use remote forwarding by typing 'ssh -R{remote_port}:localhost:{local_port} {remote_address}'

If someone has similar problem, here I found a great tutorial on that:


event, handle, ssh

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keyboard events interrupting mouse events. miner49er Linux - Hardware 3 11-04-2008 05:16 AM
Hang on triggering udev events- is there a buildup of events? sonichedgehog Slackware 20 07-11-2008 03:49 AM
What is the significance of sync events in event handling? montylee Programming 1 05-12-2008 06:14 AM
wxPython: control handling its own events? Hko Programming 1 07-30-2005 07:58 PM
qmail, ssh and events in a LAN Zingaro2002 Linux - Networking 1 08-16-2002 04:50 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration