Getting rid of the “redirecting to systemctl” message in OpenSUSE

On OpenSUSE systems running systemd all rcX scripts now redirect start, stop, reload, restart, etc. service commands to systemctl. The messages that  used to appear on STDOUT telling you that a command is successful (or not) are now logged, but are no longer displayed on STDOUT.

That I can deal with, but every call to an rcX script now generates the message “redirecting to systemctl” to STDERR. I have a lot of scripts that call rcX scripts, and they interpret STDERR messages as “something just broke”.

The culprit is the new /etc/rc.status script that ships with OpenSUSE. It spews out the “redirecting to systemctl” message to STDERR for every operation that you do. The following command will modify the script and remove this stupid message:

if ( grep -q 'redirecting to systemctl' /etc/rc.status ) ; then
    # Save a copy of the original file
    cp -p /etc/rc.status /etc/rc.status.orig;

    # OpenSUSE 12.1:
    perl -i.bak -pe 's,echo "redirecting to systemctl" >/dev/stderr,,;' /etc/rc.status;

    # OpenSUSE 12.3:
    perl -i.bak -pe 's,echo "redirecting to systemctl \${SYSTEMCTL_OPTIONS} \$1 \${_rc_base}" 1>&2,,;' /etc/rc.status;
fi

This works for OpenSUSE 12.1 and 12.3. I did not have a 12.2 system available to test with.

Hope you find this useful.

Leave a Comment

Bring Pidgin’s window into front focus when there’s an inbound IM

I was talking to a co-worker about Pidgin not coming into focus when there’s a new, inbound IM. The Pidgin window used to come into focus, front and center, when I was running Ubuntu/Gnome and when running OpenSUSE/KDE, but when I upgraded my office desktop to Ubuntu/Unity it stopped behaving this way. My co-worker noticed the same behavior with Fedora17/Gnome. A new IM would come in, but the Pidgin IM window would remain in the background, hidden, unseen and unread.

I thought “There has to be a setting that controls this,” and there is…

  • Bring up Pidgin’s Buddy List
  • Click Tools > Plugins
  • Locate the Message Notification plugin and highlight it
  • At the bottom of the Plugins window is a Configure Plugin button. Click it
  • Under Notification Methods check both Raise conversation window and Present conversation window
  • Click Close

That’s it. The next time someone IM’s you, your Pidgin Conversation will pop up in the center of your screen, in front of all of your other windows.

Hope you find this useful.

Comments (1)

How to turn off AMBER alerts on an iPhone

Last night I was woken up by an AMBER alert on my iPhone. Apparently there was a horrific murder and possible child abduction and the police wanted to make absolutely sure that every cell phone -carrying person in the state was made aware of the fact, just in case we spotted the children somewhere.

I live near San Francisco. The possible abduction happened near San Diego. It’s an 8 hour drive away. Teleportation has not been invented yet. There is no possible way that I am going to have witnessed anything that can help.

Until the people operating the AMBER alert system either:

  1. Limit notifications to the geographic area where they might actually do some good
  2. OR Give me the option to disable AMBER alerts while I’m asleep (“Do Not Disturb” mode is enabled)
  3. OR Give me the option to disable AMBER alerts while stationary (phone is not moving, so I’m not out and about and therefore unlikely to witness anything helpful)

… I am going to disable AMBER alerts on my iPhone. If one of these problems is addressed I’ll consider turning alerts back on. Until then, they’re staying off.

If you feel the same way, here’s what you do:

  • Go to Settings -> Notifications
  • Scroll all the way down to the bottom of the screen
  • Switch “AMBER Alerts” to the OFF position
  • Get some (undisturbed) sleep

How to Improve the AMBER Alert System so that it’s MORE Effective

I am convinced that the AMBER alert system can do good, but I also believe that it will be less and less effective if the people managing the system continue to send out alerts in such a ham-handed way. If the people managing the system send alerts to mobile phones in the middle of the night, and the only options that a mobile phone user has are ON and OFF, more and more people will start turning AMBER alerts OFF, making the AMBER alert system less and less effective.

I’ve built many operations alert systems over the past 15 years.  Sending repeated alarms to the wrong people makes those people ignore alarms. Sending alerts all of the time desensitizes people when there’s an actual alarm they should worry about. If I had a little more control over how and where I receive AMBER alerts, I’d leave them on. Here are my suggestions to the maintainers of the AMBER alert system:

Limit alerts to phones within a given radius of the scene of the crime. Every cell tower has a known geographic position. Every active mobile phone self-registers with the nearest cell tower. With the incident that took place in Boulevard, CA (near San Diego), alerts went out to all of California, alerting citizens in Yreka, CA (851 miles from the crime scene), but not Fortuna, AZ (123 miles from the crime scene).  By sending alerts to cell towers within a 200 or 300 mile radius, the alerts would be seen by the people most likely to have actually seen something. Sending alerts to people 850 miles from the crime scene desensitizes them to future alerts.

Include a URL for more information. If you’re sending the alerts to smart phones, include a link that someone can click for more information, then they might actually know what to look for.

Delay alerts for phones that are in “Do Not Disturb” mode. No one wants to be woken up at 3am with a screeching alert tone only to find out that they need to be on the lookout for a blue Nissan pickup truck. There are no blue Nissan pickup trucks in my bedroom or anyone else’s bedroom. If a phone’s “Do Not Disturb” mode is turned on, hold the alert until the DnD time is over, then alert the person carrying the phone. That’s one less person who will turn alerts off.

Better yet, hold alerts until the phone moves. If a phone’s “Do Not Disturb” mode is turned on, hold the alert until the DnD time is over, then alert the person carrying the phone as soon as they pick it up or move the phone. I’m awake now, you have my full attention, and I’m getting ready to go somewhere where I might actually see something. That’s the time to tell someone to be on the lookout, not at 3am when they’re asleep.

With these simple changes the AMBER alert system could be made more effective, reaching people who might have seen something at the time when they’re actually out and about. Without changes such as these, the system will become less and less effective over time, and lives will be lost.

Fix the system. Make it better. Make it more effective.

If you find this useful, please click the “share” button and share it with your friends.

Comments (1)

Creating differential backups with hard links and rsync

You can use a hard link in Linux to create two file names that both point to the same physical location on a hard disk. For instance, if I type:

> echo xxxx > a
> cp -l a b
> cat a
xxxx
> cat b
xxxx

I create a file named “a” that contains the string “xxxx”. Then I create a hard link “b” that also points to the same spot on the disk. Now if I write to the file “a” whatever I write also appears in file “b” and vice versa:

> echo yyyy > b
> cat b
yyyy
> cat a
yyyy
> echo zzzz > a
> cat a
zzzz
> cat b
zzzz

Copying to a hard link updates the data on the disk that each hard link points to:

> rm a b c
> echo xxxx > a
> echo yyyy > c
> cp -l a b
> cat a b c
xxxx
xxxx
yyyy

“a” and “b” point to the same file on disk, “c” is a separate file. If I copy a file “c” to “b” that also updates “a”:

> cp c b 
> cat a b c
yyyy
yyyy
yyyy
> echo zzzz > c
> cat a b c
yyyy
yyyy
zzzz 

What most people don’t know is that rsync is an exception to this rule. If you use rsync to sync two files, and it sees that the target file is a hard link, it will create a new target file but only if the contents of the two files are not the same:

> rm a
> rm b
> echo xxxx > a
> cp -l a b
> cat a
xxxx
> cat b
xxxx
> echo yyyy > c
> cat c
yyyy
> rsync -av c b
sending incremental file list
c
sent 87 bytes  received 31 bytes  236.00 bytes/sec
total size is 5  speedup is 0.04
> cat b
yyyy
> cat c
yyyy
> cat a
xxxx

File “b” is no longer a hard link of “a”, it’s a new file. If I update “a” it no longer updates “b”:

> echo zzzz > a
> cat a b c
zzzz
yyyy
yyyy

However, if the file that I’m rsync-ing is the same as “b”, then rsync does NOT break the hard link, it leaves the file alone:

> rm a
> rm b
> rm c
> echo xxxx > a
> cp -al a b
> cp -p a c
> cat a b c
xxxx
xxxx
xxxx

At this point “a” and “b” both point to the same file on the disk, which contains the string “xxxx”. “c” is a separate file that also contains the string “xxxx” and has the same permissions and timestamp as “a”.

> rsync -av c b
sending incremental file list
sent 39 bytes  received 12 bytes  102.00 bytes/sec
total size is 5  speedup is 0.10
> cat a b c
xxxx
xxxx
xxxx

At this point I’ve rsynced file “c” to “b”, but since c has the same contents and timestamp as “a” and “b” rsync does nothing at all. It doesn’t break the hard link. If I change “b” it still updates “a”:

> echo yyyy > b
> cat a b c
yyyy
yyyy
xxxx

