tag:blogger.com,1999:blog-15413715212247657842024-02-06T21:08:35.716-08:00Field Notes of an Audacious AmateurThe <i>Field notes of an Audacious Amateur</i> series is offered in the spirit of the open source movement. While the concept of open source is typically associated with computer programmers, there is a growing body of those who don't know jack about programming, but who nevertheless use the creations of open source programmers. . . .wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.comBlogger38125tag:blogger.com,1999:blog-1541371521224765784.post-86792902701682321052020-04-24T23:01:00.001-07:002020-04-29T13:59:51.038-07:00Another imagemagick trick: txt to pngI ran across an article some time ago that discussed exporting text to an image format using <tt>imagemagick</tt>'s <tt>convert</tt> option. Although it looked interesting, I wasn't sure at the time whether it would actually be useful to me in any real-world way. Since I'm now considering various schemes for making paper back-ups of some sensitive data, I've begin investigating again this means of making an image from text. So I though I'd provide a bit of documentation here and just make a comment or two on some recent tests.<br />
<br />
So the current iteration of the command I've been testing is<br />
<br />
<tt>convert -size 800x -pointsize 6 caption:@my-data.txt my-data.png</tt><br />
<br />
The -size switch performs the obvious function of setting the image size, or at least its width. The -pointsize switch defines the size of font that will be used in the text that will appear in the image--in the case of this example, a very small font. I'm sure font face can be specified as well, though I am not experimenting with that at this time.<br />
<br />
In the example given here, the name of a text file is specified. Long lines are split by the program according to the width specified, but if no width is specified the width of the image will correspond to the longest line length. The output of a command can also be directed to an image. Slightly different syntax from what is seen in this example would need to be used in that case, of course.<br />
<br />
Another <tt>convert</tt> option that works similarly to <tt>caption</tt> is <tt>label</tt>. It seemed to me the <tt>caption</tt> option was more relevant to the task I was experimenting with since a larger amount of text could be involved.<br />
<br />
The experiments I've been conducting are for the possible purpose of making a paper back-up of the sensitive data. An image file of the data could be created, printed, then the image file erased.<br />
<br />
Finally, I recently discovered that there is a fork of <tt>imagemagick</tt> called <tt><a href="http://www.graphicsmagick.org/">graphicsmagick</a></tt>. I have not looked into that very deeply or used it so far. But I will be investigating further.<br />
<br />
For reference I got my original introduction to this neat feature from an article at <a href="https://www.ostechnix.com/save-linux-command-output-image-file/">https://www.ostechnix.com/save-linux-command-output-image-file/</a><br />
<br />
More can be found at <url><a href="http://www.imagemagick.org/Usage/text/">http://www.imagemagick.org/Usage/text/</a></url>wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-79363257117191826732019-11-14T15:01:00.000-08:002020-04-29T19:49:12.608-07:00view youtube videos while browsing with elinksI recently wanted to view a youtube video using a computer that had no graphical browser installed. Long story short, the computer runs Gentoo and is used almost exclusively for recording and playback of television content: so for almost all use case scenarios, having a graphical browser is not needed, the excessive compile times they would entail (over 24 hours on this somewhat low-resource machine) being unjustifiable.<br />
<br />
I decided there must be some way, using the non-graphical browser I did have on this machine--<tt>elinks</tt>,to view youtube videos. A bit of online research revealed how I could accomplish this task. Though there is undoubtedly more than one way to skin this cat, I used the one that seemed most straightforward to me, as described below.<br />
<br />
Since I already had installed the <tt>mpv</tt> utility, all I had to do was some minor tweaks to <tt>elinks</tt>. First, I went into <tt>Setup > Option manager > Document > URI passing</tt> and added a new entry. I simply named it <tt>youtube-handle_mpv</tt>. Of course the final task for this step is to save that option.<br />
<br />
I then edited that entry, using information found at the Arch wiki entry for <tt>elinks</tt>, and added the line <tt>mpv %c</tt> (this allows <tt>elinks</tt> to feed the designated URI to <tt>mpv</tt>). Having done that, I next needed to assign a key which, when pressed, would trigger the URI passing.<br />
<br />
I went to <tt>Setup > Keybinding manager > Main mapping > Pass URI of current frame to external command</tt> and there designated the grave or backtick key as the one that would trigger the URI passing. Again I selected "save" and exited the Setup menu.<br />
<br />
After having done that, I navigated <tt>elinks</tt> to youtube's site, searched for the video I wanted to view and, having highlighted the desired link using the arrow keys, pressed the grave/backtick key. After a brief pause (for downloading and caching some of the data, I presume), <tt>mpv</tt> opened and the video began to play.<br />
<br />
NOTE: the pause between pressing the designated key and the actual playback of the video under <tt>mpv</tt> could vary based, I believe, on the length/quality of the video.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-49069856776692100692019-02-15T14:55:00.002-08:002019-04-24T13:46:51.178-07:00Stress-testing hard drivesThis entry will consist mostly in someone else's content. The back story is that, about 3 years ago on the mythtv-users list-serv, one of the list members offered such a concise, straightforward, and apparently sound description of how she tests out new hard drives, that it remained in my memory.<br />
<br />
Well, now that it has come time for me to replace an aging hard drive in my MythTV machine, it's time to dig out those directives and actually use them. And while I'm doing that, I may as well post them on this blog for future reference. Credit for the material goes to faginbagin/Helen, the user who posted it in the list-serv.<br />
<br />
Without further ado, here is the content:<br />
<blockquote class="tr_bq">
I look for drives with the longest warranty. This Christmas I bought 4 3TB HGST drives with 3 year warranties. Got to look close, because some only have 2 year warranties. Before I put any new drive into service, I use the following procedure to increase the chances it's a good drive<br />
that will last. </blockquote>
<blockquote class="tr_bq">
Capture SMART data via:<br />
<tt>smartctl -a /dev/sdx > smart0.out </tt></blockquote>
<blockquote class="tr_bq">
Write semi random data on the whole drive with:<br />
<tt>nohup shred -n1 -v /dev/sdx > shred.out & </tt></blockquote>
<blockquote class="tr_bq">
Go away for a couple of hours. Check shred.out and figure out how long<br />
it will take to finish. Come back when it should be done. </blockquote>
<blockquote class="tr_bq">
Read the whole drive and compute a checksum:<br />
<tt>nohup md5sum /dev/sdx > md5sum.out & </tt></blockquote>
<blockquote class="tr_bq">
Go away for roughly the same time it took shred to write to the drive.<br />
Read the whole drive again and make sure the checksum matches:<br />
<tt>nohup md5sum -c md5sum.out > md5sum.chk & </tt></blockquote>
<blockquote class="tr_bq">
Go away for roughly the same time it took the first md5sum to read the<br />
drive. </blockquote>
<blockquote class="tr_bq">
Write zeros to the drive:<br />
<tt>nohup dd if=/dev/zero of=/dev/sdx bs=1M > dd.out & </tt></blockquote>
<blockquote class="tr_bq">
Capture SMART data via:<br />
<tt>smartctl -a /dev/sdx > smart1.out </tt></blockquote>
<blockquote class="tr_bq">
Compare the two smart runs:<br />
<tt>diff smart0.out smart1.out </tt></blockquote>
<blockquote class="tr_bq">
Make sure there are no complaints about sectors. </blockquote>
<blockquote class="tr_bq">
Make sure the kernel didn't report any errors:<br />
<tt>dmesg| tail </tt></blockquote>
<blockquote class="tr_bq">
If no SMART or kernel reported errors, create partition table, create<br />
partitions, mount, etc... </blockquote>
<blockquote class="tr_bq">
If any errors, return immediately. </blockquote>
Original post located at http://lists.mythtv.org/pipermail/mythtv-users/2016-April/386438.htmlwayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-16872833907689327932019-01-31T13:18:00.003-08:002019-02-01T11:55:48.871-08:00dhcpcd hooks: what are they and why should you care?I know I didn't know what <tt>dhcpcd</tt> hooks were and why I should care about them. That is, until I set up a file server that runs headless and which I want to make sounds when certain events, such as the network coming up, occur. This, as may be evident, will help me ascertain whether, in absence of a monitor displaying graphical indicators, the machine booted and came online successfully--a pretty important status for a machine like a file server.<br />
<br />
<tt>dhcpcd</tt> (the final "d" stands for "daemon") is, of course, the utility that runs on a lot of Linux computers in order to get them connected to the network. It polls for an <tt>IP</tt> from whatever dhcp (dynamic host configuration protocol) server is running on the network, and the <tt>IP</tt> received gets assigned to the computer's designated network interface. So the "hooks" under discussion essentially latch onto that process and cause some other process(es) to be triggered once <tt>dhcpcd</tt> accomplishes its task. This, then, could allow me to implement the desired behavior on my headless file server<br />
<br />
I had part of the solution in place already, namely the <a href="https://wiki.archlinux.org/index.php/PC_speaker#Beep"><tt>beep</tt></a> program, a utility that allows for the playing of various tones through the <a href="https://wiki.archlinux.org/index.php/PC_speaker">pc speaker</a>. Yes, I'm aware that most computer users seem to want only to disable the pc speaker: I, on the other hand, have found it quite useful on my systems.<br />
<br />
Having done some on-line research on this matter, I was able to succeed at the task of getting the pc speaker to play a tone once the computer had booted and gotten an <tt>IP</tt> by using the following steps (geared toward the <a href="https://voidlinux.org/">Void Linux</a> distribution installed on that target system).<br />
<br />
I first created a file owned by root and in the root group in <tt>/usr/share/dhcpcd/hooks/</tt>--(call it, say) <tt>10-beeponIP</tt>--with the following content:<br />
<br />
<tt>if ([ $reason = "BOUND" ] || [ $reason = "RENEW" ])
then<br />
# your script commands here (see below for the command I used)<br />
/usr/bin/beep -f 1000 -r 5 -n -r 5 -l 10<br />
fi</tt><br />
<br />
I can't go into many specifics of the bash syntax seen in this file since I understand it rather poorly myself (it was simply lifted from the askubuntu link listed below). But some testing of its claimed efficacy revealed that it would, in fact, result in the behavior I was aiming to enable.<br />
<br />
I had to set proper permissions on that file, then symlink it. Doing the former was straightforward (permissions needed are, like the rest of the files in that directory, 444). I ran the following command to create the needed symlink: <tt>sudo ln -s /usr/share/dhcpcd/hooks/10-beeponIP /usr/libexec/dhcpcd-hooks</tt>.<br />
<br />
Having done that, on rebooting the computer, the designated tone plays though the pc speaker, letting me know that the system booted normally and is now on-line. Mission accomplished!<br />
<br />
Some links that helped me to better understand and accomplish this task are given below:<br />
<br />
<tt>https://askubuntu.com/questions/1005653/how-do-i-execute-a-script-after-dhcp-assigns-an-ip-address-on-start-up<br />
https://wiki.voidlinux.eu/Network_Configuration#Starting_wpa_supplicant_through_dhcpcd_hooks<br />
https://man.voidlinux.eu/dhcpcd-run-hooks.8</tt>wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-14704476881180239012018-11-17T11:05:00.001-08:002018-11-18T17:02:06.600-08:00Twitter Alerts: A Trick for the Twitter-averseI'm not a registered Twitter user and have never managed to think of a compelling reason to be one. In fact, the only time I ever really have or want anything to do with Twitter is when some Twitter feed comes up in an internet search. And all I do in those cases is read any relevant text and move on. I suppose I'm not much of a socialite and accordingly have little interest in social media phenomena such as this.<br />
<br />
Recently, however, I became interested in joining a service that sends out invitations periodically on Twitter. Not having an account and not being interested in much of anything else Twitter represents or offers, I'm at a distinct disadvantage in this case: what am I supposed to do, start checking it every day for possibly months on end in hopes of stumbling upon the desired invitation? Not for me, obviously.<br />
<br />
But I soon began to realize, based on other web-scraping and scheduling jobs I'd set up recently, that I would likely be able to automate the task of checking this Twitter feed for invitations. I had tools like text-mode browsers that seemed to render Twitter pages pretty well, as well as commands like <tt>grep</tt> for finding target text. And of course <tt>cron</tt> could play a key role in automating things as well. Accomplishing the task actually turned out to be quite simple.<br />
<br />
I had already set up a way to check a Twitter feed using keystrokes and rendering the text in a terminal on my desktop: <tt>elinks -dump -no-numbering -no-references https://twitter.com/TargetTwitt | tail -n +21 | head -n -8 |less </tt>seemed to do the job just fine.* The problem with that approach with regard to the task at hand is that I would need to remember to use the key combination to check for invitations daily.<br />
<br />
The next step, then, could be to recruit grep to search for target text--a keyword like "invit"--which, if found in the text essentially scraped from the Twitter feed, would trigger my machine to send me an e-mail. Since I already regularly use <tt>mailx</tt> to auto-send myself various sorts of e-mails, most of that aspect of this task was already in place as well.<br />
<br />
The command I tested and that seemed to bring together well most of these various elements is as follows: <tt>body="$(elinks -dump -no-numbering -no-references https://twitter.com/TargetTwitt | grep -A 1 -B 1 the)" && echo "$body" | mailx -s Twit-invite me@my-em.ail</tt>.** That line, of course, uses, for testing purposes, a common word (the article "the") as the searched string to prove that the whole thing will work together as expected.<br />
<br />
The command first dumps text from the Twitter feed to <tt>stdout</tt> then pipes it to <tt>grep</tt>, where <tt>grep</tt> looks for the target text-string. If the string is found, it is included--along with a couple of adjacent lines--in the body of an e-mail that <tt>mailx</tt> will sent to me (the scheme assumes that a valid <tt>smtp</tt> transport mechanism has been set up for <tt>mailx</tt>--a topic beyond the scope of this brief post). If the term is not found--something I also tested by changing the search term to one I was sure would not be included in the twitter feed--nothing further is done: the scraped text simply gets discarded and no e-mail is sent.*** The test passed with flying colors, so the only remaining thing to implement was to set up a daily <tt>cron</tt> job.<br />
<br />
Though this configuration seems to work well and looks as though it will serve my purposes just fine, it likely could be improved upon. Should any readers of this blog have suggestions for improvements, feel free post them in the comments section below.<br />
<br />
<br />
* <tt>lynx</tt>, <tt>cURL</tt>, <tt>wget</tt>, and other tools could easily likely replace <tt>elinks</tt>, and might even be more effective or efficient. Since I know <tt>elinks</tt> fairly well and I use it for other similar tasks, I did not investigate any of those.<br />
<br />
** Command found and copied in large part from https://unix.stackexchange.com/questions/259538/grep-to-search-error-log-and-email-only-when-results-found.<br />
<br />
*** More precisely, I think what happens is that when a string is searched for using <tt>grep</tt> and is not found, <tt>grep</tt> returns exit code 1, which, in the case of this series of commands, means the process does not proceed to && (which means something like "proceed to the next command on successful completion of the previous command"). wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-91223277338573783442016-10-20T14:00:00.000-07:002016-10-20T16:40:20.618-07:00Discussion topic 1: vim or emacs for personal wiki, etc?Instead of my more typical how-to, this posting will aim to solicit input from readers. I realize I may be inviting some sort of flame war,
but rest assured that my intentions are sincere: I really am largely ignorant of the respective virtues and and flaws of the two utilities on
which I want to solicit input, having barely dabbled in either. My hope is that I might get input here on which will be the more worthwhile
one to put further effort into learning.<br />
<br />
First, a bit about my aims. I set up for myself some time ago a personal wiki--a vehicle for keeping track of inspiring ideas, tasks on which
I am now working, or will need at some point in the future, to work, and a receptacle for various tech tips I have employed and which I may
need again in the future to use, but which I have difficulty remembering. I wanted the wiki to be accessible to me, not just at home, but
from the internet as well. Much as I wanted to keep the wiki's set-up and maintenance simple, at the time I deemed that deploying it under a
web-serving scenario would be required. To that end, I implemented the <code>MoinMoin</code> wiki on a machine I administered.<br />
<br />
That scenario has worked out acceptably well over the last few years. But it is now time to take that machine out of service. So I will be
needing to reconstitute my wiki and so am revisiting the matter of how I will set up and administer it.<br />
<br />
Having a preference for simple, resource-frugal utilities, I am hoping I might migrate my wiki to some command-line interface. The overhead and complexity of the web server most wikis involve is not really justified for my use case: in fact, I might be engaging in a bit of hyperbole in claiming that I use what I have as a real wiki--it's used more like just an organizer.<br />
<br />
Under my best-case envisioned scenario, I could either ssh into my machine to consult and/or modify my wiki, or perhaps even host it at a shell account to which
I have access. It's an appealing thought and one I hope I will soon be able to implement.<br />
<br />
So far as I can tell, the two candidate command-line tools I might use for this are <code>vimwiki</code> and <code>emacs</code> in <code>org-mode</code>. And I must admit
that my experience with both has been very slight. In fact, I've tried to avoid using either <code>vim</code> or <code>emacs</code>, typically gravitating to
<code>nano</code> for the sorts of needs either of those utilities might otherwise fulfill. Perhaps <span style="font-family: monospace;">emacs</span> will be slightly more preferable since development on the <span style="font-family: monospace;">vimwiki</span>plugin seems to have ceased a little over 4 years ago, while <span style="font-family: monospace;">emacs org-mode</span> seems to have a quite active and extensive user and development base.<br />
<br />
Both utilities, with their arcane interfaces and keystroke options have left me baffled and even trapped on more than one occasion. Having a
few years of command-line interaction under my belt, I did recently manage a bit of experimentation with <code>emacs org-mode</code>--at least enough to
convince me that it could be a suitable new vehicle for my wiki.<br />
<br />
I had pretty much written off <code>vim</code> as a possible vehicle since, in past attempts to utilize it, I have found it even more obtuse and
intractable than <code>emacs</code>. But that situation recently changed somewhat when I realized that one of the best tools for doing some routine
maintenance on one of my Arch systems employs <code>vimdiff</code>. Having used that a few times, I can now say that I've recently managed, under the
guise of <code>vimdiff</code>, to use <code>vim</code> successfully for some system maintenance tasks.<br />
<br />
And just today I learn that emacs has its own <code>diff</code> implementation--<code>ediff</code>--as well. So <code>emacs</code> might also be serviceable in the
system-maintenance capacity, should I decide that it will be more worthwhile to try and better learn <span style="font-family: monospace;">emacs org-mode</span>.<br />
<br />
Bottom line here is that it looks as though I am going to be using one or other of these utilities routinely, so it is time I started
learning it better. And I can, at the same time, use whichever I will be learning better, as the new vehicle for my wiki.<br />
<br />
So I am looking for guidance and recommendations on which is likely better to suit my needs and disposition--or whether I might even have overlooked some other command-line utility for creating an maintaining a personal wiki. I should state that I am unlikely ever to do any
sort of programming, so whatever may be the relative advantages of either with respect to coding, will be largely irrelevant for me. Rather,
I would be using them for perhaps some simple editing functions, and mostly for some routine maintenance tasks (comparing updated config
files with files already on my system) and for managing my wiki.<br />
<br />
Let the discussion begin.<br />
<br />
Afterthought: perhaps even creating a markdown file containing my wiki's material, then converting that to html for viewing with <code>elinks/lynx</code> could even work? In other words, a sort of homebrew solution?wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-52906738226385110912016-06-18T07:55:00.000-07:002020-04-30T18:39:46.799-07:00Another addendum to the seventh installment: imagemagick as a resource for the budget-constrained researcher continuedContinuing on the theme of the last couple of entries, the budet-contrained researcher may own or wish to acquire a piece of hardware that can aid him in obtaining needed materials from research libraries. For example he may need but a single article or perhaps a chapter from a book. Or maybe a bibliography. Obtaining limited segments of larger works such as those mentioned may be more difficult through inter-library loan channels, especially in the case of works that may contain more than one item of potential interest. It can happen that the researcher will need to go in person to inspect the work to decide which part is actually required.<br />
<br />
Suppose the researcher is already on the premises of the local academic library and has located target material. Should he not wish to check out a book, he is left with the option of himself scanning the material. Of course these libraries often have scanners that they make available to patrons, so that is one possible option. Yet another option is for the researcher to use his own scanner, and this is where highly portable hardware such as the Magic Wand portable scanner comes in.<br />
<br />
I invested in one of these a few years ago and it has proved quite useful. One of the problems with using it, though, is that, for the bulk of books and journals (i.e., those of more standard size) it seems to work best to scan pages sideways--horizontally, rather than vertically. In other words, it works best to start from the spine and to scan toward page edges. This, obviously, entails that roughly every other page will have been scanned in a different orientation from the page preceding.<br />
<br />
Once all pages are scanned, they can be easily rotated in bulk to the desired orientation--by 90 or 270 degrees, as the case may be--using <tt>imagemagick</tt>'s <tt>mogrify</tt> switch, like so; <tt>mogrify -rotate 90 *.JPG</tt> (a command like <tt>convert -rotate 270 PTDC0001.JPG PTDC0001-270rotate.jpg</tt> would perform much the same function while preserving the original file). In my case, it seemed best to first copy all odd, the all even, image files to separate directories prior to rotating them.<br />
<br />
At this point, I needed to name all files with either odd or even numbers. My <tt>bash</tt> scripting skills being modest at best, I began scouring the internet for a solution that would aid me in doing this sort of bulk renaming. I found such a script at <a href="http://www.linuxquestions.org/questions/programming-9/bash-script-for-renaming-files-all-odd-617011/">http://www.linuxquestions.org/questions/programming-9/bash-script-for-renaming-files-all-odd-617011/</a> and a bit of testing proved it to be a solution that would work for me.<br />
<br />
I modified the script into 2 variants and named one rename-all_odd.sh and rename-all_even.sh. The scripts look as follows:<br />
<br />
<textarea name="code" cols="70" rows="9" wrap="off">#!/bin/bash
# rename all files having .JPG extension in current directory with an odd 4-digit numeral series
# found at http://www.linuxquestions.org/questions/programming-9/bash-script-for-renaming-files-all-odd-617011/
#
num=1
for file in *.JPG; do
mv "$file" "$(printf "%04u" $num).jpg"
let num=num+2
done</textarea>
<br />
and<br />
<br />
<textarea name="code" cols="70" rows="10" wrap="off">#!/bin/bash
# rename all files having .JPG extension in current directory with an even 4-digit numeral series
# for use with image files created using Magic Wand handheld scanner
# found at http://www.linuxquestions.org/questions/programming-9/bash-script-for-renaming-files-all-odd-617011/
#
num=2
for file in *.JPG; do
mv "$file" "$(printf "%04u" $num).jpg"
let num=num+2
done</textarea>
<br />
It was then a simple matter of copying all the renamed files into a separate directory and concatenating them into a <tt>pdf</tt>, as was covered in a previous installment.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-24550245827908716572016-03-27T16:23:00.002-07:002016-03-28T14:46:51.849-07:00Miscellaneous Monday quickies: manipulating and excising pages from pdfsSo you've gotten, via inter-library loan, the <tt>pdf</tt>'s you requested to aid you in researching the article you're writing. For purposes of putting them on your e-reading device, the form they're in is probably perfectly suitable. But what if you'd like to do other things with one or more of them, such as printing them out? There is quite a range of <tt>pdf</tt> manipulation tools that can help you put them in a form more congenial to such aims.<br />
<br />
One that I recently discovered, for example, allows you to "n-up" your <tt>pdf</tt> document, i. e., to put more than one page per sheet of paper. Should you wish to print the document, this can help you lessen paper waste. The utility is called <tt><a href="http://manpages.ubuntu.com/manpages/wily/man1/pdfnup.1.html">pdfnup</a></tt>, and the relevant command for accomplishing this end is <tt>pdfnup --nup 2x2 myfile1.pdf myfile2.pdf</tt>. Presumably one could use 4x4 in place of 2x2 to get four pages per sheet instead of two.<br />
<br />
This utility gives results similar to <tt><a href="http://manpages.ubuntu.com/manpages/hardy/man1/psnup.1.html">psnup</a></tt>, a utility I have used (and previously <a href="http://audaciousamateur.blogspot.com/2014/04/miscellaneous-friday-quickies-crop-pdf.html">witten about</a> in this blog) in the past for making booklets comprised of multiple pages per sheet of paper, though <tt>pdfnup</tt> likely lacks the advanced collating options of <tt>psnup</tt>. But <tt>psnup</tt> involves greater complexity in that it operates on postscript files, which usually need to be converted to or from some other format.<br />
<br />
Getting back to the task at hand, should you wish to print out any of your <tt>pdf</tt>'s with the aim of minimizing paper waste, you may well wish to eliminate extraneous pages from your document. In my experience, for example, inter-library loan <tt>pdf</tt> documents routinely include one or more copyright notice pages. Before printing such documents, I almost always try to exclude those pages--simple enough if you send them directly from the printer from a <tt>pdf</tt> reader. But what if you're taking the additional step of n-upping multiple pages per sheet?<br />
<br />
As it turns out, <tt>pdfnup</tt> is actually part of a larger <tt>pdf</tt>-manipulation suite called <tt><a href="http://www2.warwick.ac.uk/fac/sci/statistics/staff/academic-research/firth/software/pdfjam/">pdfjam</a></tt>. And that suite enables you to not only n-up your <tt>pdf</tt> document, but to eliminate extraneous pages as part of the same process. To give an example, if you have a fifteen page document wherein the first and last pages are copyright notices that you wish to exclude from your 2-upp'ed version, you'd use the command<br />
<br />
<tt>pdfjam MyDoc.pdf '2-14' --nup 2x1 --landscape --outfile MyDoc_2-up.pdf</tt>.<br />
<br />
The meaning of the various command switches will, I think, be obvious.<br />
<br />
This is just a thin slice of the capabilities offered by just one suite of <tt>pdf</tt> manipulating tools available under GNU/Linux. I have used other tools such as <tt><a href="http://pdfedit.cz/en/index.html">pdfedit</a></tt>, <tt><a href="https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/">pdftk</a></tt>, <tt><a href="http://flpsed.org/">flpsed</a></tt>, to good effect as well.<br />
<br />
LATER EDIT: I just discovered a new and interesting functionality of <tt>pdfjam</tt>; it can convert <tt>pdf</tt>'s from a4 to letter format (and vice versa). The relevant command is <tt>pdfjam --paper letter --outfile out.pdf in.pdf</tt>wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-41195509720782909092016-03-21T15:14:00.001-07:002016-03-24T11:47:04.909-07:00Addendum to the seventh installment: imagemagick as a resource for the budget-constrained researcherIn this installment, I'll cover concatenating multiple image files into a multi-page <tt>pdf</tt>--a very handy trick the <a href="http://www.imagemagick.org/script/index.php"><tt>imagemagick</tt> </a>utility <a href="http://www.imagemagick.org/script/convert.php"><tt>convert</tt></a> makes possible. But first, a bit of grousing on the subject of academia, budget-constrained researching, and academic publishing.<br />
<br />
Pricing for on-line academic resources tends, not surprisingly, to be linked to budgetary allowances of large academic institutions: what institutions can afford to pay for electronic access to some journal or other, for example, will influence the fee that will be charged to anyone wishing to gain such access. If one is affiliated with such an institution--whether in an ongoing way such as by being a student, staff, or faculty member, or in a more ephemeral way, such as by physically paying a visit to one's local academic library--one typically need pay nothing at all for such access: the institution pays some annual fee that enables these users to utilize the electronic resource.<br />
<br />
But for someone who has no long-term affiliation with such an institution and who may find it difficult to be physically present in its library, some sort of payment may be required. To give an example, while doing some research recently for an article I'm writing, I found several related articles I need to read. I should mention that, since I am still in the early stages of writing my article, there are bound to be several additional articles to which I will need ongoing access. I will address two journal articles in particular, both of which were published between twenty and thirty years ago.<br />
<br />
I discovered that both articles were available through an on-line digital library. I was offered the option of downloading the articles at between twenty and forty dollars apiece. At that rate--since one of my articles' main topics has received fairly scant attention in modern times and I might need to review only another twenty or so articles--it could cost me well over six hundred dollars just to research and provide references for this topic. The time I spend actually writing and revising the article--the less tangible cost, which will exceed by a substantial amount the time spent researching--is an additional "expense" for producing the material.<br />
<br />
There are, of course, ways to reduce the more tangible costs. Inter-library-loan often proves a valuable resource in this regard since even non-academic libraries who may lack subscriptions to academic publishers or digital libraries can nonetheless request journals or books containing relevant articles or, even better yet, obtain for their patrons such articles in electronic format--typically <tt>pdf</tt> files--these latter often having been created by scanning from paper-and-ink journals or books.<br />
<br />
Some digital libraries even offer free--though quite limited--access to their materials. In researching my project I found three articles available from such a site. On registration at their site, they offered free on-line viewing, in a low-resolution scan, of just a couple of articles--those being made available for viewing for only a few days. Once the limited number of articles was reached, only at the end of those few days could another article be viewed. For purposes of the budget-constrained researcher, while this is a promising development, it's not an entirely practicable one.<br />
<br />
Being able to view an article on a computer screen is a lot better than having no electronic access to it at all. But it also is of no help in those circumstances where one may be without an internet connection. Having the ability to save the article to an e-reader would be preferable and far more flexible than reading it, one page at a time, in a browser window. But the service seems calculated to preclude that option without payment of the twenty- to forty-dollar per article fee. It turns out, however, that sometimes ways around such restrictions can be discovered. And that, finally, is where the tools mentioned in the first paragraph of this article enter in. Thus, without further ado, on the the technical details.<br />
<br />
Some digital libraries actually display, on each page of the article that appears as you go about reading it in a web browser window, a low-resolution image of the scanned page. As I discovered, one can right-click on that image and select to save it to the local drive. The file name may have, instead of a humanly-comprehensible name, just a long series of characters and/or numbers. And it may, as well, lack any file extension. But I discovered that the page images could, in my case, be saved as <tt>png</tt> files. Those <tt>png</tt> files, then, appropriately named so as cause them to retain their proper order, could then, using imagemagick tools, be concatenated into a multi-page <tt>pdf</tt>. That multi-page <tt>pdf</tt> can then be transferred to the reading device of choice. I found that, although the image quality is quite poor, it is nonetheless sufficient to allow deciphering of even such smaller fonts as one typically finds in footnotes. Although involving a bit of additional time and labor, using this tactic can yet further defray the budget-constrained researcher's more tangible costs.<br />
<br />
For reasons that will become obvious, the image files should be saved to a directory empty of other <tt>png</tt> files. How the images are saved is essentially a numerical question and is dependent on the total number of pages in the article. If the total number of pages is in the single digits, it would be a simple matter of naming them, for example, <tt>1.png</tt>, <tt>2.png</tt>, <tt>3.png</tt>, and so forth. If the number of pages reaches double digits--from ten through ninety nine, zeros must be introduced so that all file names begin with pairs of numbers; for example <tt>00.png</tt>, <tt>01.png</tt>, <tt>02.png</tt>, and so forth. The same formula would hold for--God forbid, since the task would become quite tedious--articles with total pages reaching triple digits.<br />
<br />
Provided imagemagick is already installed, once the saving is done, the very simple formula <tt>convert *.png full-article.pdf</tt> can be used to produce the <tt>pdf</tt> of concatenated image files. Since the files have numerical prefixes, the program will automatically concatenate them in the proper order.<br />
<br />
In the next installment I will be covering manipulation of <tt>pdf</tt>'s provided through inter-library loan services--focusing on removal of extraneous pages (e.g., copyright-notice pages) routinely included by those services. wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-44691247744060639912016-02-04T09:06:00.002-08:002016-02-04T09:56:26.296-08:00Miscellaneous Thursday quickies: what's your bi-directional syncing utility?So I've been pursuing a research project for the last year or so and have been locating and saving material related to it, as well as doing some of my own writing in the area. I keep that material in a particular folder. That's all fine and good. The problem is that I want the ability to work on the project while I'm at any of 3 different computers--computers that are often located in 3 different locales, some of which are even remote from my LAN. So, how to host the same folder on all three machines, and keep it current with the most recent changes made on any of the 3 computers?<br />
<br />
I intend for this to be a manual process, i.e., one that will involve me manually running some program or script on each of the three machines, in order to update the folder. I should also mention that I have access to a shell account where I can run a number of utilities that can facilitate this--so a 4th computer, technically speaking, is involved as well. I envision the shell account functioning as a sort of central hub for keeping said folders in sync: a sort of master copy of the folder can be stored there and each of the three machines can syncronize with that folder as need will arise.<br />
<br />
I'm still trying to puzzle out how to pull all this together and am looking at the sorts of software/utilities that can accomplish the task. I've only tested out one option thus far--<tt>bsync</tt>. I opted for that in an initial foray for its simplicity: it's just a python script that enhances the functionality of <tt>rsync</tt> (a great sync utility, but one that does not do bi-directional synchronization). So all I needed to do was download the script and make it executable.<br />
<br />
Using the utility, I was able to put the most current copy of the folder at my shell account by just running <tt>bsync MyFolder me@my.shellacct.com:MyFolder</tt> (the MyFolder directory must already exist at the remote address). So I've at least made a beginning.<br />
<br />
That said, I'm still in the early stages of investigating approaches to do the sort of bi-directional synchronization I'm after. Tests with <tt>bsync</tt> have gone well so far but, if I'm understanding correctly, this utility does not deal well with sub-folders--which could be an issue in my use scenario; it seems <tt>bsync</tt> will work best on a folder or directory that contains only files, while my directory has a few sub-directories under it.<br />
<br />
Other possible options I've found are <tt><a href="https://www.csync.org/">csync</a></tt> (which uses <tt>smb</tt> or <tt>sftp</tt>), <tt><a href="https://github.com/deajan/osync">osync</a></tt>, <tt><a href="https://github.com/sickill/bitpocket">bitpocket</a></tt>, and <tt><a href="http://www.freefilesync.org/">FreeFileSync</a></tt>. The first 3 of these are most attractive to me since they are command-line utilities. <tt>FreeFileSync</tt> is a graphical utility, though it does appear that it can be run from the command line as well. I should also mention <tt><a href="https://www.cis.upenn.edu/~bcpierce/unison/">unison</a></tt>, which I've looked at but not pursued--the reason being that it apparently requires that the same version be installed on all concerned machines, which is something that will be unrealistic in my case (Arch runs on 2 machines, an older Ubuntu on another, and BSD on the fourth).<br />
<br />
So, what is your bi-directional synchronization software preference? Any further tips or pointers to add on accomplishing this task?wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com16tag:blogger.com,1999:blog-1541371521224765784.post-33827215988968355162016-01-12T22:17:00.001-08:002016-01-14T09:17:42.771-08:00Addendum to 11th installment: Lynx; scraping credentialed web pagesSort of a dramatized headline for what I've accomplished using the command-line <a href="https://en.wikipedia.org/wiki/Lynx_(web_browser)">Lynx</a> browser, but not too far from the mark. I've described in previous <a href="http://audaciousamateur.blogspot.com/2013/01/11th-installment-lynx-your-own-personal.html">entries</a> how I've used <tt>lynx</tt> to accomplish similar goals of extracting target information from web pages, so this entry is a continuation along those same lines.<br />
<br />
I recently signed up for a prepaid cellular plan touted as being free, though it is one limited to a certain (unreasonably low, for most) number of minutes per month. The plan has thus far worked well for me. The only real issue I have come across is that I had not yet discovered any way easily to check how many minutes I've used and how many are left. The company providing the service is, of course, not very forthcoming with that sort of information: they have a vested interest in getting you to use up your free minutes, hoping thereby that you'll realize you should buy a paid plan from them, one that includes more minutes. The only way I'd found for checking current usage status is to log in to their web site and click around til you reach a page showing that data.<br />
<br />
Of course I am generally aware of the phenomemon of <a href="https://en.wikipedia.org/wiki/Web_scraping">web-page scraping</a> and also have heard of python and/or perl scripts that can perform more or less automated interactions with web pages (<a href="http://youtube-dl.org/"><tt>youtube-dl</tt></a> being one example). So I initally thought my task would require something along these lines--quite the tall order for someone such as myself, knowing next to nothing about programming in either python or perl. But then I ran across promising information that led me to believe I might well be able to accomplish this task using the tried and true <tt>lynx</tt> browser, and some experimentation proved that this would, indeed, allow me to realize my goal.<br />
<br />
The information I discovered came from <a href="http://blog.unixy.net/2009/06/script-to-automate-browsing-actions-using-lynx/">this</a> page. There is found a description of how it is possible to record to a log file all keystrokes entered into a particular <tt>lynx</tt> browsing session--something reminiscent of the way I used to create macros under Microsoft Word when I was using that software years ago. The generated log file can then, in turn, be fed to a subsequent <tt>lynx</tt> session, effectively automating certain browsing tasks, such as logging into a site, navigating to, then printing (to a file, in my case) a page. Add a few other utilities like <a href="https://en.wikipedia.org/wiki/Cron"><tt>cron</tt></a>, <a href="https://en.wikipedia.org/wiki/Sed"><tt>sed</tt></a>, and <a href="https://en.wikipedia.org/wiki/Mail_(Unix)"><tt>mail</tt></a>, and I have a good recipe for getting the cellular information I need into an e-mail that gets delivered to my inbox on a regular basis.<br />
<br />
The initial step was to create the log file. An example of the command issued is as follows:<br />
<tt><br /></tt>
<tt>lynx -cmd_log=/tmp/mysite.txt http://www.mysite.com</tt>.<br />
<br />
That, of course, opens the URL specified in <tt>lynx</tt>. The next step is to enter such keystrokes are are necessary to get to the target page. In my case, I needed to press the down arrow key a few times to reach the login and password entry blanks. I then typed in the credentials, hit the down arrow again, then the "enter" key to submit the credentials. I then needed to hit the "end" key on the next page, which took me all the way to the bottom of that page, then the up arrow key a couple of times to get to the link leading to the target page. Once I got to the target page, I pressed the "p" key (for print), then the "enter" key (for print to file), at which point I was prompted for a file name. Once I'd entered the desired file name and pressed the "enter" key again, I hit the "q" key to exit lynx. In this way, I produced the log file I could then use for a future automated session at that same site. Subsequent testing using the command<br />
<tt><br /></tt>
<tt>lynx -cmd_script=mysite.txt http://www.mysite.com</tt><br />
<br />
confirmed that I had, in fact, a working log file that could be used for retreiving the desired content from the target page.<br />
<br />
The additional steps for my scenario were to turn this into a <tt>cron</tt> job (no <tt>systemd</tt> silliness here!), use <tt>sed</tt> to strip out extraneous content from the beginning and end of the page I'd printed/retrieved, and to get the resulting material into the body of an e-mail that I would have sent to myself at given intervals. The <tt>sed</tt>/<tt>mail</tt> part of this goes something like<br />
<tt><br /></tt>
<tt>sed -n 24,32p filename | mail -s prepaid-status me@mymail.com</tt>*<br />
<br />
* <span style="font-size: x-small;">I can't go into particulars of the <tt>mail</tt> program here, but suffice to say at least that you need a properly edited configuration file for your mail sending utility (I use <tt>msmtp</tt>) for this to work.</span>wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-17409458488142337962015-04-17T08:47:00.001-07:002015-04-20T16:13:26.064-07:00Addendum to 12th installment: watermarks with copyright notice using LaTeXSo, it's been awhile. And there's been plenty I could have blogged about on the tech front. Like when I copied my Arch install to another hard drive, making it bootable. But I didn't. And now I've forgotten important details of how I did it. Oh well.<br />
<br />
I can blog about this next item, though, which is still fresh in memory.
I've got to write up some articles and am sending them out for proofreading. So I wanted to mark them as drafts, something I already know how to do and have blogged about <a href="http://audaciousamateur.blogspot.com/2013/10/12th-installment-adding-watermarks-to.html">previously</a>.<br />
<br />
I decided to modify things a bit for the current task, though. This time I'm using only one utility to do the watermarking--LaTeX--and I'm tweaking things a bit further.<br />
<br />
The challenge this time is making a watermark with a line break, as well as one that contains text with differing font sizes in the two lines. I want a really large font for the first line, which marks the document as a draft--as in my previous installment--but I want a really small font for the second line this time. That second line is where a copyright notice will be located.<br />
<br />
Without further ado, here's the MWE (TeX-speak for minimum working example) I've come up with for accomplishing this:<br />
<br />
<textarea cols="65" name="comments" readonly="readonly" rows="9" wrap="off">\documentclass{article}
\usepackage{fullpage}
\usepackage[margin=1.0in]{geometry}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{type1cm}
\usepackage{eso-pic}
\usepackage{color}
\makeatletter
\newcommand{\the\year}
\makeatother
\SetWatermarkText{\rotatebox{15}{\parbox{16cm}{%
DRAFT \\
\small{\textbf{Unless otherwise attributed, content of this document \textcopyright Yours Truly, \the\year}}}} }}
\SetWatermarkScale{1.4}
\SetWatermarkColor[gray]{0.90}%
\title{Lorem ipsum}
\begin{document}
\maketitle
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}
}</textarea>
<br />
<br />
This will place, diagonally across each page of the document, a notice in light gray font and in very large letters, with the word DRAFT. Underneath that, there will be text in much smaller font alerting that the material is under copyright claim of the document's author. It's also got a nice little feature that auto-inserts the year, so it's something that can be reused in varying documents over a period of time, relieving the composer of having to fiddle with minor details like dates.<br />
<br />
So, that's about it for this installment!<br />
<br />
LATE ADDITION: Just today I ran across a new means of watermarking that can be done on already-existing <tt>.pdf</tt> files. It involves using the program <a href="https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/"><tt>pdftk</tt></a> and is quite simple. You simply create an empty--except for your desired watermark--<tt>.pdf</tt>, then use the program to add the watermark to the already-existing <tt>.pdf</tt>. Something like the following:<br />
<br />
<tt>pdftk in.pdf background back.pdf output out.pdf</tt><br />
<br />
(I ran across that <a href="http://bioeng-student.blogspot.com/2009/02/adding-pdf-headers-footers-and.html">here</a>). I used LibreOffice Draw to create such a background watermark and easily added that to an existing <tt>.pdf</tt>. It worked great, though it should be noted that the watermark won't cover graphics; I assume there must be a way to make it do so, however.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-77952349342857951932014-11-18T13:39:00.002-08:002016-01-31T17:01:28.324-08:00Miscellaneous Tuesday quickies: creating and using ssh tunnels/proxiesThis entry will concern tunneling so as to get around port-blocking restrictions. It's something I learned about some years ago, but had a difficult time wrapping my head around it. While I can't say I understand it a whole lot better now, I can at least say that I've been able to get it working.<br />
<br />
In my case it was needed because I've been working in a library whose wifi network is set up to block a variety of non-standard ports. That's a problem for me since I run my (command-line) e-mail client on a home computer, and I connect to that computer via <tt>ssh</tt>--which, in turn, runs on a non-standard port. So, when I work in this library, I am unable to connect to my home machine to do e-mailing. There are also occasional problems with sites being blocked on this network (and, no, I'm not rying to view porn).<br />
<br />
For this to work, one must have access to some machine outside the wifi network that runs <tt>ssh</tt> on port 443. I happen to have a shell account with a service that has just such a set-up.<br />
<br />
In my case, then, I can set up the tunnel as follows:<br />
<tt><br /></tt>
<tt>ssh -L localhost:1234:my.dyndns.url:12345 -p 443 my-user@my.shellacct.net</tt>.<br />
<br />
I am asked for my password, then logged into my shell account, and the tunnel is thus opened.<br />
<br />
Then, to connect to ssh as running on my home machine, I simply issue<br />
<tt><br /></tt>
<tt>ssh -p 1234</tt><br />
<br />
To get around the occasional page blocking I've run into, I first downloaded a browser I will dedicate to this task--namely, qupzilla. Then, I need to set up a <tt>socks</tt> proxy, which is done via <tt>ssh</tt>, like so:<br />
<br />
<tt>ssh -D 8080 my-user@my.shellacct.net -p 443</tt><br />
<br />
After that, it's a matter of configuring qupzilla (or your preferred browser) to route web traffic over the socks proxy you've just created. That's done by going to Edit > Preferences > Proxy Configuration, ticking the Manual configuration radio button, selecting <tt>socks5</tt> from the drop-down menu, then entering localhost into the first field next to that and 8080 in the Port field. Click Apply and Ok, and qupzilla will be set to route its traffic over your proxy, thus avoiding the blocks instituted by the wifi network.<br />
<br />
With this basic information, it should be clear how other sorts of <tt>ssh</tt> tunnels and/or proxies could be set up.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-15560158004357690742014-07-18T11:54:00.001-07:002014-07-18T13:17:47.599-07:00Miscellaneous Friday quickies: The Plop boot manager; what is it and why would you need it?Prefatory remark: I am uncertain of the licensing status of the project discussed in the posting below, but I suspect it may not<span style="font-family: sans-serif;">--unlike most of the other utilities I discuss in this blog--</span>be open-source.<br />
<br />
Unless you, like me, are stubbornly trying to repurpose aging hardware, this tool might not be of much interest to you. But it allowed me to get an older machine booting from USB when BIOS limitations were interfering, , so I decided to document here the fairly simple procedures I followed to accomplish this in case they might be of benefit to others.<br />
<br />
How old was said machine? Well, old enough to not only have problems booting from USB flash drives (BIOS USB boot options were limited to USB floppies or ZIP disks), but to have a floppy drive in it as well! A single core machine, as you might guess, although the motherboard did at least have SATA headers--which made it a good candidate for the project I had in mind.<br />
<br />
I learned, through some on-line research, about the <a href="http://www.plop.at/en/bootmanager/download.html">Plop boot manager</a>--touted for enabling systems to boot from USB even where BIOS settings limited it--and that floppy disk images of the boot manager are included in the download. So I dug up and dusted off a floppy, downloaded the image, and wrote it to the floppy the GNU/Linux way--using <tt>dd</tt>:<br />
<tt><br /></tt>
<tt>dd if=/path/to/plpbt.img of=/dev/fd0</tt><br />
<br />
And that disk did, in fact, allow me to boot sanely from a USB thumb drive I'd plugged into the system. On boot, a starfield simulation reminiscent of the old Star Trek intro (ok, I'm dating myself here) appeared on the screen, in the foreground of which was a boot menu from which I could select the medium I wished to boot. And, sure enough, USB was one of the items.<br />
<br />
That wasn't quite all I needed for my own application, however; you see, my hope was to have this machine run headless. So, how to make the boot manager default to booting from the USB drive after a certain number of seconds?<br />
<br />
For that, it turns out, I needed another program included in the download called <tt>plpbtcfg</tt>. That program is what allows one to modify the binary file <tt>plpbt.bin</tt>. And <tt>plpbt.bin</tt> needs to be accessed somehow as well in order to modify it--accomplished in my case by mounting <tt>plpbt.img</tt> as a looped file system.<br />
<br />
So I ran <tt>mount -o loop /path/to/plpbt.img /mnt/loop</tt>. Once that image had been thus mounted, I <tt>cd</tt>'d to where I'd downloaded <tt>plpbtcfg</tt> and ran <tt>plpcfgbt cnt=on cntval=4 dbt=usb /mnt/loop/plpbt.bin</tt>: that gave the boot menu a four-second time count, after which the computer would automatically boot from USB. I rewrote, using <tt>dd</tt> again, that image, to the floppy. So, mission accomplished.<br />
<br />
Except some other aspects of that machine's operation proved not very suitable to the application I was hoping to deploy it for, so I'm not sure it will finally be put into service. But that's another story . . .wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-36264243863811755302014-04-12T04:12:00.002-07:002016-03-28T09:05:28.788-07:00Miscellaneous Friday quickies: crop pdf margins with psnupAs sometimes happens, I recently needed to print off a portion of a public-domain work that's been scanned to portable document format and made available for download via Google Books. As the case proves to be at times, the original book had pages with fairly wide margins; when that sort of scanned book gets printed on letter-sized paper, you end up with a smallish text-box in the middle of a page that will have something like two-inch margins. That makes the text harder to read because the font ends up being relatively small, and it also results in waste of a lot of paper.<br />
<br />
What to do, then, to make the text larger and make it occupy more of the page? I used three utilities for this job: <tt><a href="http://www.foolabs.com/xpdf/">xpdf</a></tt> to excise the target pages into a <a href="http://en.wikipedia.org/wiki/PostScript">postscript</a> file, <tt>psnup</tt> to enlarge the text and crop margins, and <tt>ps2pdf</tt> to convert the modified pages back to a <tt>pdf</tt> file. <tt>psnup</tt> is part of the <a href="http://knackered.org/angus/psutils/"><tt>psutils</tt></a> package, while <tt>ps2pdf</tt> relies on <a href="http://pages.cs.wisc.edu/~ghost/doc/AFPL/6.50/Readme.htm">Ghostscript</a>. A description of the steps I took follows.<br />
<br />
With the pdf-viewer <tt>xpdf</tt>, the print dialog offer two option: print the document to a physical printer, or print to a postscript file. Both options allow for page-range stipulation. That's how I created a postscript file from the target pages.<br />
<br />
Next, <tt>psnup</tt>--a really handy tool I've used previously for creating booklets (more about that in a future entry), but which I'd never considered might perform a job like this--was used to reduce margins, which had the added effect of increasing the text size. The command I used, which I appropriated from <a href="http://www.uofr.net/~greg/ps_nomargin.html">here</a>, looks like this:<br />
<br />
<tt>psnup -1 -b-200 infile.ps file_zoomed.ps</tt><br />
<br />
The crucial switch here seems to be <tt>-b</tt> (which is short for borders) followed by a negative numeral. Of course the numeral 200 as seen in this example will need to be modified to suit your circumstances.<br />
<br />
The final step of converting <tt>file_zoomed.ps</tt>, using <tt>ps2pdf</tt>, to a <tt>pdf</tt> was simplest of all--in fact so simple that I won't even describe it here. I hope this brief description may be an aid to others wishing to execute a task like this.<br />
<br />
Finally, I ran across some other related information of interest while reaserching how to crop pdf margins. Here, for example, is a page that describes a few other, more technically-involved ways to reduce margins: <a href="http://ma.juii.net/blog/scale-page-content-of-pdf-files">http://ma.juii.net/blog/scale-page-content-of-pdf-files</a>. This posting on the Ubuntu forums has a really interesting script someone put together for making pdf booklets: <a href="http://ubuntuforums.org/showthread.php?t=1148764">http://ubuntuforums.org/showthread.php?t=1148764</a>. And this one offers some clever tips on using another <tt>psutils</tt> utility--<tt>psbook</tt>--for making booklets: <a href="http://www.peppertop.com/blog/?p=35">http://www.peppertop.com/blog/?p=35</a>. Then, there's what might be the most straightforward utility of all for cropping pdf margins--<tt><a href="http://pdfcrop.sourceforge.net/">pdfcrop</a></tt>. Since I could not get it to work for me in this instance, I looked for and found the alternative described above.<br />
<br />
MUCH LATER EDIT: having done some further experimentation with <tt>pdfcrop</tt> I've discovered an important element: using negative values to specify width of margins. Doing this, I was able, using this tool, to trim margins to my staisfaction. A command such as <tt>pdfcrop --margins '-5 -25 -5 -40' MyDoc.pdf MyDoc-cropped.pdf</tt> ended up doing the trick for me quite nicelywayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-72444518562051428902014-03-17T08:25:00.000-07:002014-03-17T11:40:28.945-07:00Miscellaneous Monday quickies: volume adjustment via keyboardBeing an enthusiast of minimalist GUI systems, I'd heard some time ago of the <a href="http://i3wm.org/"><tt>i3</tt> window manager</a> and liked what I'd read. Recently, I switched over a couple of my computers to it and have been quite happy with it.<br />
<br />
I ran across a <a href="https://www.linux.com/learn/tutorials/766143-how-to-use-the-superfast-i3-tiling-window-manager-on-linux">news item</a> the other day that was touting the virtues of <tt>i3</tt> and which therefore caught my interest. Especially intriguing was the author's description of how, using that WM, certain keyboard keys or key combinations could be mapped so as to govern the computer's sound ouput--intriguing, that is, even apart from the fact that it was a description of a system configured to use <a href="http://en.wikipedia.org/wiki/PulseAudio">pulse audio</a> for sound output (my preference for <a href="http://en.wikipedia.org/wiki/Advanced_Linux_Sound_Architecture">ALSA</a> over pulse is material for another entry). Still, I felt it should not be too hard to modify those directions to suit my systems.<br />
<br />
As in the article referenced, it was a simple matter of modifying <tt>~/.i3/config</tt>, adding some lines. In my case, the lines were as follows:<br />
<br />
<textarea cols="50" name="comments" readonly="readonly" rows="4" style="height: 78px; margin: 2px; width: 473px;">bindcode 171 exec amixer -q set Master 2dB- unmute
bindcode 173 exec amixer -q set Master 2dB+ unmute
bindcode 121 exec amixer -q set Master toggle</textarea><br />
<br />
The keyboard on that particular machine is what I believe is called a "multimedia keyboard," meaning that it has a few keys dedicated, rather than to alphanumeric characters, to multimedia functions such as volume control. Finding which key codes to place in that file was a simple matter of using the <a href="http://www.freebsd.org/cgi/man.cgi?query=xev&apropos=0&sektion=1&manpath=FreeBSD+Ports&arch=default&format=html"><tt>xev</tt></a> utility. The ALSA--as opposed to pulse audio-- commands for raising, lowering, and muting volume were readily found in an internet search.<br />
<br />
After a few trial runs and further tweaks, a quick restart of <tt>i3</tt> revealed that things were working as expected. Flush with success from that project, I decided I might get the same thing working on another computer in my apartment--though that computer, since it needs to be usable for my wife, runs a different WM; incidentally, it runs <a href="http://joewing.net/projects/jwm/">JWM</a> with a home-brewed Gnome 2 mock-up interface (I plan to do a write-up someday describing the Gnome 2 mock-up I created).<br />
<br />
The basic idea of getting keyboard keys controlling volume is the same, though it involves editing a different configuration file--named <tt>~/.jwmrc</tt>--that uses alternate syntax. Since the keyboard attched to this machine is not a multimedia keybaord, I ended up repurposing some seldom-used keys, in combination with the <tt>Alt</tt> key, for volume control functions. The entries in that file are as follows:<br />
<br />
<textarea cols="50" name="comments" readonly="readonly" rows="3" style="height: 78px; margin: 2px; width: 473px;"><key mask="A" key="Delete">exec:amixer set Master 3%-</Key>
<key mask="A" key="End">exec:amixer set Master 3%+</Key>
<key mask="A" key="Next">exec:amixer set Master toggle amixer</Key></textarea><br />
<br />
That pretty much sums it up this quickie entry.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-87079031482472412662014-03-08T16:23:00.001-08:002014-03-17T07:46:09.408-07:00Miscellaneous Saturday quickies: udev rules and you<blockquote class="tr_bq">
PREFACE: "<tt><a href="http://en.wikipedia.org/wiki/Udev">udev</a></tt> is a device manager for the Linux kernel. Primarily, it manages device nodes in <tt>/dev</tt>. It is the successor of <tt>devfs</tt> and <tt>hotplug</tt>, which means that it handles the <tt>/dev</tt> directory and all user space actions when adding/removing devices, including firmware loading." (Wikipedia entry for <tt>udev</tt>) Those wanting a better orientation to <tt>udev</tt> may wish to do some further reading of material found at some of the links provided in this entry.</blockquote>
I felt a great sense of triumph when, oh, 5 or 6 years ago, I managed to create a <tt>udev</tt> rule that would make a scanner I was trying to use be identified in a certain way to the system. In the wake of that project I was also able to craft some <tt>udev</tt> rules for some external hard drives I was using. Since then, I've learned, however, that computer tech is a quickly moving target; the things I took such great pains to learn and apply back then, as I now know, might be of little use to me in just a few short years.<br />
<br />
Case in point: fast forward to yesterday, when, after a <a href="http://www.mythtv.org/">Mythtv</a>/<a href="http://www.mythbuntu.org/">Mythbuntu</a> upgrade, one of the capture cards I'd written a <tt>udev</tt> rule for was no longer being properly identified to the system. The reason being, of course, that some changes had been made to <tt>udev</tt> conventions and the old trick I'd used to identify that card to the system was no longer working.<br />
<br />
So I had to rewrite the rule. It turns out some parts of the routine for identifying and naming devices have been a bit simplified. The new incantation I needed to run to find out details about the catpure card which I could incorporate into the udev rule goes like this:<br />
<br />
<textarea cols="50" name="comments" readonly="readonly" rows="1">udevadm info -a -p  $(udevadm info -q path -n /dev/sdb)</textarea><br />
<br />
(where <tt>sdb</tt> is replaced by the device name of the hardware you're querying--in my case, <tt>video0</tt>)<br />
<br />
That bit was lifted from a 2009 entry from a blog located <a href="http://raftaman.net/?p=343">here</a>. He references an even older web page as a source for his information, one I'd used in my first attempts 5 or 6 years ago, and which looks to be pretty outdated now. That page is called "recativated" and can be found <a href="http://www.reactivated.net/writing_udev_rules.html">here</a>.<br />
<br />
In any case, an even simpler rendition of the incanation above is offered in the "comments" section of that blog, as follows:<br />
<br />
<textarea cols="50" name="comments" readonly="readonly" rows="1">udevadm info -a -n /dev/sdb</textarea><br />
<br />
Both gave the results I needed and helped me resolve the issue of the card being identified and labelled as I wanted it to be. Maybe this information will be useful to you as well--at least so long as you find and try to apply it before the next big change comes to <tt>udev</tt>, or <tt>udev</tt> gets superseeded by some other, "better" utility.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-64679030223675859612013-11-27T16:38:00.000-08:002013-11-29T15:34:06.687-08:0014th installment: home-brewed WOD by e-mail dailyI used to subscribe to an on-line dictionary's word-of-the-day (WOD) program. That entailed signing up, using a valid e-mail address, on their web site so that they would, each day, send a different WOD along with its definition to that address. The service proved to be a bit flaky, however, and the e-mails would sometimes get caught up in my spam filter. So, somewhere along the line--perhaps owing to an e-mail address change--I stopped receiving those educational e-mails.<br />
<br />
I'd had in the back of my mind going back to using that service but hadn't signed up again--all the while having a nagging suspicion that it must be possible, using open source tools, to cobble together some way of doing this sort of thing from my own computer, thereby obviating the need to sign up for some service. But could I, with my modest technical acumen, actually pull this off? Read on to find out the result.<br />
<br />
Meantime, as I've continued learning my way around GNU/Linux and computing in general, I made some headway in learning how to use the program <tt><a href="http://www.roaringpenguin.com/products/remind">remind</a></tt> to help me keep track of scheduled appointments and to-do items, even progressing so far as puzzling out how to get my computer to e-mail me my schedule on a regular basis. Perhaps I'll write more about that accomplishment--of which I'm quite proud--in a future entry.<br />
<br />
The relevance of that observation to the present post is that I learned how to use the program <tt><a href="http://linux.die.net/man/1/mail">mail</a></tt>, along with the small <tt><a href="http://msmtp.sourceforge.net/">msmtp</a></tt>, for sending--when triggered by <tt>cron</tt>--to myself automated reminder e-mails from my system. So some major ingredients were actually already in place that would allow me finally to implement my own, home-brewed WOD-by-e-mail solution.<br />
<br />
This was perhaps the final piece of the puzzle for me, although another crucial piece had been under my nose recently as well, something I ran across while investigating <tt>bash</tt> functions (I wrote about that a few installments earlier, as you can see <a href="http://audaciousamateur.blogspot.com/2013/01/11th-installment-lynx-your-own-personal.html">here</a>). By adapting one of the <tt>bash</tt> functions I'd found, I was first able to see the WOD from the command line by simply issuing <tt>wod</tt> from a command prompt. But I soon began forgetting to do that, which spurred me to consider once again having the WOD somehow e-mailed to me.<br />
<br />
Finally, putting two and two together, I realized I could adapt the thrust of that function to my needs by having its output placed into the body of an e-mail that would be automatically sent to me each day at 6 A.M. Following is a description of how I did that.<br />
<br />
A key ingredient I have not yet mentioned is the text-mode browser <tt>lynx</tt>, which produces an <tt>html</tt> file that gets parsed for material that will be inserted into the e-mail body: and I didn't mention it because <tt>lynx</tt> and me go back a long, long ways--clear back to the close of the twentieth century, to be precise. The line, swiped straight from the <tt>bash</tt> function I found on the web, is as follows: <tt>lynx -dump http://www.wordthink.com/</tt>. That simply "dumps the formatted output of the default document or those specified on the command line to standard output," as the <tt>man</tt> page tells us--obviously not enough to get a WOD into an e-mail body, but fairly close.<br />
<br />
What's needed, then, is, like the <tt>bash</tt> function, to pipe that output through <tt>grep</tt>, searching for a certain pattern, then to extract from it the relevant lines which belong in the body of the e-mail. Those results then get piped to <tt>mail</tt>, which inserts the lines into the body of an e-mail. Below is the full line that I inserted into my crontab file, minus the bit that tells the line to be executed at 6 A.M. daily:<br />
<br />
<tt>lynx -dump -nonumbers "http://www.wordthink.com/" | grep -A 10 -m 1 "Today's Word of the Day" | mail -s WOD my-addy@my-mail.com</tt><br />
<br />
This <tt>cron</tt> entry tells <tt>lynx</tt> to dump the page found at the specified link to standard output (whatever that means), then to pipe that through <tt>grep</tt>, searching for the phrase "Today's Word of the Day." Once that phrase is found, <tt>grep</tt> is to stop searching (the <tt>-m 1</tt> switch--it's to look for only one instance) and to "print" the ten lines preceding (the <tt>-A 10</tt> switch), which actually then get piped to <tt>mail</tt> and become the body of the message. The <tt>-s</tt> switch specifies what the subject line of the e-mail should be. The <tt>-nonumbers</tt> switch just tells <tt>lynx</tt> not to preface the links it finds in the page with numerals between square brackets, which it would otherwise do.<br />
<br />
That's about it for this entry. I really do need to write up a <tt>remind</tt> entry, since I had hoped long and hard to find some scheduling utility that would be no-frills, yet powerful enough to issue me reminders on a regular basis. So that may be next on the agenda for this blog.<br />
<br />
<i>Some afterthoughts</i>: piping the output of <tt>lynx -dump</tt> through <tt>grep</tt> to extract target text is not ideal, since--if I've read its man page correctly--you are limited to extracting text by line. A problem arises here because the number of lines for the target entries for the WOD can vary day-by-day. As a result, it is likely that either extraneous line(s) will be included on many days, or that some target line(s) will get cut off on other days. Perhaps piping the <tt>lynx -dump</tt> output through <tt>sed</tt> or <tt>awk</tt>--which, as I understand it are both far more flexible when it comes to identifying target text--might be a better solution. But because I am not well-versed in either of those utilities and because extracting the WOD from web sites whose layout may change at any time is a moving target, I am presently not attempting to improve on the method I've described here. I do, on the other hand, welcome suggestions for improving this WOD-by-e-mail solution from any reader who may know those--<tt>grep</tt> included--or other utilities better than I.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-55893646086219514642013-11-14T15:28:00.000-08:002013-11-21T13:38:12.526-08:0013th installment: how slow is too slow for a motion detection security cam system?In this post, I'll answer a question to which I hoped I'd find an answer on the internet--but I did not manage to find that answer. The question is about minimal specs for a motion-capture machine and, though my answer will have to remain somewhat imprecise owing to the fact that I did not test multiple systems, it will at least give a probable base-line for what may be the lowest-powered system one could use for the task I'm describing.<br />
<br />
So, without further ado, on to a description of the task. Or, more specifically, I'll start off describing what precipitated the task.<br />
<br />
For some months now, things located in public areas of the apartment building where I live--for example in the corridors or the garage--have been disappearing. I assumed it was only affecting others until I noticed that a cheap DVD player I'd put in the exercise facility here had disappeared. Then, I noticed that certain bicycle parts and tools had vanished from my garage space.<br />
<br />
I decided I could take at least some action toward stemming the theft and perhaps catching the perpetrator, by setting up a security camera. I knew that GNU/Linux had utilities for recording from motion detection cameras, and some preliminary searching revealed that the <a href="http://www.lavrsen.dk/foswiki/bin/view/Motion">motion</a> program was likely to suit my needs.<br />
<br />
It so happened that a friend had recently passed along to me a decent webcam, so all I needed to do was find a target machine on which to set up the software. An old laptop would have been ideal because of the small size, but I didn't have one available.<br />
<br />
What I did have was an old all-in-one unit, an early LCD monitor with a built-in computer--in the person of a laptop motherboard--in its base. I even had Debian (Squeeze) already installed on that machine, since I'd set it up for my father-in-law to use when he visits. But I'd taken the machine out of service a couple of years ago, judging that, as a single-core machine with a 433 MHz Celeron and 192 megabytes of RAM, it was getting a little long in the tooth to be useful anymore. So, could this ancient machine actually be used for a motion detection security camera?<br />
<br />
I won't in this post go into the particulars of setting up <tt>motion</tt>, which did not prove particularly challenging. But after stripping down the operating system to the basics, installing motion, and editing its configuration file for my set-up, I was able to get it to run and record on this machine.<br />
<br />
Though the web-cam is capable of 720p recording, I had to settle for 640x480, since the older USB 1.1 ports on this machine could not handle anything approaching the bandwidth high-definition video demands. And the hard disk on this machine, at a measly 6 gigabytes, was not a good candidate for recording HD video anyway.<br />
<br />
Once I'd disabled, per the <tt>motion</tt> <a href="http://www.lavrsen.dk/foswiki/bin/view/Motion/FrequentlyAskedQuestions#Increasing_available_USB_bandwidth">documentation</a>, <tt>alsa</tt>'s <tt>snd-usb-audio</tt> module, I was off to the races with this rig. I did manage to find an 40 gigabyte hard drive for sale for $3 which, when added, upped my recording capability from about 2 months to a little over one year.<br />
<br />
So, in case you're wondering, as of this date (late 2013), you can actually run a single* motion-sensing camera, if you're satisfied with VGA video quality and a low frame rate (I've set it to 2 per second), on a single-core 433 Celeron with as little as 192 megabytes of RAM. It will even happily run <tt>ffmpeg</tt> and stitch together the stills it captures into a video for you.<br />
<br />
* I didn't try but am virtually certain such a machine could not handle two cameras.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com1tag:blogger.com,1999:blog-1541371521224765784.post-36367844185332643042013-10-30T11:32:00.002-07:002013-11-21T13:38:57.331-08:0012th installment: adding watermarks to documentsIn this twelfth installment, I'll describe my recent success with adding watermarks to a document. As often happens when I want to do a quick document or need to work on a <tt>.doc</tt> file, I turned to <a href="http://www.libreoffice.org/">LibreOffice</a> for this task. The major part of this post, then, will be occupied with how to add watermarks to documents created in or edited with LibreOffice/OpenOffice. I decided, just out of curiosity, to look into how watermarks can be added to <tt>TeX/LaTeX</tt> documents as well, so I'll share as well a bit of information that I gleaned about that from another site.<br />
<br />
First, though, a bit about watermarks. As the <a href="http://en.wikipedia.org/wiki/Watermark">wikipedia</a> article on the topic tells us "[a] watermark is a recognizable image or pattern in paper that appears as various shades of lightness/darkness when viewed by transmitted light (or when viewed by reflected light, atop a dark background), caused by thickness or density variations in the paper."<br />
<br />
Watermarks proper are actually added into the paper itself during manufacture, and the text was later printed over the watermark. With the advent of modern computer printing, however, it has become possible to print "watermarks"--actually it might be better to refer to these as pseudo-watermarks--onto standard, clean paper and so to add them, page by page, to a document. This is the sort of watermarking I will be discussing.<br />
<br />
This pseudo-watermarking might be added to a document for a number of reasons: a background image--such as a business logo--might be wanted in a document; a copyright notice might be added to a document in this way; or a document might need to be identified as a draft, as opposed to a final revision. The latter of these scenarios applied to me and was why I wanted to learn how to do pseudo-watermarking.<br />
<br />
I was pretty certain I could readily find instructions for how this is done using LibreOffice, and a quick search proved my supposition correct. That search furthermore proved that it is a fairly trivial task, so long as one feels comfortable with using some image editing or creating software. I used <a href="http://www.gimp.org/">GIMP</a> for creating my image, though I decided as well to experiment with LibreOffice Draw and had success with it as well. The image created is simply selected as a background for the document. The steps I used were as follows.<br />
<br />
First, open GIMP and select File > New. In the resulting dialog, I changed the increments for image size to inches, so as to create an image that will fit within an 8.5x11 inch sheet.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUjluKykrr0oAa0p0Eg2xAT6CrB17hhbwXEqyvDmY5rXBryWdSWmOShdAJ7P8O81EDnIJEMGBeayB0eLhexhUqTVVnlPR0glPdEdGWvrV9d98xKC3uyE3tG1qkPCzmwnqWeCda4r1oLEE/s1600/gimp1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="225" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUjluKykrr0oAa0p0Eg2xAT6CrB17hhbwXEqyvDmY5rXBryWdSWmOShdAJ7P8O81EDnIJEMGBeayB0eLhexhUqTVVnlPR0glPdEdGWvrV9d98xKC3uyE3tG1qkPCzmwnqWeCda4r1oLEE/s320/gimp1.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
Once I'd selected the size I wanted and created the file, I next went to the GIMP toolbar and selected the Text Tool. I printed in the resulting window the text I wanted to appear, selected a light gray color for the font, changed the font increment to point, then increased the font size substantially (as you'll see in the screenshot, I went with 213 point type).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-j-TnFJRMnPYZEldyn4i8uORcsCj1Vg1Eoro10m2khUkvCAvxd4la1BgJZyCJKr8km-ovvuyTtHQrryMTZQaOnZKL3uiO9r9fFQzNd-iFwByJGUg92qNBmX-jYwZ0Dub3f9N3jeG_NSg/s1600/gimp2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="271" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-j-TnFJRMnPYZEldyn4i8uORcsCj1Vg1Eoro10m2khUkvCAvxd4la1BgJZyCJKr8km-ovvuyTtHQrryMTZQaOnZKL3uiO9r9fFQzNd-iFwByJGUg92qNBmX-jYwZ0Dub3f9N3jeG_NSg/s320/gimp2.png" width="320" /></a></div>
The somewhat tricky part after having done that was to rotate the text such that it would run across the page at an angle. This I accomplished by selecting Layer > Transform > Arbitrary Rotation. Doing this raises a window with a slider that allows you to rotate the image to the desired angle--in my case -57.66 degrees. As will be evident in the screenshot, the text can be better centered in the image using this dialog as well (x and y axes).<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg76ZhdJpPrjvsOAIkIG9sh6GS6w6hPEbq_J78lyFhsiwz2FXKd2AZkEPekxIp9qYq3xMFVTlVwuDbgJCTtM0Q-xhDwAsmMfwuSm2KetGcG4RmLZqDcakHnpy7dphIh-idOuYCtscgwPRU/s1600/gimp3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="267" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg76ZhdJpPrjvsOAIkIG9sh6GS6w6hPEbq_J78lyFhsiwz2FXKd2AZkEPekxIp9qYq3xMFVTlVwuDbgJCTtM0Q-xhDwAsmMfwuSm2KetGcG4RmLZqDcakHnpy7dphIh-idOuYCtscgwPRU/s320/gimp3.png" width="320" /></a></div>
<br />
Thus, the final product (not very well centered here):<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb7-HqQMQqsmGf9UQp5pnmVwWMuG-FQMoV63uCLc5b8_aTxbKIGAB5IHQRvziQPhrHSeBTnlpkMeqHqwW038VHTp1XSyb6ALcdyVf6rkfAxBcAoWDuVMqQYEXghLCSWB4cE23_oHdxJzs/s1600/gimp4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb7-HqQMQqsmGf9UQp5pnmVwWMuG-FQMoV63uCLc5b8_aTxbKIGAB5IHQRvziQPhrHSeBTnlpkMeqHqwW038VHTp1XSyb6ALcdyVf6rkfAxBcAoWDuVMqQYEXghLCSWB4cE23_oHdxJzs/s320/gimp4.png" width="258" /></a></div>
I exported that image to a <tt>.png</tt> file as the final step. From here, it's a simple matter of opening your LibreOffice document and clicking on Format > Page, selecting the "Background" tab, selecting "Graphic" from the "As" drop-down menu, and finding and selecting the file you just created using GIMP. Once that's done, all pages in that file will have a pseudo-watermark with the text "Draft" on them.<br />
<br />
The initial <a href="http://www.youtube.com/watch?v=VXdxK9JCW6Q">video</a> I found described making the watermark using LibreOffice's Draw program, so I decided I should have a try with it as well. That process was almost as simple as GIMP's, but it had the limitation that the largest font size I could select was 96 point--a bit on the small side. I will nonetheless outline the steps here.<br />
<br />
First, I opened up Draw and selected the "T" (for text insertion) from the toolbar at the bottom of the page.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqIKLdXvVVhS-b9OpCB_FX4kBH_REmyhNB09PgRQq7U-zNDYKSC9qjBqHLMqtGzz4AXHCC2zWbbY_ZHpw0o3cRGm1D7K8qdEADey4959L__vCeCI2MlIUv26-PMOMKZhyphenhyphenlIpyDWThlJ2A/s1600/draw1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="66" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqIKLdXvVVhS-b9OpCB_FX4kBH_REmyhNB09PgRQq7U-zNDYKSC9qjBqHLMqtGzz4AXHCC2zWbbY_ZHpw0o3cRGm1D7K8qdEADey4959L__vCeCI2MlIUv26-PMOMKZhyphenhyphenlIpyDWThlJ2A/s320/draw1.png" width="320" /></a></div>
Next, I selected a light gray font color and the largest possible font size from the menu, and printed the text "Draft" in the page. The text ends up being in a horizontal orientation, of course, as can be seen in the screenshot.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPItNuHrmAi1nFse5RxGcLkf_nvFs06-fGaB11e9mNq0RAmEVnpTpza3XzFh1RNzrE6MPVxb2Satxkhy2qgxaOO5Fwz_GDrzXAZn470nLN3LfiiLVjWMIKcRCuTahKuyH1tWhtonsa-wg/s1600/draw2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPItNuHrmAi1nFse5RxGcLkf_nvFs06-fGaB11e9mNq0RAmEVnpTpza3XzFh1RNzrE6MPVxb2Satxkhy2qgxaOO5Fwz_GDrzXAZn470nLN3LfiiLVjWMIKcRCuTahKuyH1tWhtonsa-wg/s320/draw2.png" width="285" /></a></div>
In order to make the text run at an angle across the page, it is next necessary to choose the "Effects" tool from the bottom toolbar (the symbol has two blue boxes off kilter from one another and is situated fourth from the right side on my toolbar). Once that's done the highlights of the text box just created turn red, and if the cursor is moved over the top right corner of that text box, the box can be dragged such that it is oriented on the page at the desired angle.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjo6BqFrkcus79A69jREXlyCUV1A1zEhyphenhyphenvyT5NKY_H2a9cTznXn06rvm3c8chOcr60FgmT_2cOdEAVEdfZce023TDE2igj49GSsSpdFn7t5wTWFjFJPbogcziEWOFuie21LEyM57d2BIQ/s1600/draw4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjo6BqFrkcus79A69jREXlyCUV1A1zEhyphenhyphenvyT5NKY_H2a9cTznXn06rvm3c8chOcr60FgmT_2cOdEAVEdfZce023TDE2igj49GSsSpdFn7t5wTWFjFJPbogcziEWOFuie21LEyM57d2BIQ/s320/draw4.png" width="259" /></a></div>
Once the text box is satisfactorily oriented and centered, the file can be exported. Once again, I chose the <tt>.png</tt> format. The resulting image can then be added to the background of a document using the same process followed above to add the GIMP image.<br />
<br />
Finally, though I did not try out this last method, I wanted to see how difficult or easy it might be, using <tt>TeX/LaTex</tt>, to add a pseudo-watermark to a document. I easily found some directions <a href="http://filoxus.blogspot.com/2008/01/how-to-insert-watermark-in-latex.html">here</a>. That author describes three different methods, the simplest of which--since it is one on which <tt>pdflatex</tt> can be run directly, is quite easy with use of the <tt>graphicx</tt>, <tt>eso-pic</tt>, and <tt>type1cm</tt> packages, as demonstrated in the code below:<br />
<textarea cols="67" name="comments" readonly="readonly" rows="9" wrap="off">search()
\documentclass{article}
\usepackage{graphicx}
\usepackage{type1cm}
\usepackage{eso-pic}
\usepackage{color}
\makeatletter
\AddToShipoutPicture{%
\setlength{\@tempdimb}{.5\paperwidth}%
\setlength{\@tempdimc}{.5\paperheight}%
\setlength{\unitlength}{1pt}%
\put(\strip@pt\@tempdimb,\strip@pt\@tempdimc){%
\makebox(0,0){\rotatebox{45}{\textcolor[gray]{0.75}%
{\fontsize{6cm}{6cm}\selectfont{DRAFT}}}}%
}%
}
\makeatother
\title{Lorem ipsum}
\begin{document}
\maketitle
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{document}
}</textarea>
<br />
<br />
Here's how the resulting page looks:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBncWAW-O9U0eo4ArJsnpvB_m6ZXY33HLTYmRurlwiTPSl7wZGrHgi-xwkNAi4RkhS0qXeaDHuM5L0A_aF-JkdOxvrAXAZvILfF0Ufgc7RlOhb9gOIDkXHhg_vPHkJxI5WjCjnXhc_W_g/s1600/watermark.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBncWAW-O9U0eo4ArJsnpvB_m6ZXY33HLTYmRurlwiTPSl7wZGrHgi-xwkNAi4RkhS0qXeaDHuM5L0A_aF-JkdOxvrAXAZvILfF0Ufgc7RlOhb9gOIDkXHhg_vPHkJxI5WjCjnXhc_W_g/s320/watermark.PNG" width="212" /></a></div>
<br />
<br />
That's it for this installment.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com1tag:blogger.com,1999:blog-1541371521224765784.post-60478935302919753252013-01-23T19:07:00.003-08:002013-01-24T09:01:49.010-08:0011th installment: lynx; your own personal google scraperOk, I'll admit it: there's certainly hyperbole in this entry's title. What I'm doing with the text-mode browser <tt><a href="http://lynx.browser.org/">lynx</a></tt> isn't really <a href="http://en.wikipedia.org/wiki/Web_scraping">scraping</a>--it's just something that bears some conceptual (in my view) similarities. It might appear similar because what I've done is to come up with a way of invoking <tt>lynx</tt> (or any other <a href="http://en.wikipedia.org/wiki/Text-based_web_browser">text-mode browser</a> for that matter), with search terms already entered, from the command line. The end product is just the text results google finds relative to your query--sans all the bells and whistles google's search portal has been foisting on us in recent years. Why is this a significant accomplishment? Well, consider the following.<br />
<br />
<b>Background</b><br />
<br />
Have you found google's search portal to be increasingly cluttered and bothersome? I certainly have. Things like pop-out previews do nothing for me but create distraction, and auto-completion is far more often an irritation to me than a help: as a liberal estimate, perhaps 25% of my searches have benefited from the auto-completion feature. For what it's worth, if google wished to provide better service to users like me, they would create two separate search portals: one would be a fuzzy-feely search portal for those who might be uncertain as to what they're seeking and who could benefit from auto-completion and/or pop-out previews; the other would be google's old, streamlined search page and would involve little more than short text summaries and relevant links.<br />
<br />
Once upon a time there was a google scraper site at <a href="http://en.wikipedia.org/wiki/Scroogle">www.scroogle.org</a>--billing itself more as a search anonymizer than as an interface unclutterer--that provided a results page pretty much like the old google one. I used to use scroogle in the days before google introduced some of the more irritating "enhancements" that now plague their site, and came to appreciate above all its spartan appearance. But, alas, scroogle closed its doors in mid-2012 and so is no longer an option. I've been stuck since, resentfully, using google.<br />
<br />
In a recent fit of frustration, I decided to see whether there might be any other such scrapers around. As I searched, I wondered as well whether one might not be able to set up their own, personal scraper, on their own personal computer: I had certainly heard and read about the possibilities for conducting web searches from the command line, and this seemed a promising avenue for my query. I ended up finding some results that, while providing but a primitive approximation, look like they may nonetheless have given me a workable way to do the sort of pseudo-scraping I need. Thus, the following entry.<br />
<br />
<b>More about the task</b><br />
<br />
Conducting web searches from the command line is another way of describing the task I aimed to accomplish. Granted, doing this sort of thing is nothing especially new. <a href="http://surfraw.alioth.debian.org/"><tt>surfraw</tt></a>, for example, created by the infamous <a href="http://en.wikipedia.org/wiki/Julian_Assange">Julian Assange</a>, has been around for a number of years and more properly fits into the category of web-search-from-the-command-line utilities than does the solution I propose--which just invokes a text-mode browser. There are actually several means of doing something that could be classified as "searching the web from the command line" (<a href="https://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=%22searching+the+web+from+the+command+line%22#hl=en&sugexp=les%3B&gs_rn=1&gs_ri=serp&gs_mss=%22searchi%20the%20web%20from%20the%20command%20line%22&tok=OK5qr9AUF1SfGcOPqS34KA&pq=%22searching%20the%20web%20from%20the%20command%20line%22&cp=7&gs_id=9&xhr=t&q=%22search+the+web+from+the+command+line%22&es_nrs=true&pf=p&tbo=d&sclient=psy-ab&oq=%22search+the+web+from+the+command+line%22&gs_l=&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&bvm=bv.41248874,d.aWM&fp=2f9f27f1931459d4&biw=1278&bih=889&bs=1">google</a> that and you'll see), including the interesting "google shell" project, called "<a href="http://goosh.org/">goosh</a>."<br />
<br />
Still, the solution I've cobbled together using bits found in web searches, and which involves a <a href="http://tldp.org/LDP/abs/html/functions.html"><tt>bash</tt> function</a> that calls the text-mode browser <tt>lynx</tt>, seemed on-target enough and something worth writing an entry about. Details below.<br />
<br />
<b>The meat of the matter: <tt>bash</tt> function</b><br />
<br />
To begin with, some credits. The template I cannibalized for my solution is found <a href="http://superuser.com/questions/47192/google-search-from-linux-terminal">here</a>: I only did some minor modifications to that code so that it would work more to my liking. There's another interesting proposition in that same thread, by the way, that uses <tt>lynx</tt>--though it pipes output through <tt>less</tt>. I tried that one and it got me thinking in the direction of using <tt>lynx</tt> for this. But I liked the way the output looked in <tt>lynx</tt> much more than when piped through <tt>less</tt>, so I decided to try further adapting the <tt>bash</tt> function for my uses and came up with the following.<br />
<br />
The <tt>bash</tt> function outlined at that site actually uses google search and calls a graphical browser to display the output. The graphical browser part was the one I was trying to obviate so that would be the first change to make. I mostly use <tt><a href="http://elinks.or.cz/">elinks</a></tt> these days for text-mode browsing, but having revisited <tt>lynx</tt> while experimenting with the other solution posed there, I decided I would try it out. And I must say that it does have an advantage over <tt>elinks</tt> in that URL's can be more easily copied from within <tt>lynx</tt> (no need to hold down the shift key).<br />
<br />
I could not get the google URL given in that example to work in my initial trials, however. This is likely owing to changes google has made to its addressing scheme in the intervening interval since that post was made. So I first used a different URL from the search engine <a href="https://startpage.com/">startpage</a>.<br />
<br />
After some additional web searching and tweaking, I was finally able to find the correct URL to return google search results. Though that URL is likely to change in the future, I include it in the example below.<br />
<br />
What I have working on this system results from the code below, which I have entered into my <tt>.bashrc</tt> file:<br />
<br />
<textarea cols="67" name="comments" readonly="readonly" rows="9" wrap="off">search()
{
search=""
echo "$1"
for term in $*; do
search="$search%20$term"
done
lynx "http://google.com/search?q=$search" #for startpage results try "https://startpage.com/do/search/?q=$search"
}</textarea><br />
<br />
Once that has been entered, simply issue <tt>. .bashrc</tt> so that your system will re-source your <tt>.bashrc</tt> file, and you're ready for command-line web searching/pseudo-scraping. To begin searching, simply enter the new terminal command you just created, <tt>search</tt>, followed by the word or phrase you wish to search for on google: <tt>search word</tt>, <tt>search my word</tt>, <tt>search "my own word"</tt>, <tt> search my+very+own+word</tt>, or seemingly just about any other search term or phrase you might otherwise enter into google's graphical search portal seem to work fine.<br />
<br />
<tt>lynx</tt> will then open in the current terminal to the google search results page for your query. You can have a quick read of summaries or follow results links. Should any of the entries merit graphical inspection, you can copy and paste the URL into your graphical browser of choice.<br />
<br />
You'll probably want to tell <tt>lynx</tt> (by modifying the relevant option in <tt>lynx.cfg</tt>) either to accept or reject all cookies so as to save yourself some keystrokes. If you do not do so, it will, on receiving a cookie, await your input prior to displaying results. Of course you could use any other text-mode browser--such as <a href="http://w3m.sourceforge.net/">w3m</a>, the old <a href="http://www.jikos.cz/~mikulas/links/">links</a> or xlinks, <a href="http://retawq.sourceforge.net/">retawq</a>, <a href="http://netrik.sourceforge.net/">netrik</a>, or any other text-mode-browser candidates as well.<br />
<br />
Suggestions for improvements to my solution or offerings of alternative approaches will be appreciated. Happy pseudo-scraping/command-line searching!<br />
<br />
AFTERTHOUGHT: I happened upon some other interesting-looking bash functions at <a href="http://www.novell.com/coolsolutions/tools/18639.html">another site</a> that are supposed to allow other types of operations from the command line; e.g., defining words, checking weather, translating words. These are rather dated, though (2007), and I couldn't get them to work. Interpreting their workings and determing where the problem(s) lie is a bit above my pay grade: anyone have ideas for making any of these functions once again operable?wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com0tag:blogger.com,1999:blog-1541371521224765784.post-61011014202518990812013-01-10T04:43:00.002-08:002013-01-23T20:17:43.405-08:0010th installment: resume an scp file transfer<i>NOTE: as a knowledgeable commenter later pointed out "[c]urrently (and since around 2004) the default transfer protocol in rsync *IS* ssh. There is no need for the '-e ssh' unless you directly connect to a remote rsync daemon." I have tested this claim and it is, indeed, true that the file transfer resumption using <tt>rsync</tt> does not require the <tt>-e ssh</tt> bit I stipulated in the instructions below. I did not manage to test whether the same alternate port switch (<tt>-p 1234</tt>) works, though I assume it does.</i><br />
<br />
I recently went on vacation and, since my <a href="http://www.mythtv.org/">mythtv</a> set-up was, for some crazy reason, not allowing me to do a direct download of recorded programming through the <a href="http://code.mythtv.org/trac/wiki/MythWeb">mythweb</a> interface, I needed to find an alternate way of snagging those files. I have an <tt>ssh</tt> server running on my home LAN, so using <tt>scp</tt> for this seemed like it should work, though I knew it would take a bit of tinkering. Read on to see what sort of tinkering I did and, just as importantly, a way I discovered of resuming the disrupted download.<br />
<br />
I first investigated the possibility of setting up an <tt>ssh</tt> tunnel, since the computer on my LAN that contains the video files is not the one running the <tt>ssh</tt> server. But doing that looked a tad beyond my skill level. So I decided I'd just copy those files over to the computer running the <tt>ssh</tt> server manually, then <tt>scp</tt> them to the remote computer from there.<br />
<br />
These were very large files--i.e., > 2 GB--and, given the fairly limited rate at which I could transfer them, I expected there might be some disruption or disconnection during the download. Prior to beginning the dowloads, then, I searched google under "<tt>scp</tt>" and "resume," and I immediately came across results that showed how to use the <tt><a href="http://en.wikipedia.org/wiki/Rsync">rsync</a></tt> utility to resume disrupted downloads. This encouraged me to go ahead and try the <tt>scp</tt> download method.<br />
<br />
As wikipedia informs us, "rsync is a software application and network protocol for Unix-like systems . . . that synchronizes files and directories from one location to another while minimizing data transfer." Though I had, when previously considering differing ways to back up certain directories on my computers, looked at some documentation on <tt>rsync</tt>, I had no prior experience with actually using it. Nonetheless, that's the solution I ended up employing--though I needed to do a slight adaptation for my circumstances. It seemed the slight variation I stumbled upon might warrant an entry on this blog.<br />
<br />
Before describing in greater detail what I did, I should first at least mention a couple of other results I found that used differing utilities. One <a href="http://dodonov.net/blog/2009/06/23/how-to-resume-a-broken-scp-transfer/">candidate</a> used <tt>curl</tt> and <tt>sftp</tt> instead of <tt>rsync</tt>, while the <a href="http://superuser.com/questions/421672/is-there-a-way-to-resume-an-interrupted-scp-of-a-file">other</a> used the <tt>dd</tt> command. Since I did not attempt to implement either of those solutions, I will, after simply making note of the fact that those utilities apparently can be used for this, move on.<br />
<br />
Getting back to <tt>rsync</tt>, the bulk of instructions I found for resuming <tt>scp</tt> transfers using it would not work "out of the box" for me because I run <tt>ssh</tt> on a non-standard port. For purposes of this blog entry, let's say that's port 1234. The question for me, then, was how to adapt the directions I'd found to the scenario involving the non-standard <tt>ssh</tt> port my LAN uses.<br />
<br />
The resolution turned out to be fairly simple. I finally ran across the an incantation very close to what I needed <a href="http://cyberang3l.wikispaces.com/SCP+Resume">here</a>. A simplified sample entry follows (a slightly more complex rendition can be seen in the description for setting up an alias below):<br />
<br />
<tt>rsync -P -e 'ssh -p 1234' user@remote.host.IP:path-to/remotefile.mpg localfile.mpg</tt>
<br />
<br />
Essentially, the command tells <tt>rsync</tt> to use <tt>ssh</tt> as the shell on remote end (the <tt>-e</tt> switch), while the <tt>-P</tt> switch tells it two things: that it should display the progress of the transfer, as well as that it only needs to do a partial transfer of the file. What falls between the inverted commas are the options that get passed to <tt>ssh</tt>--in this case <tt>-p 1234</tt> stipulating the port to connect to on the remote end.<br />
<br />
To simplify yet further this resuming process, an alias could, theoretically, be created as suggested <a href="http://eskatos.wordpress.com/2009/11/27/another-scpresume-alias-with-rsync/">here</a>. That would would not work in my case, however, since aliases appear not to allow the passing of special options to <tt>ssh</tt>: entering <tt>alias scpresume='rsync -Pazhv -e ssh -p 1234'</tt> at the command line caused the port specification to be received as an option by <tt>rsync</tt>--an option it was unable to interpret. Thus, the more permanent solution of adding that line to <tt>.bashrc</tt> would not work for me either.<br />
<br />
To make the alias work for me, I had to set up an <tt>~/.ssh/config</tt> file with the following content (as discussed <a href="http://www.linux-noob.com/forums/index.php?/topic/2848-ssh-and-bash/">here</a>):<br />
<br />
<textarea cols="67" readonly="readonly" rows="4" style="resize: none;" wrap="off">Host remote
HostKeyAlias remote.host.IP
HostName remote.host.IP
User username
Port 1234
</textarea><br />
<br />
After doing that, I was able to create the alias as <tt>alias scpresume='rsync -Pazhv -e ssh</tt> (note that the alternate port now does not need to be specified since it's entered into your <tt>~/.ssh/config</tt> file). It can now simply be run as <tt>scpresume remote:path-to/remotefile localfile</tt>. Once your <tt>~/.ssh/config</tt> file is set up, the <tt>scpresume='rsync -Pazhv -e ssh</tt> line is what needs to be entered into your <tt>.bashrc</tt> to make <tt>scpresume</tt> a permanent part of your command-line environment.<br />
<br />
Feel free to offer any improvements you may have or other suggestions for using alternate command-line utilities for resuming downloads. This method did the trick for me, and I was able to resume transfer of files that had petered out at varying points during the download process, but of course there could be other methods that are in some way superior.<br />
<br />
ADDENDUM: In light of the comment of a knowledgeable reader, the correct full, non-redundant command to use for file transfer resumption using <tt>rsync</tt> would be<br />
<blockquote class="tr_bq">
<tt>
rsync -Pazhv -p 1234 user@remote.host.IP:path-to/remotefile.mpg localfile.mpg</tt></blockquote>
wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com1tag:blogger.com,1999:blog-1541371521224765784.post-22260862430946396232013-01-04T15:40:00.000-08:002013-01-04T23:53:26.701-08:00Ninth Installment: Xmobar to the rescue!<div>
Regular readers of this blog will be aware of my inclination towards minimalist desktops or window managers and my preference, within reasonable limits, for low-resource and/or command-line tools and applications. And I've previously mentioned making use lately of the <tt>evilwm</tt> window manager, which I've pretty much settled on now in preference to two other minimalist window manages--<tt><a href="http://dwm.suckless.org/">dwm</a></tt> and <tt><a href="http://tuomov.iki.fi/software/">ion3</a></tt>--with which I experimented. One of the things I've missed, however, about the more full-blown desktops I've used, is some of the monitors or applets one can configure to run in the panel(s) and which give quite helpful system information like memory and/or CPU usage.<br />
<br />
I became aware some time ago of <tt>conky</tt>, a minimalistic utility that can display these--and many other--types of helpful information under differing window managers or desktops and, though I'd seen screenshots of it configured to run as a sort of panel, most <tt>conky</tt> configurations I've come across actually have it display on the desktop background--not something particularly desirable for me since I tend to run applications full-screen on my <tt>evilwm</tt> desktops. But lately, I somehow came across information about another utility--<tt><a href="http://projects.haskell.org/xmobar/">Xmobar</a></tt>--that can display the sorts of system information I want but which seems to be configured to run mainly as a panel. So I decided to have a go with it. I was able to configure it to my liking fairly easily and decided to offer in this entry a further description of the program and to post the configuration I am using. That information follows.<br />
<br />
To begin with a bit more information on <tt>Xmobar</tt>, it seems originally to have been written to complement the minimalist window manager <a href="http://xmonad.org/" style="font-family: monospace;">Xmonad</a> (which, incidentally, I've not tried). As the <a href="https://wiki.archlinux.org/index.php/Xmobar">Arch Wiki </a>entry--my main source for setting up and configuring <tt>Xmobar</tt>--informs us, it is written, as is <tt>Xmonad</tt>, in the Haskell programming language. In case you might be intimidated at the prospect of potentially having to learn something about that programming language, take heart; as the wiki entry further elucidates "while <tt>xmobar</tt> is written in Haskell, no knowledge of the language is required to install and use it."<br />
<br />
As with many other GNU/Linux utilities, <tt>Xmobar</tt> relies on a hidden configuration file--named, predictably, <tt>.xmobarrc</tt>--located in the user's home directory. The Arch wiki contains a sample configuration file, and that's the one on which I based my initial experiments with <tt>Xmobar</tt>.<br />
<br />
To start <tt>Xmobar</tt>, I simply call it as the last line in my <tt>.xinitrc</tt> file. That will, of course, not be the universally applicable way of starting the utility: those using a log-in manager will undoubtedly need to invoke the utility in some other way. Being the GUI-adverse type I am, however, this is what works for me.<br />
<br />
Below I include a screenshot of the lower section of one of my desktops, which shows <tt>Xmobar</tt> running as it is currently configured on one of my systems.<br />
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEDtxZYAKmdhEbbRn1VkVi8iilWI6DD0m0vt66GngJ896_7YLtxBMtnZBoA74R2BeJPkbKUlUA4UHgOAE_POh1duV_lAPf_6ZLcVkQCgFk9D8ZDFTtospQ4kY7G0hsQVNqVlib4Qdznrw/s1600/xmobar-crop.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="25" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEDtxZYAKmdhEbbRn1VkVi8iilWI6DD0m0vt66GngJ896_7YLtxBMtnZBoA74R2BeJPkbKUlUA4UHgOAE_POh1duV_lAPf_6ZLcVkQCgFk9D8ZDFTtospQ4kY7G0hsQVNqVlib4Qdznrw/s400/xmobar-crop.png" width="400" /></a></div>
<br />
Though a good deal will be obvious from the picture, I will nonetheless offer a verbal description of each section of the panel. After the description, I will provide the content of my <tt>.xmobarrc</tt> file for further reference.<br />
<br />
On the left side of the panel we see, on the far left, of course, a CPU meter of sorts (CPU percentage meter). Next to that is the memory meter, showing percentage of main <tt>RAM</tt> and swap in use. Then follows a network meter showing current upload/download speed: the dash to the left indicates <tt>Xmobar</tt> did not find <tt>eth0</tt> since, in the instance when the screenshot was taken, no network cable was attched to it. After the network speed indicator follows a keyboard layout indicator: at the moment the US keyboard layout is in use, but I also have Russian and Greek keyboards configured for this machine (more on keyboard layouts and switching between them in a future entry).<br />
<br />
On the right side of the panel is seen first the date and time. Next to that is a battery meter that displays percentage of battery charge left as well as estimated remaining time; the screenshot comes from a laptop, of course. That is followed by a location indicator and outside temperature reading: I happened to be near the town of Mikkeli in Finland at the time I wrote this entry--thus the EFMI weather station code in the configuration file below. Finally, the kernel version and distribution are listed--this being derived, of course, from uname output.<br />
<br />
Below, then, is the content of my <tt>.xmobarrc</tt> file. I added a few tweaks to the one I found on the Arch Wiki, mainly the battery meter as well as the keyboard layout indicator. I also did a bit of color tweaking since it seemed to me the section dividers (the pipe character--|) needed to be in a different color so as to more readily draw attention to the field delimitations. A bottom rather than top orientation was more to my liking, so I made that modification as well.<br />
<br />
<textarea cols="67" readonly="readonly" rows="20" style="resize: none;" wrap="off">Config { font = "-misc-fixed-*-*-*-*-14-*-*-*-*-*-*-*"
, bgColor = "black"
, fgColor = "grey"
, position = Bottom
, lowerOnStart = True
, commands = [ Run Weather "EFMI" ["-t","<station>: <tempf>F","-L","10","-H","90","--normal","green","--high","red","--low","lightblue"] 36000
, Run Network "eth0" ["-L","0","-H","32","--normal","green","--high","red"] 10
, Run Network "wlan0" ["-L","0","-H","32","--normal","green","--high","red"] 10
, Run Cpu ["-L","3","-H","50","--normal","green","--high","red"] 10
, Run Battery ["-t","<left>%<fc=#0000ee>/</fc><timeleft>","-L","30","-H","75","-h","green","-n","#ffff00","-l","red"] 10
, Run Memory ["-t","Mem: <usedratio>%"] 10
, Run Swap [] 10
, Run Com "uname" ["-r"] "" 36000
, Run Date "%a %b %_d %Y %I:%M:%S" "date" 10
, Run Kbd [("us", "US"), ("ru(phonetic)", "RU"), ("gr(polytonic)", "GK")]
]
, sepChar = "%"
, alignSep = "}{"
, template = "%cpu% <fc=#cd00cd>|</fc> %memory% %swap% <fc=#cd00cd>|</fc> %eth0% - %wlan0% <fc=#cd00cd>|</fc> %kbd%}{ <fc=#ee9a00>%date%</fc> <fc=#cd00cd>|</fc> %battery% <fc=#cd00cd>|</fc> %EFMI% <fc=#cd00cd>|</fc> %uname%"
}
</textarea><br />
<br />
I am thus far quite happy with <tt>Xmobar</tt>. At the same time, I would be interested to hear from <tt>conky</tt> users who have their layout configured as a panel like this. Feel free to pipe in with your input on these or other minimalist panel utilities.wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com2tag:blogger.com,1999:blog-1541371521224765784.post-54783535635807096792012-12-19T10:10:00.001-08:002012-12-20T12:29:50.412-08:00Eighth Installment: compress and encrypt/decrypt a directory<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I recently visited a relative who is studying in the natural sciences and who, surprisingly, is even less capable in certain technical aspects of computing than I am. He was trying to create, on his Mac, a script that would run as a <tt>cron</tt> job, and asked me for some pointers. Though I know the basics about <tt>cron</tt> and was willing to pitch in, I wasn't so sure about the script: you see, calling my <tt>bash</tt> skills rudimentary would be high praise. Nonetheless I decided that, with some web searching, I might be able to assist with that, too. Sure enough, I was able to find just the sort of information that would help us create a script that would <tt>tar</tt> and compress, then encrypt, a target directory. Details--shamelessly lifted from various locales on the web--are included below.<br />
<br />
Over the years that I've been using Linux I have, of course, read more than a few articles that describe methods of encrypting files or partitions. Most recently, for example, there appeared on Lxer an <a href="http://www.webupd8.org/2011/06/encrypt-your-private-dropbox-data-with.html">article</a> that described a clever way of encrypting a local directory that then gets backed up to some cloud storage service like <a href="https://www.dropbox.com/">dropbox</a>. I've bumped up against the issue of encryption when doing fresh installations as well, as it has been the case for some time now that an option is given on installation for many Linux distros of encrypting, for example, the <tt>/home</tt> directory.<br />
<br />
Despite reading at least some of those articles with interest, I did not feel the need to implement such encryption on my own systems. So it was not until someone else asked my assistance in doing something like this that I actually tried it myself. As you will see, it was actually fairly simple to implement. But first, a few caveats.<br />
<br />
I'll skip any details in the following description regarding the <tt>cron</tt> aspect of this project--not that I could provide a whole lot of enlightenment anyway--other than to say that it's a handy way to make programs or processes run on a set schedule on computers than run *nix. One way I've used it is to cause a weather map, which I've set up as the desktop background on one of my computers, to update every 10 minutes--look for a future entry in this blog on how I managed that.<br />
<br />
I'll also not speak in any depth about another ingredient in this recipe--<tt>tar</tt>--other than to say that it is an abbreviation for for "tape archive." I myself do not understand its workings terribly well, though I've used it on several occasions. I will mention on a related note, however, that, in my research, I ran across articles that used another, similar, utility--<tt>dd</tt> (an abbreviation for "disk dump")--to create compressed and encrypted archives. But I did not follow up on the <tt>dd</tt> option and so cannot post any further information about how that was done.<br />
<br />
Finally, I can't speak in any depth about the program I used for doing the encryption--<tt>openssl</tt>--or about another program with which I experimented and which also does encryption--<tt>gpg</tt>. But I promise, despite those rather glaring deficits, that I will describe something I managed to accomplish and which you, too, should be able to accomplish by following the steps outlined.<br />
<br />
Perhaps in some future entry for this blog I'll be able to further explore <tt>tar</tt>, <tt>dd</tt>, and/or <tt>cron</tt>. But for now I'm going to focus my attention mainly on the option we ended up using, which involved mainly <tt>tar</tt> and <tt>openssl</tt>.<br />
<br />
The relative in question, as I mentioned, works in the natural sciences. He has a directory of his ongoing work that he wants to back up regularly, but to which he does not want anyone else to have access. His choice for backing up beyond his own PC, is to use dropbox. So the task was, as mentioned, to compress and encrypt the target directory: moving it to the location on the local machine where dropbox would find it so as to back it up will also not be covered in this write-up, though that step did end up being part of his final resolution.<br />
<br />
So, what's left? It was quite easy to find directions of the web for doing all this. I pretty much went with the first workable solution I found, which came from the <a href="http://www.linuxquestions.org/">linuxquestions</a> forum (the relevant thread can be found <a href="http://www.linuxquestions.org/questions/linux-newbie-8/howto-encrypt-a-tar-file-on-the-fly-933314/">here</a>).<br />
<br />
The incantation we used was as follows:<br />
<br /></div>
<tt>tar -cj target-dir | openssl enc -aes128 -salt -out target-dir.tar.bz2.enc -e -a -k password</tt><br />
<br />
What that line does may be evident to most, but I will offer a bit of review nonetheless. The target directory is first <tt>tar</tt>'red and compressed with <tt>bzip</tt>, (the <tt>c</tt> option stands for "create" and the <tt>j</tt> option specifies that the created file should be compressed with <tt>bzip2</tt>) then it is piped to <tt>openssl</tt> for encryption. The word "password" is, obviously, to be replaced by whatever password the user chooses.<br />
<br />
One possible drawback to this method, as pointed out in the thread from which I lifted it, is that the encryption password gets entered, in plain text, right on the command line (which is slightly less of an issue with a <tt>cron</tt> script such as we were creating). Thus, anyone who can gain access to the machine can, by using the command line history, see what the encryption password was. Since someone gaining access to his computer and viewing the command line history was not a concern for the fellow I was helping, this is the solution we implemented. But that potential concern can be easily remedied by simply leaving off the <tt>-k password</tt> switch at the end, which has the effect of prompting the user for a password, which does not get echoed to the command line.<br />
<br />
To decrypt the file, the following command--which prompts for the password--is used:<br />
<tt><br /></tt>
<tt>openssl enc -aes128 -in target-dir.tar.bz2.enc -out target-dir.tar.bz2 -d -a
</tt><br />
<br />
The file can then be uncompressed and untar'red. This part of the process could likely be reduced from two steps (decryption, then uncompression/un<tt>tar</tt>'ing) to one by using a pipe, but since it was presumed, for purposes of this project, that the file would act simply as insurance against loss--the need for ever actually recovering the content being very unlikely--I did not pursue streamlining that aspect.<br />
<br />
I did manage to find and test a couple of other variants which I will offer here as well. The second variant was found <a href="http://www.vanemery.com/Linux/Apache/openSSL.html">here</a>, and follows:<br />
<br />
<tt>tar -cj target-dir | openssl enc -e -a -salt -bf -out target-dir.blowfish
</tt><br />
<br />
It is much the same as the first variant, though it uses a different encryption method called blowfish. I am uncertain which of these two encryption schemes is considered better. To decrypt the compressed directory, the following command is used:<br />
<br />
<tt>openssl enc -d -a -bf -in target-dir.blowfish -out target-dir-decrypt.tar.bz2</tt><br />
<br />
Finally, I discovered yet another variant, details about which can be found <a href="http://www.madboa.com/geek/gpg-quickstart/">here</a>. A sample of how to use this one is as follows:<br />
<br />
<tt>tar -cjf target-dir.tar.bz2 target-dir/ | gpg -r user -e target-dir.tar.bz2</tt><br />
<br />
As will be noted, this variant uses <tt>gpg</tt> to encrypt the directory. Of course <tt>user</tt> must be replaced by the name of someone who has a valid <tt>gpg </tt>key on the system, usually the primary user of said machine or account.<br />
<br />
An interesting feature I discovered about this method is that a time-sensitive <tt>gpg</tt> key can be created, i.e., one that expires after a certain interval. If I understand correctly how this works, once the key expires, the directory can no longer be decrypted.* This feature should, obviously, be used with care.<br />
<br />
Decrypting the directory can be done in the following way:<br />
<br />
<tt>gpg --output target-dir.tar.bz2 --decrypt target-dir.tar.bz2.gpg</tt><br />
<br />
The same two-step process of decrypting, then un<tt>tar</tt>'ing/uncompressing, applies to these two methods as well.<br />
<br />
This sums up what I have to offer in this entry. Now that winter is upon us northern-hemispherers, I may be able to post more frequent entries. There are a few things I've been wanting to document for some time now.<br />
<br />
* Correction: an anonymous commenter writes of my claim that the key expiration makes decrypting the file no longer possible that "Unfortunately not. The expired key is no longer trusted but is still functional."</div>
wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com2tag:blogger.com,1999:blog-1541371521224765784.post-78961899854913215412012-12-08T13:18:00.001-08:002012-12-10T21:12:59.549-08:00Seventh installment: imagemagick trick 1 of (?)<div dir="ltr" style="text-align: left;" trbidi="on">
During a recent vacation, I needed to convert some digital images taken by a relative's camera from a raw format into something that would display better on my laptop. As usual, <tt><a href="http://www.imagemagick.org/script/index.php">imagemagick</a></tt> came to the rescue. Details are included below.<br />
<br />
<tt>imagemagick</tt> has been called something like "the swiss army knife of image manipulation utilities." I've utilized this application on many occasions over my years as a GNU/Linux user and been amazed to have as yet found nothing that it <i>cannot</i> do. Moreover, it's a CLI-friendly tool, which makes it doubly appealing for someone like me who favors using the least resource-intensive application for any given job.<br />
<br />
I should mention that, not only was I converting these images to a different format with which my laptop could better deal, desirable, but resizing them was needed as well. You see, each photo taken by this fairly high-end camera came in at about 25 megabytes, and the dimensions of each image were probably in thousands of pixels. So I wanted to both resize and convert them; but, based on past experience with <tt>imagemagick</tt>, I was sure it would be up to the job.<br />
<br />
I was surprised, after some initial searching on how to accomplish this task, at how simple this task would turn out to be. After mounting the Secure Digital card on my laptop, I copied over all the images--which had the <tt>.CR2</tt> extension, by the way--to a temporary directory on my laptop.<br />
<br />
The incantation I then used, after <tt>cd</tt>'ing to the temporary directory where the images resided, was <tt>mogrify -format jpg -geometry 1024x768 *.CR2.</tt> It should be fairly obvious what this does, but just in case it's not, let me explain. The <tt>mogrify</tt> command is part of <tt>imagemagick</tt>'s image manipulating routines and can be invoked to do a number of things with an image, but in this case the <tt>-format</tt> switch, followed by the <tt>jpg</tt> extension, tells it to convert from one format to another.<br />
<br />
Though most readers of this blog are likely to know this already, it will be worth mentioning that the asterisk preceding the file extension is the wildcard symbol. Thus, all files in that directory with the designated extension get converted. Incidentally, they are given the same prefix as the raw <tt>.CR2</tt> files, but after conversion have the <tt>.jpg</tt> extension instead of the <tt>.CR2</tt> extension.<br />
<br />
I should mention here that, although raw formats are not especially new, I did run across some indications while researching how to do this, that older versions of <tt>imagemagick</tt> might not be able to operate on such formats. But I believe any version that's come out in the last 2 or 3 years should understand and be able to manipulate these raw formats.<br />
<br />
The <tt>-geometry</tt> switch tells <tt>imagemagick</tt> to resize the image from something in the thousands of pixels down to a size that displays better, and takes up a whole lot less disk space, on this laptop. The switch does also have a somewhat undesirable effect on photos taken in vertical rather than horizontal orientation, since, as written to disk, these are taller than they are wide (whereas photos taken in horizontal orientation are wider than they are tall): the program thus makes the height of the photo 768 pixels, while the width, being kept proportional, turns out to be quite a bit less than that. But for my purposes--which was simply being able to view quickly these fresh photos on my laptop--these somewhat under-sized photos did not pose any particular problem.<br />
<br />
The process of converting many photos this way can be lengthy, but, as you have seen, it is quite simple. I would simply start the process, then either do some other task in another desktop while awaiting completion, or just set the laptop aside while it was running the process. After about a half hour or so, I was ready to view photos.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGxFiA6hZwqIL_s4_3bZiIpNjzI7fOt6C6YNrqWz5ZpSwkjGvQC3VdWtJ-hV2cyG_3t-l42l12V9gSml_URsLwRizDoT_2Scs_rGRbP0G1Rt8Ab5RyBMxb0jRNMKMagx4mu9Zv2FyxYuc/s1600/2012photo.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="266" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGxFiA6hZwqIL_s4_3bZiIpNjzI7fOt6C6YNrqWz5ZpSwkjGvQC3VdWtJ-hV2cyG_3t-l42l12V9gSml_URsLwRizDoT_2Scs_rGRbP0G1Rt8Ab5RyBMxb0jRNMKMagx4mu9Zv2FyxYuc/s400/2012photo.jpg" width="400" /></a></div>
Above is a sample of one of the converted images. Oh, and by the way, the "(?)" in the title of this entry is meant to indicate the multitude of other <tt>imagemagick</tt> tricks, as yet unknown to a relatively casual user such as myself, there are likely to be.</div>
wayover13http://www.blogger.com/profile/13204644261961607009noreply@blogger.com3