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
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Designing Electronics with Linux
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- What's the tweeting protocol?
- Kernel Problem
3 hours 10 min ago - BASH script to log IPs on public web server
7 hours 37 min ago - DynDNS
11 hours 13 min ago - Reply to comment | Linux Journal
11 hours 45 min ago - All the articles you talked
14 hours 9 min ago - All the articles you talked
14 hours 12 min ago - All the articles you talked
14 hours 13 min ago - myip
18 hours 38 min ago - Keeping track of IP address
20 hours 29 min ago - Roll your own dynamic dns
1 day 1 hour ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
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