A sh script INI parser

An INI file provides an old-timey way to configure applications. On MSDOS and early versions of Windows, it was the primary configuration mechanism. (Sadly, it’s been mostly replaced by the stupid registry.) Fortunately, INI files are still around because they remain very useful. On Linux, many developers have adapted the format.

Years ago Your JoeDog wrote an INI parser in sh. This enabled him to use one config file across multiple SAP landscapes. Each section of the file, is headed by the landscape name: [D] [Q] [P] etc. A script’s configuration varied depending on which landscape it was launched in. This enabled us to test on one landscape and promote the script without any changes to the next one.

Recently a colleague needed this type of one-with-many configuration. She needed to loop through a list of servers and reference their many attributes. Your JoeDog dusted off this parser for her and now he’s passing it along to you.

Consider this INI file:

#
# The parser supports comments
[WEB]
 srv = www.joedog.org
 usr = jdfulmer
 file = haha.txt
 path = /usr/local/content/www
[FTP]
 srv = ftp.joedog.org
 usr = jeff
 file = papa.txt
 path = /usr/local/content/ftp

Now here’s a script that contains our parser along with an example of how to use it:

#!/bin/sh
##++
## Parses an INI style file:
## [section]
## attr=thing
## key=val
## [header]
## thing=another
## foo=bar
## <p>
## @param file full path to the INI file
## @param section a header that matches the stuff in brackets [section]
## @return void (the variables are made available to your script)
##--
ini_parser() {
 FILE=$1
 SECTION=$2
 eval $(sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
 -e 's/[;#].*$//' \
 -e 's/[[:space:]]*$//' \
 -e 's/^[[:space:]]*//' \
 -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
 < $FILE \
 | sed -n -e "/^\[$SECTION\]/I,/^\s*\[/{/^[^;].*\=.*/p;}")
}
# A sections array that we'll loop through
SECTIONS="WEB FTP"
for SEC in $SECTIONS; do
 ini_parser "papa.conf" $SEC
 echo "scp $file $usr@$srv:$path/$file"
done
exit

Now let’s run this script and see what happens:

Pom $ sh papa
scp haha.txt [email protected]:/usr/local/content/www/haha.txt
scp papa.txt [email protected]:/usr/local/content/ftp/papa.txt



Posted in Programming, sh | Leave a comment



Site Outage Or How To Move Your EC2 Into Another Region

Your JoeDog’s site was down for much of the afternoon. Why? Well, it appears some Amazon employees are having a bad day. This site is hosted with Amazon Web Services and throughout much of the day it was unavailable. When he could get in, Your JoeDog checked his logs for a root cause. As far as he could tell, there was nothing wrong at the server level. Something was wrong with the host.

Hoping the problem was regional, Your JoeDog decided to move his EC2 instance into another region. He did that by following these steps inside the EC2 console:

  1. Shut down the running instance
  2. Hilight the volume, then Actions => Create image
  3. Go to AMIs on the left nav; select your image, then Actions => Launch
  4. As you navigate the settings select a new region to place it in.

Your JoeDog’s server runs in the Western region and he didn’t have an option to move it east. He did, however, have subregions from which to choose. Whereas the old server was running in us-west-2a, he put the new one in us-west-2c.

When the server came up, it did so with new security settings. No problem. It’s easy to associate the new server with your old rules. Hilight it in the dashboard then select Actions => Networking => Change Security Group. You can select your old group and toss the new one that was created when you launched a new image.

NOTE: Your JoeDog now has two volumes and one running instance in his EC2 Dashboard. He’s 99% certain he can toss that old volume but that won’t happen until he grabs copies of all his 1s and 0s. (Just to be safe).

 

Posted in OS, System | Leave a comment



ArrayList.ensureCapacity

Have you ever wanted to initialize a java ArrayList to a certain size? You peruse the javadoc and you see what appear to be two different options, one is a constructor option and the other is a chained method.

Here’s the constructor:

ArrayList (int initialCapacity)

Constructs an empty list with the specified initial capacity.

And here’s the method:

void ensureCapacity(int minCapacity)

Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

And here’s the thing: Neither one changes the logical size of the array. They each change its capacity. That is they change the size it can reach before it has to start copying its values to resize itself. If you do something like the following, you’ll get an IndexOutOfBounds Exception:

ArrayList<String> list = new ArrayList<String>();
list.ensureCapacity(200);
list.add(190, "JoeDog");

Exception in thread "main" java.lang.IndexOutOfBoundsException