This is how many modern file system backup programs work. On day 1 you make an rsync copy of your entire file system:

backup@backup_server> DAY1=`date +%Y%m%d%H%M%S`
backup@backup_server> rsync -av -e ssh earl@192.168.1.20:/home/earl/ /var/backups/$DAY1/

On day 2 you make a hard link copy of the backup, then a fresh rsync:

backup@backup_server> DAY2=`date +%Y%m%d%H%M%S`
backup@backup_server> cp -al /var/backups/$DAY1 /var/backups/$DAY2
backup@backup_server> rsync -av -e ssh --delete earl@192.168.1.20:/home/earl/ /var/backups/$DAY2/

“cp -al” makes a hard link copy of the entire /home/earl/ directory structure from the previous day, then rsync runs against the copy of the tree. If a file remains unchanged then rsync does nothing — the file remains a hard link. However, if the file’s contents changed, then rsync will create a new copy of the file in the target directory. If a file was deleted from /home/earl then rsync deletes the hard link from that day’s copy.

In this way, the $DAY1 directory has a snapshot of the /home/earl tree as it existed on day 1, and the $DAY2 directory has a snapshot of the /home/earl tree as it existed on day 2, but only the files that changed take up additional disk space. If you need to find a file as it existed at some point in time you can look at that day’s tree. If you need to restore yesterday’s backup you can rsync the tree from yesterday, but you don’t have to store a copy of all of the data from each day, you only use additional disk space for files that changed or were added.

I use this technique to keep 90 daily backups of a 500GB file system on a 1TB drive.

One caveat: The hard links do use up inodes. If you’re using a file system such as ext3, which has a set number of inodes, you should allocate extra inodes on the backup volume when you create it. If you’re using a file system that can dynamically add inodes, such as ext4, zfs or btrfs, then you don’t need to worry about this.

Comments (3)

Workaround to fix the problem of KDE “forgetting” your multi-monitor setup

I originally reported this KDE4 bug as https://bugs.kde.org/show_bug.cgi?id=312190. It’s also reported as bugs #311641, #309356, and #307589.

In my case I have 3 monitors on one video card. The card and all three monitors are detected correctly, but after I reboot the “Position” settings have all reverted to what they were when I first installed KDE.

I can change the position settings back to the correct settings, click “Save as Default”, log  out, log in, and the position settings have once again reverted to what they were when I first installed KDE.

After trying several things I still haven’t fixed the problem (I suspect a timing issue in the KDE startup) but I did figure out a work-around that anyone can use to “fix” their system so their monitors come up correctly. I posted the work-around on bugs.kde.org and I’m also posting it here.

Here’s how you do it:

Get your monitors set up the way you want them using Configure Desktop > Display and Monitor and click “Save as Default.” This updates the file ~/.kde4/share/config/krandrrc.

Open ~/.kde4/share/config/krandrrc, copy everything on the line after “StartupCommands=”. In my case the line looks like this:

xrandr --output DVI-I-1 --pos 1680x0 --mode 1680x1050 --refresh 60\nxrandr --output DP-0 
  --pos 3360x0 --mode 1680x1050 --refresh 60\nxrandr --output DVI-D-0 --pos 0x0 --mode 1680x1050
  --refresh 60\nxrandr --output DVI-I-1 --primary

Create a new script called ~/bin/workaround-for-kde-bug-312190.sh:

mkdir -p ~/bin
vim ~/bin/workaround-for-kde-bug-312190.sh

(If you don’t like vim, use whatever editor you like.)

Paste the line into the script file.

Change the “\n” characters into actual newlines so you end up with each “xrandr” command on a separate line. In my case I ended up with:

xrandr --output DVI-I-1 --pos 1680x0 --mode 1680x1050 --refresh 60
xrandr --output DP-0 --pos 3360x0 --mode 1680x1050 --refresh 60
xrandr --output DVI-D-0 --pos 0x0 --mode 1680x1050 --refresh 60
xrandr --output DVI-I-1 --primary

These are the settings for MY desktop. Yours will look different!

Make it executable:

chmod +x ~/bin/workaround-for-kde-bug-312190.sh

Run the script ~/bin/workaround-for-kde-bug-312190.sh. Your monitors should still be set up correctly. If they’re messed up, you probably didn’t cut and paste the line correctly. Repeat the above steps again.

Pick Autostart from the KDE menu. (Use the Search function if you can’t figure out where it’s buried.)

Click “Add Script” and paste the line “~/bin/workaround-for-kde-bug-312190.sh” into the “Shell script path” text box.

