Sunday, October 30, 2016

Bash Programs, Task Scheduler, and Random Quote Notes

This is a brief extension to my last post with some implementation notes.

First of all, I use my flash drives mounted on my PCs to store certain portable or near-portable applications, including a launcher I've described in the past, Quick Cliq. It's fairly easy to build folders of applications and utilities in Quick Cliq. I can use a utility like Voidtools' Everything Search to quickly locate desired executables and drag/drop the executable to the command region of a new menu item. It's also easy to build a Microsoft utility folder. The command region has a set utility pull down region, with a System Shortcut option (about halfway down). Then you can pick and choose your key utilities through a pop-up selection, e.g., computer management, add or remove programs, services, and task scheduler. (Note that you can also script elevated privileges, e.g., on CMD prompt, by prefacing the command with RUNAS.)

To be honest, I never played much with Microsoft's Task Scheduler. I ran into puzzling issues in trying to schedule a Bash script as described in the last post. (By the way, it's not necessary to use the -c option.) Also, one of my licensed security software products identified my batch cover file for a Bash script as "malware" and expunged it from my system. Basically, I specify bash as the command and then type the Unix-style full path to the shell script in the parameter box, e.g., "/mnt/c/Users/Ro..../.../newquote.sh"  (note that there are sometimes issues with embedded spaces,  as in "Ronald Guillemette", so I'll typically include the fully qualified file name in double-quotes). After I created the task (with repeated intervals), I could run it manually from the scheduler, and it seemed to indicate an expected next scheduled run-time but didn't seem to launch at that time. It may have been one of those quirks which can be resolved by a PC reboot. However, I decided to use the system startup event option for the defined task and rebooted; the script is running without issue at expected intervals.

One of my gripes about the gmail signature feature is that I've got to change the signature manually.through settings. This is unlike the Mozilla Thunderbird client which more conveniently allows me to attach a (fixed) html page as the signature, e.g., newquote.htm, which my homegrown Bash script yields. I would obviously prefer functionality that doesn't require changing settings to generate an updated quote signature. However, there are ways to make the manual setting easier, e.g., launch the html file into one's browser and save it as a bookmark. Then copy and paste from your browser tab/page into the gmail signature block.

Finally, one can easily generate the html code needed for the formatted signature page through a full-fledged word processing program, like industry-standard Microsoft Word.  I then use Notepad++, a freeware text/programming editor, which reads and writes html code, to splice the code segments sandwiching the randomly selected quote in my shell script. I also use Notepad++ to modify my text quote file (one quote per line).

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++.

Sunday, October 2, 2016

Journal: 10/02/16

Embedding Podcasts in Blogger 

In my recent political post, I decided to embed an audio podcast of University of Chicago "grumpy" economist John Cochrane. Over the last 8 years I've used a number of alternative methods in html coding of players, etc. It's bad enough knowing that the source clip could be withdrawn without notice; I've dealt with Google player widgets suddenly unavailable.

It turns out the html code is quite simple (HT bloggerbuster):

<audio controls=""> 
<source src="http://files.libertyfund.org/econtalk/y2016/Cochranegrowth.mp3"></source> 
If you cannot see the audio controls, your browser does not support the audio element 
</audio>

Substitute your target source file URL in place of the red-typed example. Where did I find the link? In Chrome, I right-clicked/copied the file link from the play and/or download links at the Econtalk webpage.

USB Flash Drives Are Getting Cheaper

I suspect years from now today's prices for similar functionality will seem expensive, but I couldn't pass up 64 GB USB SanDisk flash drives selling for under $15 at Walmart and bought 3 for my backup computers. (The flash drives come with a limited version of EncryptStick (e.g., you are limited to a single vault); you can license the full license for about $12 the last time I checked; you can also make a conventional SafeHouse Explorer install portable by copying the binary to the stick. It's not just about transferring data between computers. I've configured a number of freeware portable applications to run off sticks. 

My Lazarus ASUS Went Into a Coma

There's some sort of a battery issue with my backup ASUS. I explained in a recent post that during my recent trip to Arizona, I had an issue with my primary HP laptop; I had booted up the notebook and was about to attach an external drive and make it my new primary when the ASUS went dead.

As I explained in a recent post, I saw a lot of customers reporting undoing the back cover and doing a hard reset (holding the power button for over 45 seconds) in conjunction with reinserting the battery. My brief unpleasant experience with ASUS tech support also focused on a hard reset.

I hadn't started the (fully charged) ASUS for a few days after starting it up for the first time in 2 months. I was discouraged to see it hesitate to come to life again and then a couple of brief flickers of light painting the screen. This time I held the power button for 45 seconds, briefly released and then gently touched the power button again, and the device sprang to life, as if the prior struggle had never happened. Although the laptop seems fully charged, it's clear to me the battery is a problem, but I still haven't purchased decent computer tools. Since then I've started up the ASUS daily without another. incident.

The Dreaded MS 0x80073712 Update Issue

It's truly annoying to find that the one of my PC's experiencing an issue with Microsoft's latest cumulative patch KB3194496 is my workhorse PC. It has repeatedly aborted at about 10% of the download. I still haven't resolved it  as I write; the usual techniques, e.g., deleting the files stored under Windows/Software Distribution, haven't worked, and the Windows Update troubleshooter has been unable to diagnose/fix the issue (oh, it reports that it's diagnosed and fixed maybe a half dozen issues, but same old same old). If and when I fix the issue, I'll address it in a future post.