Bash'isms

There are probably a million better ways to do these, but these are tricks that I keep using (I'm well on my way to becoming an old crusty unix guy :-( )

bash'isms

I find this really useful, just a call out to sed so I don't have to remember the syntax.

It came up twice that I had to do this, so I decided to see if I could make something simple that solved my problem. I'm sure there's a project to do this already, but here goes. I have a list of machines, I want to see if they respond to a ping so I can determine if they are up or not.

It sometimes comes up that the usual trick of reading in a stream with a pipe and a while loop doesn't work, since the pipe causes a subshell and any variables set in the subshell are unavailable to the parent.
For example the normal trick (output the first few lines of the /etc/services file, just the first two columns and not empty or comment lines):

[uphill@zagreb]: grep -v ^# /etc/services | grep -v ^$ | head | awk '{print $1" "$2;}'
tcpmux 1/tcp
tcpmux 1/udp
rje 5/tcp
rje 5/udp
echo 7/tcp
echo 7/udp
discard 9/tcp
discard 9/udp
systat 11/tcp
systat 11/udp
[u

Sometimes it's easier to write a quick script in bash that uses arrays rather than figure out how to do it with something more appropriate like awk or perl.

It's really very quick and simple. To start, declare your variable as an array

[uphill@host]: declare -a myvar

If the array is going to be global then add x to export it.

 

Note: this is super old, use puppet instead these days...

 

Script: update_machine update_file
We use this simple script (no error checking as usual) to update our machine configuration.
We keep the configuration files in cvs and download them to a new machine.