bash

warning: Creating default object from empty value in /hermes/walnaweb12a/b57/moo.greydragoncom/nodsw/modules/taxonomy/taxonomy.pages.inc on line 33.
Leeland's picture

Shell Scripts That In-Line Java

Sometimes the simplest things get overlooked. There are many times where I need to do something a little cross system languages. For example dynamically deciding on the right arguments to feed to a Java tool or service JVM. Or when I need to do some undirected graph manipulations of data from PowerShell or bash. There is no reason to not step up to the higher level language to get the job done.

Leeland's picture

All of bash history revisited: load time solved plus directory history

Imagine logging into a box after a nice long three day weekend and asking yourself "self, what was I doing last Thursday?" or "what did I do on this server when I was here nearly a month ago?" What if you could answer that in such detail as what you did, where you were when you did it and you could get back there with only a few key strokes? Check this out (opening a new ssh session to my production box I haven't been on for weeks):
Using username "a-lartra".
Authenticating with public key "imported-openssh-key" from agent
  
Leeland's picture

All of bash history forever and across multiple sessions

The last terminal to exit wins the "who's history is saved" game. Unless you pull a cute Linux stunt or three.

Update: A better solution is now available All bash history revisited: Load time solved PLUS directory history

Leeland's picture

Keeping SSH Sessions Alive NATs & Firewalls

Working often requires opening terminal sessions or VPN connections. It can be very annoying when these connections fail after being left idle for a few minutes, or with VPNs in the middle of a work day in spite of traffic. In regard to SSH connections many people (even many experts) incorrectly assume that the SSH server (sshd) has some restrictive session auto-timeout setting. If you look carefully at the manual for sshd configuration (man sshd_config) you will see that there is not even a setting to enable a session timeout behavior.

Leeland's picture

SSH vs. nohup and hung jobs

Every 6 months or so I have some little loop I wrote to run a process on a long list of servers sit and hang forever by waiting for the nohup background process to end before moving on to the next host. Naturally I come back after getting lunch expecting all the boxes to be busily humming away to find 3 have finished and the 4th is still running. This of course causes me to remember that ssh hangs on processes even if they are pushed off to the background with a nohup.

Leeland's picture

Script Based Unit Testing

== ShUnit ==

:Target: All POSIX (Linux/BSD/UNIX-like OSes)
:URL: http://shunit.sourceforge.net/
:Latest Version: 1.3 (15 Jan 2005)

:A unit testing framework for the Bourne shell family of shells modeled after JUnit. This has not been updated since 2005 and I think the project is defunct.

== shUnit2 ==

:Target: All POSIX (Linux/BSD/UNIX-like OSes)
:Latest Version: 2.1.1 (13 Jul 2007)
:URL: http://shunit2.sourceforge.net/
:Documentation: http://shunit2.svn.sourceforge.net/svnroot/shunit2/trunk/source/2.1/doc/...

Leeland's picture

BASH magic

== Table of Contents ==

__TOC__

== My .bashrc.user file right now ==
:

export SVN_EDITOR=/usr/bin/vim

# make bash autocomplete with up arrow
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'

# a simple function that will check for headers of HTTP server.
#
# invoke: headers  []
#                 port number defaults to 80 if not provided.
headers() {
    server=$1; port=${2:-80}
    exec 5<> /dev/tcp/$server/$port
    echo -e "HEAD / HTTP/1.0\nHost: ${server}\n\n" >&5
    cat <5
    exec 5<&-
}
Leeland's picture

SED Recursive Search and Replace With Multiple Actions

About once every 6 months or so I end up needing to do a recursive search and replace across a whole bunch of files. Every time I need to do this I turn to SED as it is just so good at doing the work. But of course there is the problem of multiple actions.

The secret to this is using the SED file. This works across thousands of files on the local box and even more interestingly can be wrapped in a SSH script to walk hundreds of remote boxes.

Thread Slivers eBook at Amazon

Syndicate content