dannyman.toldme.com


Featured, FreeBSD, Linux, Mac OS X, Technical

HOWTO: Random Number in Shell Script

Link: https://dannyman.toldme.com/2008/07/04/shell-sh-bash-random-splay/

The other day I was working on a shell script to be run on several hundred machines at the same time. Since the script was going to download a file from a central server, and I did not want to overwhelm the central server with hundreds of simultaneous requests, I decided that I wanted to add a random wait time. But how do you conjure a random number within a specific range in a shell script?

Updated: Due to much feedback, I now know of three ways to do this . . .

1) On BSD systems, you can use jot(1):
sleep `jot -r 1 1 900`

2) If you are scripting with bash, you can use $RANDOM:
sleep `echo $RANDOM%900 | bc`

3) For portability, you can resort to my first solution:
# Sleep up to fifteen minutes
sleep `echo $$%900 | bc`

$$ is the process ID (PID), or “random seed” which on most systems is a value between 1 and 65,535. Fifteen minutes is 900 seconds. % is modulo, which is like division but it gives you the remainder. Thus, $$ % 900 will give you a result between 0 and 899. With bash, $RANDOM provides the same utility, except it is a different value whenever you reference it.

Updated yet again . . . says a friend:
nah it’s using `echo .. | bc` that bugs me, 2 fork+execs, let your shell do the math, it knows how
so $(( $$ % 900 )) should work in bsd sh

For efficiency, you could rewrite the latter two solutions:
2.1) sleep $(( $RANDOM % 900 ))
3.1) sleep $(( $$ % 900 ))

The revised solution will work in sh-derived shells: sh, bash, ksh. My original “portable” solution will also work if you’re scripting in csh or tcsh.

2 Comments


Technical

HOWTO: Link to Google Search with hidden site: parameter

Link: https://dannyman.toldme.com/2008/05/30/howto-google-search-site-parameter-as_sitesearch/

I was trying to hack up a little search box to access the local Google search appliance. I know you can search with a query like “foo site:example.com/docs” but I wanted to pass site: in as a form parameter. Here is an example of how to do that:

<form action="http://googleplex.example.com/search">
    <input type="text" name="q" />
    <input type="hidden" name="as_sitesearch" value="example.com/docs" />
</form>

So, where you might use site: in the search field, you use as_sitesearch as a hidden search parameter. I figured this out by squinting at the Google Advanced Search page.

Feedback Welcome


Good Reads, News and Reaction, Technical, Technology

O’Reilly: Don’t Reinvent the Penis

Link: https://dannyman.toldme.com/2008/05/26/dont-reinvent-penis/

O’Reilly has some fun and insightful reading on the whole Microsoft-Yahoo! drama. The idea is that instead of chasing the competition because you have “penis envy” and spending your time and energy re-inventing what someone else already kicks ass at, you should figure out what awesome new things need to be built, and go do that instead. Yahoo! shouldn’t waste its time on search when what it is really good at is building a great media portal and user experience. Similarly, Microsoft should probably focus on building better network-enabled user software.

“So, my advice to Yahoo!: continue with your plan to outsource search to Google, just like you did before 2002, and plow those increased profits and reduced costs into your own innovation, strengthening the areas where you are #1, exploring new ideas that will make YOUR users insanely happy, and generally focusing on what makes Yahoo! great, rather than on what doesn’t.”

I kind of figure that building search is a waste of Yahoo!’s energy, and that if Microsoft wants to ditch their own failed effort and give Yahoo! a chunk of cash for its also-ran technology, well then hooray for Yahoo!

I was also reading about Sugar, which I have gotten to play with on the OLPC XO-1. It is somewhat frustrating to deal with because I really really really like having access to the file / folder metaphor for tracking my work. I do like the “history” interface to “activities” via the Journal, and the built-in collaboration, although I have not had a chance to actually “collaborate” with any one, seems like a really big win–the sort of thing that has a lot of potential not only for education but in the office environment that we adults use as well. It is too bad that collaboration via shared applications is such an under-developed idea. That strikes me as the sort of thing that ought to be within Microsoft’s grasp to run with, and a nice answer to the Google “spreadsheet in a web browser” mentality.

1 Comment


Linux, Technical

Canon i250 on Ubuntu 8.04

Link: https://dannyman.toldme.com/2008/05/14/canon-i250-hardy-heron/

The Ubuntu upgrade broke printing. Among other things, it removed my canoni250.ppd file. I struggled with it to no avail. Then I went back and pasted the commands in from last time and now it all works.

Yay.

2 Comments


FreeBSD, Linux, Mac OS X, Technical

Mini-HOWTO: What Time is UTC?

Link: https://dannyman.toldme.com/2008/05/06/what-time-utc/

I wanted to know what time it was in UTC, but I forgot my local offset. (It changes twice a year!) I figured I could look in the date man page, but I came up with an “easier” solution. Simply fudge the time zone and then ask.

0-20:57 djh@noneedto ~$ env TZ=UTC date
Tue May  6 03:57:07 UTC 2008

The env bit is not needed in bash, but it makes tcsh happy.

Update: Mark points out an easier solution:
date -u

Knowing you can set TZ= is still useful in case you ever need to contemplate an alternate timezone.

(Thanks, Saul and Dave for improving my knowledge.)

3 Comments


Linux, Technical, Technology, WordPress

WordPress 2.5.1

Link: https://dannyman.toldme.com/2008/04/25/wordpress-251/

There’s a notice on the WordPress dev blog that WordPress 2.5.1 is out. Alas, they neglected to link to the upgrade documentation. My favorite? Upgrading via Subversion:

0-11:17 djh@ratchet ~> cd public_html/toldme
0-11:17 djh@ratchet ~/public_html/toldme> svn sw http://svn.automattic.com/wordpress/tags/2.5.1/
[ . . . ]
Updated to revision 7839.

When I logged in to post this little note, it blocked me and ran the upgrade procedure, then I had to log in again, and here I am!

There’s a further note about the secret key setting:

Since 2.5 your wp-config.php file allows a new constant called SECRET_KEY which basically is meant to introduce a little permanent randomness into the cryptographic functions used for cookies in WordPress. You can visit this link we set up to get a unique secret key for your config file. (It’s unique and random on every page load.) Having this line in your config file helps secure your blog.

It leaves me to wonder: if the secret key can be randomly generated by a machine, why not go ahead and do that and then stash it in the database? There may be a good reason for that . . .

In unrelated news, I upgraded to the newer Ubuntu release at home yesterday. The only trick I have noticed so far is that it runs with Firefox 3.0, which is beta, and I lost use of my foxmarks plugin, for now. So, I’m waiting until that is supported before I upgrade my workstation.

Feedback Welcome


Politics, Sundry, Technical, Technology

Special Election Day

Link: https://dannyman.toldme.com/2008/04/08/special-election-day/

Today was a special election for my congressional district. It was an open primary for Congress–two Democrats, two Republicans, and a Green. I voted for the Green candidate in part because he is the only one who sent any campaign literature, and because this is a safely gerrymandered Democrat district anyway.

I was the first citizen of my precinct to try the electronic ballot. To explain the touch screen, the staff boasted “it’s just like an iPhone!” I dug around in English and Chinese and explored the “large print” zoom feature, then I had to ask how one actually casts the ballot. (The user interface places commands on the bottom of the screen, but the “review screen” had a big box in the middle that said “press here to review your paper ballot” and below that the standard “review” button to review the electronic ballot . . . I kept pressing the little button, until the guy showed me that the big box in the middle is also a button.)

I was pleased at the paper trail. On my way out, I noted that the optical scanner had counted three ballots thus far, so this morning’s exit poll is running at least 25% Green.

Feedback Welcome


Linux, Technical

Canon i250 on Ubuntu 7.10

Link: https://dannyman.toldme.com/2008/03/13/canon-i250-ubuntu-feisty/

I had a rough go of it until I found BlackNight’s post, and now my Canon i250 printer works with Ubuntu like a charm. I thought I would recap here for those who, like me, at first Googled in vain. If you paste these command into Ubuntu 7.10 (Feisty) things ought to work:

First, enter your sudo password:

sudo echo

Now, this paste just might set up everything you need:

sudo apt-get install libpng3 libtiff4 cupsys alien
cd /tmp
wget http://download.canon.com.au/bj/i250linux/bjfilteri250-2.3-0.i386.rpm
wget http://download.canon.com.au/bj/i250linux/bjfiltercups-2.3-0.i386.rpm
sudo alien --scripts bjfilteri250-2.3-0.i386.rpm
sudo alien --scripts bjfiltercups-2.3-0.i386.rpm
sudo dpkg -i bjfiltercups_2.3-1_i386.deb bjfilteri250_2.3-1_i386.deb
sudo ln -s /usr/lib/libtiff.so.4 /usr/lib/libtiff.so.3
sudo ln -s /usr/lib/libpng.so.3 /usr/lib/libpng.so.2
sudo /etc/init.d/cupsys restart

Then, go set up your printer in the GUI, and specify this PPD file:

/usr/share/cups/model/canoni250.ppd

(Or, in retrospect, since it has a GNU license on it, you could just download the PPD directly off my web site.)

If things turn out less-than-straightforward, definitely review BlackNight’s page for details, and if this does work out for you drop him a thank you note in the comments!

5 Comments


About Me, Excerpts, Featured, Technical, Technology

Danny Ten Years Ago

Link: https://dannyman.toldme.com/2008/03/09/computer-literacy-decade/

It is fun to see how people change over time, and how they stay the same. A decade ago I wrote a “Computer Literacy Narrative” for an English class:

The Internet continues to play a very big part in my life. My web site grows slowly every week. I keep my diary on-line for others to read. I write CGI applications. I’m a hard-core Unix geek, administering two of my own systems, writing my HTML and perl scripts in vi, wowwing friends with afterstep. I work for the networking group at NCSA, for the CSIL as a labsitter, and worked last summer at an ISP in Chicago called EnterAct, where I may very well return this summer.

I now use only Unix, and my old Amiga systems from time to time out of nostalgia and respect for history. I own two Unix boxen, four Amiga systems, and the old Commodore 64. While most of these are antiques, I still lend some systems out to others from time to time to facilitate their computing needs.

My fanatical Unix snobbery does mean that I know very little about Windows 95 or Mac. Because I have good computer karma, I still tend to negotiate such systems better than the average Joe, but I’m by no means a wiz. Instead I enjoy spending my time tinkering with completely open systems like FreeBSD. I am proud and inspired by the idea that there are now several very competent Operating Systems available even for normal users that are built and maintained entirely by volunteer effort. It is my goal to continue to learn and ultimately contribute to this effort as I can.

“Wow.”

Feedback Welcome


Sundry, Technical, Testimonials

“Focus Follows Mouse!!”

Link: https://dannyman.toldme.com/2008/02/12/geek/

Walking down the hall at work, I hear an engineer lament.

“Click to focus? Arr!!”

And of course, I shout:

“Focus follows mouse!!”

I hear, beyond cubicle walls, a chorus of agreement.

Back at my desk, which I have recently switched from XP to Ubuntu, I note that I’m clicking to focus. Fortunately, I spent the morning tweaking mutt, which I started using again, after many years, because it deletes e-mail faster than Thunderbird does.

I like this place.

I hear muffled discussions of multiple desktops. I think I’ll figure out how to FocusFollowsMouse in this Gnome stuff real quick before I return my attention to work-work.

ObSolution: In Ubuntu / Gnome, go to System > Preferences > Windows and enable “Select windows when the mouse moves over them”

Feedback Welcome


News and Reaction, Sundry, Technical, Technology, Testimonials

Why I Hope Yahoo! Says No

Link: https://dannyman.toldme.com/2008/02/01/please-stay-yahoo/

Much buzz about Microsoft’s offer to buy Yahoo!

I am a big fan of Google and their myriad products, but sometimes they get on my nerves. I like having Yahoo! as an alternative. I love Flickr. I would hate to see Yahoo! swallowed up my Microsoft, leaving the biggest players on the Internet being a choice between the Google and the Microsoft.