If you want to initialize an ArrayList to a particular size, you’ll have to roll your own method:

 private static void ensureSize(ArrayList<?> list, int size) {
   list.ensureCapacity(size);
   while (list.size() < size) {
     list.add(null);
   }
 }

You can call it like this:

ArrayList<Thing> list = new ArrayList<Thing>();
ensureSize(list, 64);

 


Posted in Java, Programming | Leave a comment



CENTCOM Gets PWND

baseYour JoeDog followed the events in France pretty closely. After reading two days of reports from the US and Europe, he had no fscking clue what was going on. The killers were captured and one was dead! Um, the killers are in the woods with helicopters overhead! Um, no, they’re inside a Jewish deli back in Paris. In a rush to publish, the only thing they did was add to our confusion.

And so it goes with the CENTCOM hack. Your JoeDog heard ISIS was inside Pentagon computers!!1!1!!! After sifting through news reports, it appears that ISIS simply defaced their Twitter and YouTube accounts. Wait a second — CENTCOM has a twitter account? What do they post besides “blew up some shit today!”

Is this a Big Deal? It depends on your perspective. From a security standpoint, it’s not. Imagine if you shared your GMail password with a friend and he started sending dick pics to everyone in your address book. That’s pretty much what happened. ISIS gained access to the accounts and pranked the military.

From a public relations perspective, it’s embarrassing. Unless they’re absolute morans, no sensitive data was compromised.  You wouldn’t link your bank account to your twitter feed, there’s no reason to believe CENTCOM would do the same with its operational servers. But at the same time, it paints US military as a careless organization. It didn’t use two-factor authentication, its credentials were easy to crack and/or it fell for a phishing expedition.

It does make you wonder what else they’re “protecting” with ‘password123′ or to what extent the people inside Central Command are click-happy. Those are speculative musings which may have no basis in fact. Still, you can imagine a military ass-chewing that began with the Commander-in-Chief and worked its way down to the lowliest private. Your JoeDog is glad he doesn’t work in CENTCOM today.

 

 

Posted in On The Job, Security, Tech Media | Leave a comment



Anonymous At War

anonYour JoeDog blogged about politics for a solid five years. During that time, there was nobody he wouldn’t attack head-on. With his blogging posse, he helped drive several foes from the Internets, he defaced other blogs with titties and Goatse and waged a holy war with the state of Denmark. He even got into a bare-knuckle brawl with Daniel Pearl’s widow. (Hey – she started it.)

But it’s not true to say he’s without fear. Your JoeDog wouldn’t dream of sparring with the “hacker” collective known as Anonymous. They have a lot combined knowledge and a lot of time on their hands. You may consider yourself well guarded but Anonymous will tirelessly prod your defenses until they find an exploitable weakness. They are more relentless than you are thorough.

And so Your JoeDog was greatly amused when he learned that Anonymous declared war on Islamic Jihadis. Because fsck Jihadis. Their values are anathema to hacker values. They try to silence opposing views. They monopolize information and points of view. They destroy rather than build. They are sexist, intolerant douchebags.

Anonymous will start with their social media but they’ll soon tire of that and move onto other things. The fledgling Islamic State surely has some digital infrastructure that could use a good fscking with. And I have no doubt they’ll expose the identities of Western assholes who take up weapons in the name of a sixth century goat herder. Good luck, Jihadis. You’re gonna need it.

 

Posted in System | 1 Comment



Now That’s Traffic

Posted in Uncategorized | Leave a comment



Robots Schmobots

Total Factor Productivity

Total factor productivity measures residual growth that cannot be explained by production inputs. Its level is determined by the efficiencies of labor and capital in production. Huh? What are you talking about? Basically, it’s a measure of productivity attributed to technological or organizational improvements. Then why didn’t you say that?

As you can see in this chart Your JoeDog cooked up with FRED, total factor productivity has leveled since the late 1990s. In other words, the pace at which humans are replaced by robots has slowed during the Internet Age. More people lost jobs to automation in the 80s and 9os than lose them now. That’s comforting … I guess.

So all the angry monkeys pecking CAPLOCKED rants about automation in the comments sections are simply displaying ignorance. Automation isn’t their foil – it’s bumbling economic stewardship.

There’s no reason to believe that employment won’t return to its 1990s levels if policy makers either increased aggregate demand or made labor scarcer, i.e., spent money or enacted labor laws. Unfortunately the people George Carlin referred to as “the owners of this country” oppose both measures. Blame them, not robots.

 

Posted in Technology | Leave a comment



Who’s Honoring Me Now?

Your JoeDog’s Fido was selected by Profit Bricks as its 24th Best Free Sysadmin Tool

About Fido:

A multi-threaded file watch utility, Fido can monitor a file or directory to see if its modification time changed, and it’s intuitive enough to recognize a change even if the daemon was down at the time of the change. Written for RedHat Enterprise Linux, Fido should run in all Linux flavors, and the source bundle contains RedHat init.d scripts for users’ convenience.

Key Features:

  • Content changes can be recognized with regular expression pattern matches
  • Monitors files for changes in content or modification times
  • It will kick off a user-defined script when it notices a change
  • Coded to POSIX 1003.1 standards
Posted in Applications, Fido | Leave a comment



Will Artificial Intelligence Take Over The World?

singularitySome are concerned that self-improving artificial intelligence will destroy the world. Stephen Hawking thinks it could destroy mankind. Elon Musk recently tweeted, “I hope we’re not just the biological boot loader for digital superintelligence.” The Guardian thinks they will disrupt jobs while leaving humans physically unharmed.

The idea is this: we build robots with smart digital brians. Those robots use those brains to build even smarter brains. Once they achieve recursive improvement, robot intelligence will rapidly advance. The most advanced species on the planet won’t a species at all – it will be a line of super intelligent robots. Welcome to the technological singularity.

People fear these machines will one day turn on humans and destroy mankind. That could occur in one of two ways: 1.) They intentionally destroy us or 2.) They unintentionally destroy us.

The first scenario requires a goal. To intentionally destroy us, robots must want to destroy us. They’ll need a test case to measure improvement. “This feature kills better than the old one.” Computers don’t feel emotions. They’re not driven by love or hate. If they’re driven to kill humans it’s only because we programmed that feature in the first place. We could be that stupid, but this seems improbable.

The second scenario seems more likely. Self-improving artificial intelligence could be programmed to reverse global warming. When the robot is ready to go-live with its fix, it better have it right or it could render the planet inhospitable to life. In other scenarios, they could deprive humans of resources as they work tirelessly to achieve a goal.

But what if robots achieve something akin to emotion? If they can set their own goals or follow their own “interests”, then who knows where this technology will go. They may devote resources to solving math problems or they might hunt humans for sport. Either way, if technology destroys humanity, we’ll have only ourselves to blame….

 

 

 

Posted in Technology | Leave a comment



Google Bombing

bombBefore he blogged about technology, Your JoeDog blogged about politics. One day, he received an inquiry from the Detroit Free Press. The author — whose name escapes him — was doing a feature on Google bombing and Your JoeDog was google-bombing the President of the United States! What kind of political statement was he making with this google bomb, she wanted to know. Your JoeDog told her that he’s just tossing cyber spitballs from the back of the room.

For those who’ve never heard of it, google bombing is the practice of poisoning search results so that an unrelated page ranks high on a disparaging term. You trigger these bombs by linking to a site with your favorite derogatory phrase. If we all link to the Imperial Grand Poobah of North Korea as Little Kim, we can help craft “Little Kim” as his his online identity.

After the Iraq War debacle, “Miserable Failure” became George W. Bush’s online identity. His allies countered by linking the same phrase to Michael Moore. Unwilling to be a participant in bitter partisan politics, Google changed it’s algorithm and George Bush fell thousands of positions for that phrase.

“But wait!” you might say. “If Google changed its algorithm, then how come Rick Santorm remains a ‘frothy mixture of lube and fecal matter’?” That’s a good question!

Google’s change worked like this: if the words associated with a link do NOT appear on the page, then that link won’t count toward its page rank. Since neither George W. Bush nor Michael Moore described himself miserable failure, those links no longer mattered. Santorum, on the other hand, wasn’t so lucky. Why? Because spreadingsantorum.com contains the word ‘santorum.’

So remember, kids. You can still google bomb your worst enemies but you have to be clever about it. I’ll help you out. Here’s the word ‘asshole.’ Now link the word asshole to this page and I’ll soon be the biggest one on the Internets….

 

 

Posted in Community | Leave a comment



Recent Comments

  • Jeff Fulmer: Ten isn’t a large number of concurrent users so you’re probably not opening more connections...
  • Snooops: Hey Guys, im running siege 3.0.9 with: siege -c10 -r once -f urls2.txt -b i get a lot of: [alert] socket:...
  • Oleg: Hm, i have the same problem as “Gokul Muralidharan says: July 27, 2012 at 1:00 pm” He says “I...
  • Jeff: Oleg, Because you told it to run just one repetition: -r1 I think what you’re looking for is...
  • Oleg: I think, i have found one bug. The command siege -d10 -r1 -c25 -f url.txt hits ONLY FIRST url. Why?