Friday, 15 September 2017

Use crontab to notify when a piece of software has been released

Sometimes I eagerly await the release of a distro version or a new version of a piece of software. But I don't want to remember to check constantly, so I wrote a script that can be run from cron to let me know.

#!/bin/sh
case $# in
0|1)
       echo Usage: $0 url message

       exit
       ;;
esac
url="$1"
shift
wget -q --spider "$url" && echo "$@"


As you can see, this runs a wget on a specified URL which does not produce any output, but if successful, will print the message. Put this in crontab and the message will be mailed to you.

This script depends on knowing a URL that will exist when the release happens. Often you can guess the URL from previous releases. Here are a couple of examples, each is all on a single line:

1. Check at 0808 every day to see if AntiX 17 has been released:

8 8 * * * watchurl https://sourceforge.net/projects/antix-linux/files/Final/antiX-17/ AntiX 17 released

2. Check at 0809 every day to see if VirtualBox 5.1.30 has been released:

9 8 * * * watchurl https://www.virtualbox.org/download/hashes/5.1.30/MD5SUMS VirtualBox 5.1.30 has been released


Rebuild kernel modules for VirtualBox on Linux automatically

I prefer to install packages distributed by VirtualBox rather than packages built by the distro maintainers as I don't have to wait for a new package when a new kernel is released. Unfortunately this involves rebuilding the vbox kernel modules after the new kernel is booted. So I decided to devise a way to automate this.

First I wrote a script to check if the vbox modules are loaded and if not to run the setup script. It's just this:

#!/bin/sh
sleep 120
if ! lsmod | grep -s vbox > /dev/null
then
       /usr/lib/virtualbox/vboxdrv.sh setup
fi


The sleep is needed as in some init systems cron comes up even before all the modules are loaded. Next, I installed a crontab entry that runs the script above once at bootup, using the @reboot notation:


@reboot /root/bin/vboxdrv

This goes into root's crontab, using crontab -e.

And voilĂ , that's all that's needed.

Friday, 11 August 2017

Fix for format problem importing contacts from Yahoo into Outlook via CSV format

After some unpleasantness with Yahoo mail blocking mail to friends addressed in the BCC field by mistakenly labelling my mail as spam, causing me to have to change the password, I decided to phase out my Yahoo mail account and use Outlook instead for sending out tidbits of interest. So I needed to export my contacts from Yahoo to Outlook.

I followed instructions found on the Internet for transferring contacts Yahoo to Outlook, but Outlook kept saying that the imported CSV file was not in the required format.

So I decided to look at a contact export file from Outlook to see what the difference might be. The first thing I noticed was that it had the Byte Order Mark, U+FEFF, at the beginning.

So I processed the CSV file with this Linux pipeline, the unix2dos is to change NL to CR-NL for good measure:

unix2dos < yahoo_contacts.csv | uconv -f ascii -t utf-8 --add-signature > y.csv

uconv is from the ICU package. After that I imported y.csv with no problems. Success!

Friday, 12 May 2017

A variety of mail address change protocols

I'm currently in the process of phasing out one email address and going through accounts I have on websites. In the process I've encountered a lot of variations on protocol and praxis. I'll start with the most secure examples:
  • Confirmation required on both the old and new addresses.
  • Confirmation required on the new address and notification to the old one, or vice versa.
  • Can just edit and save, perhaps with notification afterwards. This is bad, anybody who gains access to the account can change it. Also what if you make a typo, then you're locked out.
  • No way to edit, have to ask support to change it. Surprisingly some large sites require this. One asked me to create a new account, then they would migrate the history to it.
  • There is a user initiated process but there is a glitch such as the contact email can be changed but the login ID is still the old email. Have to contact support again.
  • The user initiated process doesn't work. Have to contact support.
And a lot of websites have no way to delete the account. All you can do is hope that your password is unique and encrypted securely, and that their database doesn't get stolen some day.

Thursday, 9 March 2017

Don't halt boot if loopback mount fails

I mount the installation DVD image for my distribution with loopback mount so that I don't have to download packages if they are on the ISO image and up to date. To do this I have a line in /etc/fstab that looks like this:

/home/data/software/opensuse/openSUSE-Leap-42.2-DVD-x86_64.iso /srv/www/htdocs/42.2 iso9660 auto,ro,loop

The problem with this is that if for some reason the mount fails, say the ISO file has been renamed, or somehow the directory of the image or mountpoint are inaccessible, the boot process fails.

Enter the nofail option of systemd.mount. If the line is changed to this:

/home/data/software/opensuse/openSUSE-Leap-42.2-DVD-x86_64.iso /srv/www/htdocs/42.2 iso9660 auto,ro,loop,nofail,x-systemd.device-timeout=10

this prevents failure to mount from affecting the boot process. The problem can then be investigated after the machine has started up. The option x-systemd.device-timeout=10 specifies a shorter timeout than the default.

Thursday, 2 March 2017

Another reason for 500 Server Error from Wordpress 4.7

I tried to login to my local installation of Wordpress last night and while the home page worked, the login page resulted in a blank screen and a HTTP 500 error in error_log.

I thought it might be the move to PHP 7 by Wordpress, although I was puzzled why since it worked the last time I used it. No luck, even after upgrading my PHP packages to PHP 7, the error persisted.

So I did what I should have done in the first place, I set display_errors = On in /etc/php7/apache2/php.ini. The error was then obvious:

PHP Fatal error:  Uncaught Error: Call to undefined function gzinflate()

An install of the php7-zlib package fixed that.

I think the reason why it stopped working was that my web browsers started requesting gzip compression. That was why when I browsed the page with w3m, it worked.

There are lots of reasons why Wordpress might result in a HTTP 500 error. The takeaway lesson is that you should enable display_errors to get more clues. Remember to set it back after you have fixed the problem.

Monday, 27 February 2017

Batch service load threshold too low

In openSUSE Leap 42.2, the batch service doesn't start a job if the load average is above a threshold. This defaults to 0.8 in the source. This means that even if you have a multi-core multi-thread CPU which can handle the load, a job will not start until the CPU is fairly quiet.

Fortunately there is a command line setting to raise this threshold, see man 8 atd. What you have to do is

systemctl edit atd

and enter these lines:

[Service]
ExecStart=
ExecStart=/usr/sbin/atd -f -l 2


Then do

systemctl restart atd

A ps ax should show atd running with the new threshold. The first ExecStart resets the command line, and the second is the one that overrides the service that will be started by systemd. I have 4 cores so I chose 2. You might choose a different load threshold.

If you are running another distro that uses systemd, you should get the ExecStart command from the existing unit file, probably /usr/lib/systemd/system/atd.service and add the -l load to suit.

It would be nice if openSUSE could provide a setting for the threshold in /etc/sysconfig/atd in future.