I prefer an online world that isn’t simply black and white, but which also has a weird shade of purple to it.

Feedback Welcome


Featured, Free Style, FreeBSD, Linux, Mac OS X, Sundry, Technical, Technology

Trendspotting: “The Amiga Line”

Link: https://dannyman.toldme.com/2008/01/26/deader-than-amiga/

I have been playing with Google Trends, which will be happy to generate a pretty graph of keyword frequency over time. A rough gauge to the relative popularity of various things. This evening, I was riffing off a post from the Royal Pingdom, regarding the relative popularity of Ubuntu and Vista, among other things.

I got started graphing various Linux distributions against each other, XP versus Vista, and trying to figure out the best keyword for OS X. Then, I wondered about FreeBSD. Against Ubuntu, it was a flatline. So, I asked myself: what is the threshold for a dead or dying Operating System?

Amiga vs FreeBSD:
Google Trends: Amiga versus FreeBSD

Ouch! Can we get deader?

Amiga vs FreeBSD vs BeOS:
Google Trends: Amiga versus FreeBSD versus BeOS

To be fair, the cult of Amiga is still strong . . . BeOS is well and truly dead. But how do the BSDs fare?

Amiga vs FreeBSD vs BeOS vs NetBSD vs OpenBSD:
Google Trends: *BSD versus Amiga, BeOS

NetBSD has been sleeping with the BeOS fishes for a while, and OpenBSD is on its way. And that’s a league below Amiga!

In Red Hat land, only Fedora beats “the Amiga Line”. For Unix in general, nothing stops the Ubuntu juggernaut. But there’s a long way to go to catch up with Uncle Bill.

(Yes, it is a rainy night and the girlfriend is out of town.)

Postscript: Ubuntu versus Obama

3 Comments


Featured, News and Reaction, Technical, Testimonials

NotchUp? Not so much . . .

Link: https://dannyman.toldme.com/2008/01/26/notchup-launch-interview/

I just got an invitation to join NotchUp. Wary of the latest craze in data mining masked as social networking I did a quick Google search. TechCrunch had the best summary.

We’re basically looking at LinkedIn (they even import your LinkedIn profile) except that you can set a price at which you would be willing to interview with a prospective employer. The idea being, maybe you are happy where you are but you’d be happy to talk about being somewhere else, though your time is valuable. (Employers, of course, already know that recruiting is an expensive undertaking . . . it is not hard to see them pony up . . .)

NOT!

Apparently this is from “Peerflix refugees” so I’d peg it as “an interesting innovation that rips off an existing proven idea that is probably ahead of their ability to execute.”

I accepted the invite, to check it out but mainly so I could invite a friend who is job hunting. I figured if Powerset and Yahoo giving it a go . . .

First Impressions:

Actually, now I feel dirty. I’m changing my LinkedIn password . . .

8 Comments


Technical

TIP: Vim can add and subtract!

Link: https://dannyman.toldme.com/2008/01/23/vim-increment-decrement-integers/

I have been using Vim for years, and have any number of times (say, when dealing with DNS configuration) had to edit many lines, changing integers by a constant value, and it was always a hassle to repeatedly switch modes and type in a new number. “There must be some macro or other special mojo,” I thought, “and sometime, I will figure this out.”

Well, there is special mojo, and the figuring it out is so dead simple I kick myself for not knowing this years ago:

Vim Tip 287: Cool trick to change numbers

Yes, I rated that tip as “life changing”!

1 Comment


Technical, Technology

NAQ: Tellme Application Advice

Link: https://dannyman.toldme.com/2008/01/17/tellme-get-hired/

So, in the unlikely event that you are reading this, and trying to score a job at Tellme, I stumbled upon a little tip while trying to debug something else: check out their HTTP headers, particularly the X-Great-Jobs: header.

I got hired there back when it was in stealth mode, and they left a “secret” message as an HTML comment on the front page of the web site. It is nice to see an old tradition is still around. It is also weird to see that their present “cover image” is an intersection on the same street my grammar school was on, back in Chicago.

1 Comment

« Newer Stuff . . . Older Stuff »
Site Archive