Click OK, click OK.

The next time you restart KDE it will still start up with the wrong configuration, then Autostart will execute ~/bin/workaround-for-kde-bug-312190.sh and fix the problem.

Leave a Comment

How to roll-over / move / rotate an Asterisk Master.csv call detail record (CDR) file every 15 minutes

If you are trying to provide CDR files to a billing service, such as WebCDR.com, you need to provide files containing your latest call data every 15 minutes or so. I wrote a script and a cron job that will create a new CDR file every 15 minutes with the latest CDR records, without interrupting call flow. You do not need to make any changes to your Asterisk configuration to use these scripts.

Setup

There are two files that you need to install on your Asterisk server:

  • asterisk-cdr-rollover.sh – A bash shell script. Copy this file into /usr/local/bin. This script moves the file /var/log/asterisk/cdr-csv/Master.csv to a new file named /var/log/asterisk/cdr-csv/cdr-YYYYMMDDHHMISS.csv, where YYYYMMDDHHMISS is the current time. A new zero-byte Master.csv file is created using the default umask of the user running the asterisk process. Asterisk will start writing to the new Master.csv file at the end of the next call.
  • asterisk-cdr-rollover – This is a cron job. Copy it into /etc/cron.d and it will run the /usr/local/sbin/asterisk-cdr-rollover.sh script once every 15 minutes.

The cron job is set up to run as the user “asterisk”. If you are running asterisk as “root” or some other user name, edit the asterisk-cdr-rollover cron job and change the name of the user running the script to the same name as the user running the asterisk process.

The latest versions of these two files can be downloaded from GitHub: https://github.com/earlruby/asterisk-cdr-rollover. The code is licensed under the GNU General Public License (GPL-2.0).

I hope you find this useful.

Comments (1)

Installing Google Maps on an iPhone 5 and iOS6

One of the reasons I bought an iPhone in the first place was so I could use Google Maps to navigate San Francisco’s public transit systems. I just started working in the City a couple of years ago and I went and bought an iPhone so I could punch in the address of where I wanted to be and the phone would tell me “go two blocks down and get on the #10 bus (which will be at the bus stop in 3 minutes).” I could even watch the phone’s GPS marker show me where I was so I knew when to get off the bus or MUNI or BART or whatever. I’ve since taken my phone to other cities and I don’t even bother to rent a car if the city has a decent transit system. I can navigate the ‘L’ in Chicago or Portland’s MAX transit using Google Maps.

So I was not happy to hear that Apple was replacing Google Maps on iOS 6 / iPhone5 with their own mapping program that doesn’t support public transit systems the way that Google Maps does. Not only that, they won’t let you download the Google Maps app from the iTunes store because they don’t want it to compete with the Apple Map app.

Luckily there’s an easy work-around that allows you to install Google Maps using a web shortcut:

 

Start up Safari on your iPhone.

 

Type “maps.google.com” into the location bar.

iPhone Safari Location Bar

 

Click “yes” if it asks if it can use your location.

 

Click the bookmark button at the bottom/middle of the screen.

iPhone Safari Bookmark Button

 

Select “Add to Home Screen”

iPhone Bookmark Options

 

You should now have a new “Google Maps” app on your iPhone screen that links you directly to maps.google.com. It doesn’t look exactly like the old app, but all of the functions are there, including the ability to plan a route using public transit.

Hope you find this useful.

Comments (7)

Getting rid of self-resizing windows in Ubuntu Linux 12.04

I’ve been using a pre-release “daily build” installation of Ubuntu 12.04 “Precise Pangolin” and noticed that current default for Gnome is for windows to resize themselves when you get close to the edge of the screen. I have two 22″ widescreen monitors and if I moved a window near the top edge it would maximize and fill the screen. If I moved a window to any edge Gnome would decide for me that what I “really” wanted was to enlarge the window to fill half the screen or do something else equally annoying. This might work well on a 10″ netbook screen, but on dual 22″ monitors it’s annoying as hell.

I tracked the problem down to a setting in Compiz, the screen compositing tool used by many Linux desktop environments, so if you’re using KDE or Unity with Compiz and you’re finding self-resizing windows irritating this fix should work for you as well.

To fix the problem you need to install the CompizConfig Settings Manager, so fire up Synaptic Package Manager and search for “compizconfig-settings-manager” and install it.

Once installed, if you’re using Gnome go to Applications > System Tools > Preferences and click “CompizConfig Settings Manager” to start the tool.

Scroll down to “Window Management.”

Uncheck “Place Windows”.

Leave “Grid” checked, but click the word “Grid” to get the Grid settings, then go to the Edges tab and change all Resize Actions to “None”.

Click Back.

Now your desktop will do what you tell it to do, rather than second-guessing you and doing something that you do not want.

One thing that you can now do (that you probably really don’t want) is to have the title bar (and it’s controls) move off-screen, which means you can’t move or resize the window unless you Alt-right-click on it. To fix that issue:

Check the “Put” plugin.

Click the word “Put” to bring up more options, go to the “Misc Options” tab, check “Avoid Offscreen”, click Back, then Close Window.

Hope you find this useful.

Comments (20)

Synchronizing Thunderbird e-mail filters using Dropbox

Two words: Use symlinks.

If you already know what a symlink is then you don’t need to read the rest of this article. If you want a better explanation, read on…

I use the Thunderbird e-mail client to read mail stored on my company’s IMAP mail server. I have a lot of filters set up that sort the mail into different folders, and Thunderbird stores the filter definitions in a file called msgFilterRules.dat. I read mail on different machines, some running various Linux distros and some running Mac OS X. I wanted all of the different machines to use the same rules for filtering e-mail into different folders, and if I make changes to the filters on one host I want those changes to take effect on all of the other hosts as well.

To do this I first set up a Dropbox account and installed the Dropbox software on my different machines, so now there’s a directory called “Dropbox” in my home directory that is synchronized between all of my different machines. I moved my filter file into the Dropbox directory and symlinked that to the location where Thunderbird expects to find the filter rules.

The step-by-step explanation if you want to do this:

Set up Dropbox on all of your machines.

Shut down Thunderbird if it’s running.

Start up a terminal window.

Find the msgFilterRules.dat file that you want to use as your “master” copy. On both my Mac laptop and Linux hosts the file is stored in ~/.thunderbird/[profile name]/ImapMail/[imap server name]/, where [profile name] is your Thunderbird profile name on that host, usually some random characters followed by ‘.default’. (Type cat ~/.thunderbird/profiles.ini if you want to see all of your profile names.)

Make a backup copy of the msgFilterRules.dat file:

cd ~/.thunderbird/[profile name]/ImapMail/[imap server name]/

cp msgFilterRules.dat msgFilterRules.dat.backup

Move the filter file to Dropbox:

mv msgFilterRules.dat ~/Dropbox/

Symlink the Dropbox copy of the file to the current directory, where Thunderbird expects to find it:

ln -s ~/Dropbox/msgFilterRules.dat .

Verify that the symlink was created correctly:

ls -al

You should see a line that looks like:

lrwxrwxrwx  1 earl users        37 Oct 25 21:12 msgFilterRules.dat -> /home/earl/Dropbox/msgFilterRules.dat

Now the machine you’re on is using the Dropbox copy of the filter file. To set this up on your other machines:

Verify that the file exists in the ~/Dropbox directory:

ls -al ~/Dropbox

Get to the directory where the filter file lives, remove the local copy, then create the symlink:

cd ~/.thunderbird/[profile name]/ImapMail/[imap server name]/

rm msgFilterRules.dat

ln -s ~/Dropbox/msgFilterRules.dat .

One word of warning: Thunderbird reads the filters into memory when it starts, and writes them back to disk when it exits. That means that if you have two hosts and Thunderbird is running on both of them, the last host that exits will write it’s version of the filters to disk. So if you make a change to the filters on one host and exit from Thunderbird, then exit from Thunderbird on the second host, the older filters on second host will overwrite the filter you just added. Because of this, I recommend exiting from Thunderbird whenever you leave your computer. I added a “killall thunderbird-bin” that runs from cron at 2am just to make sure that my copy at work isn’t running if I check mail from home in the morning.

Comments (5)

Fixing the “broken horizontal scrollbar” problem in LibreOffice Calc

This problem affects people using the KDE4 desktop with the “Oxygen” style and a recent version of the LibreOffice suite. (I’m running LibreOffice 3.4.2 on OpenSUSE 11.4) The horizontal scrollbar in Calc just doesn’t work, so if your spreadsheet is wider than your screen you can’t use the scollbar to view the right hand side.

The problem is with the Oxygen widget style. On a host running OpenSUSE 11.4 you can change this by going to:

Applications > Configure Desktop > Application Appearance > Style

Then set “Widget Style” to any style except “Oxygen”. Click Apply.

Problem solved.

Comments (2)