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 VP of engineering operations at Final, Inc., the author of a number of books including DevOps Troubleshooting and The Official Ubuntu Server Book, and is a columnist for Linux Journal. Follow him @kylerankin.
Practical Task Scheduling Deployment
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.View Now!
|The Firebird Project's Firebird Relational Database||Jul 29, 2016|
|Stunnel Security for Oracle||Jul 28, 2016|
|SUSE LLC's SUSE Manager||Jul 21, 2016|
|My +1 Sword of Productivity||Jul 20, 2016|
|Non-Linux FOSS: Caffeine!||Jul 19, 2016|
|Murat Yener and Onur Dundar's Expert Android Studio (Wrox)||Jul 18, 2016|
- Stunnel Security for Oracle
- The Firebird Project's Firebird Relational Database
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- SUSE LLC's SUSE Manager
- Managing Linux Using Puppet
- My +1 Sword of Productivity
- Non-Linux FOSS: Caffeine!
- Doing for User Space What We Did for Kernel Space
- SuperTuxKart 0.9.2 Released
- Google's SwiftShader Released
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide