Sunday, February 24, 2008

Using 'screen'

I wrote a simple script to start a 'screen' session on my mythtv box when the mythtv user logs in, at ~/bin/start_screen.sh

--------------------
#!/bin/bash

screen -d -m
--------------------

This starts a detatched screen session. I can now ssh into the mythtv box, connect to that screen, and execute commands in the context of the logged-in mythtv user. Before I had setup irexec to run in its own start-up script, I used to launch it from this screen session. And now that I've been using synergy, there's even less of a reason to keep this screen session around. I'll still keep it going, just in case :)

This page is what got me started with screen.

Synergy: My New Best Friend

I wish I had heard about Synergy sooner. This app is so cool. If you have a laptop, and run MythTV, you'll wish you've been using it all along as well.

From Synergy's site:
---------------
Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems, each with its own display, without special hardware. It's intended for users with multiple computers on their desk since each system uses its own monitor(s).
---------------

I use Synergy to let me control my mythbox from my laptop. This is not the same as VNC. I don't see the mythtv desktop from my laptop. I'm still using my TV as a monitor, but using my laptop mouse and keyboard to control it. It's very handy for watching web videos on my tv through mythtv, or just to interface with myth a little faster than with my remote control. My mythtv box doesn't have a keyboard plugged into it anymore.

I have my system setup so that my laptop is the synergy server. The server is the machine that has the keyboard and mouse that you want to share. I created a simple script on my mythtv box that starts the synergy client when the mythtv user first logs in (through the session start-up scripts configuration) at ~/bin/synergy_client:

---------------
#!/bin/bash
synergyc --name mythtv [laptop ip address]
---------------

When I want to control my myth box with my laptop keyboard and mouse, i start up the synergy server on my laptop with a simple script named ~/bin/synergy_server:

---------------
#!/bin/bash
killall synergys
sleep 1
synergys --config /etc/synergy.config --name laptop
---------------

If both the server and client are running, I just move my mouse to the right edge of my laptop's screen, and it's now on the mythtv box. Any keyboard activity is sent to mythtv. The clipboard is shared between the two machines. If I want to confine myself to the current box I'm in, I just turn on Scroll Lock. This will prevent the mouse from moving outside the current context.

For reference, here's my laptop's synergy config file:

section: screens
laptop:
mythtv:
end

section: aliases
laptop:
[laptop's ip address goes here]
mythtv:
[mythtv's ip address goes here]
end

section: links
laptop:
right = mythtv
mythtv:
left = laptop
end

section: options
screenSaverSync = false
end

Starting 'irexec' on reboot

Every time I reboot my MythTV frontend/backend box, I'm annoyed that I have to sit in front of my tv with the keyboard to open up an xterm window and run 'irexec' so that the "wife button" works to stop/start MythTV Frontend when it's misbehaving.

I tried setting 'irexec' as a start script in Gnome, but that never worked. I found the answer to be embarrassingly simple... Wrap the command in your own bash script, then set that script as a startup script.

So in /home/mythtv/bin/start_irexec.sh :
#######

#!/bin/bash
irexec

#######

That's it! I set that command as a startup command in Gnome, and now I can unplug the keyboard, and reboot anytime I need.