Archiving command history in Linux

#!/bin/bash
 umask 077
 max_lines=10000
 linecount=$(wc -l < ~/.bash_history)
 if (($linecount > $max_lines)); then
         prune_lines=$(($linecount - $max_lines))
         head -$prune_lines ~/.bash_history >> ~/.bash_history.archive \
                && sed -e "1,${prune_lines}d"  ~/.bash_history > ~/.bash_history.tmp$$ \
                && mv ~/.bash_history.tmp$$ ~/.bash_history
 fi

via BashFAQ/088 – Greg’s Wiki.

I needed to manage shell command history in a formal fashion in order to turn repeated sequences into scripts without having to type them in again.  I also wanted a  record of packages installed and in what order.   The history of commands is contained in .bash_history file which is read once when a terminal opens.   Running set -o vi allows for history commands to be recalled using standard vi commands.  The above script can be run as a user level cron job to periodically prune the top so many commands and place them into an archive.

The bash statements below set history size and make it so a command will be written to the history file immediately and not simply when a terminal closes.   These should be placed in .bashrc or whatever file executes when a new terminal opens.

HISTFILESIZE=400000000
HISTSIZE=10000
PROMPT_COMMAND="history -a"
export HISTSIZE PROMPT_COMMAND

shopt -s histappend

The Internet Dodges Another Bullet With Wget Flaw

“It was found that wget was susceptible to a symlink attack which could create arbitrary files, directories or symbolic links and set their permissions when retrieving a directory recursively through FTP,” developer Vasyl Kaigorodov wrote in a Red Hat Bugzilla comment. –

via The Internet Dodges Another Bullet With Wget Flaw.

Wget is a linux command that allows a shell script to download a web page and store it to a file.  This bug pertains to using a URL to do File Transfer Protocol (FTP) and not HTTP which is what wget was designed for.  Here are a couple more snippets of this bug.

“Random bug found by accident, but the implication is that the FTP server can overwrite your entire filesystem,” Moore tweeted to eWEEK.

Don’t use wget for ftp.  Don’t run wget with root permissions.

So just to recap here, Wget is on nearly every Linux server in the world, and it had a flaw that could have enabled anyone to overwrite directories on a server. That’s very serious.

You should only use wget for http downloads.  This doesn’t sound like one of those Internet Dodges a Bullet problems.

Things You Should Never Do, Part I – Joel on Software

There’s a subtle reason that programmers always want to throw away the code and start over. The reason is that they think the old code is a mess. And here is the interesting observation: they are probably wrong. The reason that they think the old code is a mess is because of a cardinal, fundamental law of programming:

It’s harder to read code than to write it.

via Things You Should Never Do, Part I – Joel on Software.

Each of these bugs took weeks of real-world usage before they were found. The programmer might have spent a couple of days reproducing the bug in the lab and fixing it. If it’s like a lot of bugs, the fix might be one line of code, or it might even be a couple of characters, but a lot of work and time went into those two characters.

When you throw away code and start from scratch, you are throwing away all that knowledge. All those collected bug fixes. Years of programming work.

The Soaring Financial Cost of Blocking Pirate Sites

But these 36 new sites to be blocked on copyright grounds are potentially just the tip of a quite enormous iceberg now that blocking on trademark grounds is being permitted.

Richemont has identified approximately 239,000 sites potentially infringing on their trademarks, 46,000 of which have been confirmed as infringing and are waiting for enforcement action.

via The Soaring Financial Cost of Blocking Pirate Sites | TorrentFreak.

IBM Is Not A Tech Company

IBM’s revenues are declining because there’s a big shift going on in the way companies are buying tech. Instead of buying their own software and hardware for their own data centers, then hiring expensive consultants to stitch it all together, they are renting that technology, which is often hosted elsewhere. That’s called “cloud computing.”

All the big tech firms are shifting from the old way of selling stuff to this new way with varying degrees of success: SAP, Oracle, Microsoft, Dell, HP and IBM are all getting into the cloud.

via Mark Cuban: IBM Is Not A Tech Company – Business Insider.

Researchers Find Malicious Tor Exit Node Adding Malware to Binaries

The exit node in question was in Russia, and Pitts discovered that the node was actively patching any binaries he downloaded with a piece of malware. He downloaded binaries from a variety of sources, including Microsoft.com, and each of them came loaded with malicious code that opens a port to listen for commands and starts sending HTTP requests to a remote server.

via Researchers Finds Malicious Tor Exit Node Adding Malware to Binaries | Threatpost | The first stop for security news.

From: The Case of the Modified Binaries

Companies and developers need to make the conscious decision to host binaries via SSL/TLS, whether or not the binaries are signed. All people, but especially those in countries hostile to “Internet freedom,” as well as those using Tor anywhere, should be wary of downloading binaries hosted in the clear—and all users should have a way of checking hashes and signatures out of band prior to executing the binary.

The Horror of a ‘Secure Golden Key’

A “golden key” is just another, more pleasant, word for a backdoor—something that allows people access to your data without going through you directly. This backdoor would, by design, allow Apple and Google to view your password-protected files if they received a subpoena or some other government directive. You’d pick your own password for when you needed your data, but the companies would also get one, of their choosing. With it, they could open any of your docs: your photos, your messages, your diary, whatever.

via The Horror of a ‘Secure Golden Key’.

How a dumb software glitch kept thousands from reaching 911

At first, Intrado thought that the complaints arising from various PSAPs around the country were just isolated, unconnected events — even though alarm bells were going off an hour into the breakdown. Nobody noticed the warnings until it was too late; the server taking note of the alerts categorized them as “low level” incidents and were never flagged for a human, according to the FCC report.

via How a dumb software glitch kept thousands from reaching 911 – The Washington Post.

PSAP = Poor Sucker At Phone

Remove duplicates without sorting file

Usually whenever we have to remove duplicate entries from a file, we do a sort of the entries and then eliminate the duplicates using “uniq” command.

But if we have to remove the duplicates and preserve the same order of occurrence of the entries, here is the way:

via UNIX Command Line: Remove duplicates without sorting file – BASH.

$ awk ‘ !x[$0]++’ file3

From: Unix: removing duplicate lines without sorting

This command is simply telling awk which lines to print. The variable $0 holds the entire contents of a line and square brackets are array access. So, for each line of the file, the node of the array named x is incremented and the line printed if the content of that node was not (!) previously set.

MegaBots At New York Comic Con

The team hopes one day fans will root for bots the way they do for racing’s Jeff Gordon, ultimate fighting’s Ronda Rousey, and boxing’s Floyd Mayweather, Jr.

via MegaBots At New York Comic Con – Business Insider.

In a MegaBots battle, a two-member team sits inside the bot’s upper torso, where the controls systems are housed. Although the co-founders assure me that the pilot and gunner are well protected inside, the situation presents a heightened suspense.

Each 15,000-pound robot is equipped with six-inch cannons inside its arms that fire paint-filled missiles and cannon balls at 120 miles per hour. Good aim can cause enough damage to jam its opponent’s weapons system or shoot of a limb. “These aren’t Rock ‘Em Sock ‘Em Robots,” Stroup laughs.