programming

4

Shelling scripting is a necessary skill

http://bashcurescancer.com

Yesterday a 20 line shell script caught a race condition in one of software I work on. Our best engineers looked at the problem, a vendor case was filed, and there was thoughts of automatically restarted the application to fix the issue at hand.

In the end, a 20 line shell script to strace for file operations continuously provided the needed visibility into the issue at hand.

Update: The shell script.

The shell script itself, though trivial, is owned by the company I work for, but the basic concept was as follows:

#!/bin/bash


Read more »
Created by greenx 1 year 46 weeks ago – Made popular 1 year 46 weeks ago
Category: Tech   Tags:
2

Temporarily Clearing Environment Variables

http://bashcurescancer.com

After a long break I have some more ideas…. Will be posting them soon. For now, I leave you with a command to clear your current environment:

root@67 [~]# printenv | wc -l
26
root@67 [~]# env -i printenv | wc -l
0

This is very useful when you want to run a command ignoring any environment variables you have set. I use this command with curl nearly everyday to ignore the http_proxy environment variable I have set. Another, longer, option is:

root@67 [~]# http_proxy="" curl ....

I prefer env -i as its simpler.


Read more »
Created by uioloio 1 year 51 weeks ago – Made popular 1 year 51 weeks ago
Category: Tech   Tags:
31

Reading a file, line by line

http://bashcurescancer.com

nixcraft has a link on how to read a file line by line. The method is a great way to read a file, but there some trouble spots I thought I would point out.

In the script, the special variable IFS is set:

# set the Internal Field Separator to a pipe symbol
IFS='|'

The tells the read command to split “cyberciti.biz|74.86.48.99″ into “cyberciti.biz” and “74.86.48.99″ and thus fill both the domain and ip variables here:


Read more »
Created by shankar 1 year 51 weeks ago – Made popular 1 year 51 weeks ago
Category: Tech   Tags:
4

Splitting Strings Natively with the Shell: Native vs Native

http://bashcurescancer.com

Splitting Strings Natively with the Shell: Native vs Native

In my previous post on why to split strings with bash itself, I used set to split the string.


Read more »
Created by mr-Z 1 year 51 weeks ago – Made popular 1 year 51 weeks ago
Category: Tech   Tags:
28

Splitting Strings Natively with the Shell: Why

http://bashcurescancer.com

Today I want to discuss splitting strings into tokens or “words”. I previously discussed how to do this with the IFS variable and promised a more in depth discussion. Today, I will make the case on WHY to use IFS to split strings as opposed to using a subshell combined with awk or cut.


Read more »
Created by admin 1 year 51 weeks ago – Made popular 1 year 51 weeks ago
Category: Tech   Tags: