Hack and / - Lightning Hacks
One of the more interesting parts of any conference is the lightning talks. If you haven't experienced one, a lightning talk typically features a number of different speakers, each giving a short (5–20 minutes) presentation. Lightning talks take advantage of the fact that often a speaker has an interesting topic to present, but the topic won't fill an entire hour time slot. So, lightning talks round up each of these speakers one after the other in the same time slot. Because of the variety of information and the fast nature of lightning talks, they can be really informative, interesting and definitely fun.
As I was considering what topic to cover for this month's column, I realized I had a number of different hacks I'd like to mention, but none that could really fill a full column. In the spirit of lightning talks, I decided to put all of these hacks together in true rapid-fire fashion.
In the March 2008 issue of Linux Journal, I introduced the wmctrl tool and discussed how to use it to move, resize, shade and do all sorts of window management tasks from the command line. I also introduced a few scripts I had written and bound to keys to resize and shade a few different windows on my desktop. Near the end of that article, I mentioned:
My next project is to create a “reset” script that moves all the windows on all of my desktops to precise locations and sizes, in case they all get moved around and resized. Sure, I could do all this by hand, but then I'd miss this great opportunity for automation.
Well, shortly after I wrote that, I completed my reset script. This script goes from desktop to desktop (or because I use Compiz, viewport to viewport) and moves and resizes windows per my specifications. I've added comments to explain particular sections:
#!/bin/sh
# First save my current viewport so I can return
# to it after I'm done
SAVED_VP=`wmctrl -d | perl -ne '/VP: (\d+,\d+)/; print $1;'`
# Then, move to the first viewport (at 0,0). Because it
# can take a second or two for this to take effect,
# I've opted to create a while loop that will
# continue to attempt to switch to that viewport
# until it detects it is actually there.
VP=0,0
while [ `wmctrl -d | perl -ne '/VP: (\d+,\d+)/;
↪print $1;'` != $VP ];
do
wmctrl -o $VP
done
# Now resize, move, and change state of particular
# windows (see the wmctrl man page, or my wmctrl
# column for more information on the options).
wmctrl -r 'Eterm Main 1' -e '0,0,0,645,420'
wmctrl -r 'Irssi Term' -e '0,469,0,810,500'
wmctrl -r 'Irssi Term' -b add,shaded
wmctrl -r 'Irssi Term' -b add,below
wmctrl -r 'gkrellm' -b add,sticky
wmctrl -r "Irssi Notify Term" -e '0,1180,550,100,230'
# I now switch to the second viewport. As my screen
# is 1280x768, the second viewport is at 1280,0.
# If I wasn't sure, I could switch to that viewport
# and check the output of wmctrl -d for the proper coordinates.
VP=1280,0
while [ `wmctrl -d | perl -ne '/VP: (\d+,\d+)/;
↪print $1;'` != $VP ];
do
wmctrl -o $VP
done
wmctrl -r "Mozilla Firefox" -e '0,5,0,1040,708'
# Finally I switch back to my original viewport
# so I'm back where I started.
wmctrl -o $SAVED_VP
Although there are certainly a lot of commands in that script, it actually didn't take long to write. Most of the script is simply one wmctrl command after another, and I spent a majority of the time actually fine-tuning the locations of each window and figuring out the best way to switch viewports. If your desktop environment uses multiple desktops instead of one desktop with multiple viewports, you would use the -s option to change desktops instead of the -o option, which is used for viewports. You also would need to change the logic in the while loop to something more like:
DESKTOP=1
while [ `wmctrl -d | perl -ne '/^(\d+).*?\*/;
↪print $1;'` != $DESKTOP ];
do
wmctrl -s $DESKTOP
done
Although I normally use my laptop with its own built-in screen, I frequently give presentations, so I need to display on both the LCD and the external VGA connector. Unfortunately, my laptop's function keys to toggle between those states don't currently work in Linux, so I've had to put it into a script paired with a keybinding.
The xrandr program works great with my laptop to toggle between displays, so my script first examines the output of xrandr to see whether the VGA port is connected, and if so, it adds it as a display. Otherwise, it disables VGA. I also added a line to echo some text to osd_cat. I installed this program so that I would get some output on the screen to let me know which mode my script had chosen. When I'm ready to output to a projector, I just connect it to my laptop and run the script. When I'm finished with the presentation, I disconnect it and run the script again:
#!/bin/sh
if xrandr | grep -q 'VGA connected'; then
echo "LVDS + VGA" | osd_cat --shadow=2 --align=center
↪--pos=bottom --color=green --delay=2
↪--font=lucidasanstypewriter-bold-24 --offset 40 &
# choose my laptop screen's resolution by default,
# if that fails try the auto-detected mode
xrandr --output VGA --mode 1280x768@60 || xrandr
↪--output VGA --auto
else
echo "LVDS only" | osd_cat --shadow=2 --align=center
↪--pos=bottom --color=green --delay=2
↪--font=lucidasanstypewriter-bold-24 --offset 40 &
xrandr --output VGA --off &
fi
I also created a separate version of the script that spans across both screens instead of mirroring. I chose to span below my current screen (with the --below LVDS option), but most people probably will prefer to use --right-of or --left-of:
#!/bin/sh
if xrandr | grep -q 'VGA connected'; then
echo "LVDS + VGA span" | osd_cat --shadow=2 --align=center
↪--pos=bottom --color=green --delay=2
↪--font=lucidasanstypewriter-bold-24 --offset 40 &
xrandr --output VGA --mode 1280x768@60 --below LVDS || xrandr
↪--output
VGA --below LVDS --auto
else
echo "LVDS only" | osd_cat --shadow=2 --align=center
↪--pos=bottom --color=green --delay=2
↪--font=lucidasanstypewriter-bold-24 --offset 40 &
xrandr --output VGA --off &
fi
Kyle Rankin is a systems architect; and the author of DevOps Troubleshooting, The Official Ubuntu Server Book, Knoppix Hacks, Knoppix Pocket Reference, Linux Multimedia Hacks, and Ubuntu Hacks.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Speed Up Your Web Site with Varnish | Jun 19, 2013 |
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
- Speed Up Your Web Site with Varnish
- Containers—Not Virtual Machines—Are the Future Cloud
- Linux Systems Administrator
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Senior Perl Developer
- Technical Support Rep
- Non-Linux FOSS: libnotify, OS X Style
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- RSS Feeds
- Reply to comment | Linux Journal
2 hours 22 min ago - Reply to comment | Linux Journal
6 hours 21 min ago - Yeah, user namespaces are
7 hours 38 min ago - Cari Uang
11 hours 9 min ago - user namespaces
14 hours 2 min ago - yea
14 hours 28 min ago - One advantage with VMs
16 hours 57 min ago - about info
17 hours 30 min ago - info
17 hours 31 min ago - info
17 hours 32 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
thanks
thanks for the tip, i was looking for a tool like rdiff