Saturday, October 8, 2016

Windows Update, New Bash Support, and a Qliner Quotes Alternative

If you read my last post, you knew I had installed the new anniversary update of Microsoft Windows on 3 of my 4 PC's (3 notebooks and 1 desktop), but the outstanding one is my workhorse PC. I tried downloading the patch and applying it manually (use of DISM and/or PkgMgr), Microsoft issued a fix-it script patch (which seemed to be tied to a class of users like previewers) which I downloaded but didn't help, and various tweaks suggested by others, including deleting a game folder and registry key. But after a couple of dozen or so attempts (and some of my experiences hauntingly paralleled others in forums (in my case the downloads would stop after about 10%, but in other cases update processes would complain of obscure corruption problems which I also attempted to track down)).

So finally yesterday I took up Microsoft's option of reinstalling a clean version of Windows 10 while keeping workfiles. (Nevertheless, I still took a system backup.) Of course, I had to spend considerable time reinstalling/configuring my applications.

One of the problems I ran into was reinstalling an application I've used in random quote email signatures, which I discussed in an earlier post. For some reason, I ran into a Net Framework compatibility issue. (The Qliner publisher, to the best of my knowledge, has abandoned the software with no recent updates.)

On the other hand, I discovered on a geek web post that Microsoft was implementing a (beta) subsystem for Linux (Windows features toggle switch via Control Panel) .  I've been professionally writing Unix shell scripts, a far more powerful, flexible alternative to Windows batch files, for over 20 years, and of course there have been PC implementations of Unix/Linux, including cygwin. This beta subsystem is not done by default; you also need to switch into developer mode via system settings (for developers section under Updates and Security). (Microsoft then downloads some of the Ubuntu Linux variant software and wants you to reboot thereafter.)

I'm not going to write a Unix shell script tutorial here. Let me simply outline a fairly simple solution. I took an html file with boilerplate before and after the random selection of a line from a quotes file ron2.txt (1 line per quote), which I had to used to customize quote selection in Qliner. I split the html file into two parts, test2 and test3. (Test2 includes the formatted signature header, and test3 has my name and contact information.) The key to my solution to selection of a random quote is the Ubuntu shuf.command.

I can call my Bash shell script newquote.sh  from a Windows batch file (newquote.bat):
bash -c "/mnt/c/Users/'Ronald Guillemette'/Dropbox/newquote.sh"
And here is the shell script newquote.sh:
#!/bin/bash
tpath="/mnt/c/Users/Ronald Guillemette/Dropbox"
cd "$tpath"
shuf -n 1 ron2.txt> nq
cat test2.HTM > new.HTM
cat nq   >> new.HTM
cat test3.HTM >> new.HTM
I have gone into Window task scheduler to have this task run every 15 minutes. I can easily modify the base source html file (for test2 and test3) and I maintain ron2.txt in Notepad++.