A web development/programming blog providing info, tips, and tricks on programming languages, scripting, Linux, MySQL and more
Posts tagged bash
How to append values to an array in bash
Feb 4th
Last week I was working on a bash script for a project at work. The script parsed through a log file with server load and disk usage statistics at regular intervals. The script was calculating the average CPU idle time, disk utilization, and disk usage for servers. After calculating the averages for each of these three metrics, I then proceeded to loop through all the lines in the file and create an array of all the times when the CPU idle time was below average, or the disk utilization or usage was above average.
Read the rest of this entry »
bash Scripting Cheat Sheet
Jun 28th
- If...then
- if [ expression ]
then
commands
fi - If..then...else
- if [ expression ]
then
commands
else
commands
fi - If..then...else If...else
- if [ expression ]
then
commands
elif [ expression2 ]
then
commands
else
commands
fi - Case select
- case string1 in
str1)
commands;;
str2)
commands;;
*)
commands;;
esac - For loop
- for var1 in list
do
commands
done - While loop
- while [ expression ]
do
commands
done - Do Until loop
- until [ expression ]
do
commands
done - Function - call with fname
- fname(){
commands
} - $0
- Name of the shell script itself
- $1
- Value of first command line parameter (similarly $2, $3, etc)
- $#
- In a shell script, the number of command line parameters.
- $*
- All of the command line parameters.
- varname=value
- Create a variable named varname with a value of value
Shell Scripts
Jun 19th
This page will house the Shell Scripts that I have developed. Shell scripts are run from a Linux Command-line or SSH interface.
Post to Twitter
Update your Twitter account from the shell
How to Post to Twitter from a Linux Shell
Jun 18th
I had a little downtime today and work and decided to write a shell script that I could use to tweet from the shell of my Linux server. The reason is that Twitter is one of many social networking sites that is blocked at my workplace. However, I do have access to my server and found a great one-liner on commandlinefu.com to update twitter via curl. I decided to expand on this a bit and wrote a shell script that offers a bit more than merely posting a tweet. Check out my shell script to post to Twitter here.
Linux Command-Line Cheat Sheet Posted
May 18th
I have posted today my Linux Command-Line Cheat Sheet. Unlike other Linux Cheat Sheets I have seen, I have created this one as more of a “targeted” cheat sheet. Instead of just containing various command-line commands, my cheat sheet focuses on providing tips/tricks for various Linux commands including common switches and options used with those commands, including grep, sed, find, tar, rpm, and more.
I have also included numerous shortcuts/key combinations for the vi/vim text editor. This may turn into it’s own cheat sheet in the near future if I continue to add to it due to the amount of info I have for vi alone. Time will tell.
Read the rest of this entry »

