Well House Consultants
You are on the site of
Well House Consultants
Open Source Training Courses
hotel accommodation. You are welcome to browse and use
our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Well House Manor Resources
Object Orientation and General topics
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
C and C++ Resources
Web and Intranet Resources
Web Application Deployment module A167
Shell Programming (bash)
Exercises, examples and other material relating to training module A167. This topic is presented on public courses Deploying LAMP - Linux, Apache, MySQL, Perl/PHP
, Linux Basics
, Deploying Java Applications on Linux / Unix
|Articles and tips on this subject||updated|
|4587||shell - bash. Writing conditional tests and statements - the options available|
Every language that I teach has conditionals and loops, and the bash shell is no exception. From the three day bash course given last week - an example including lots of alternative tests (but by no means all varlients!
for tests in if
if command ... ; then
The command is run and its ...
|4586||Extending your bash shell with aliases, functions and extra commands|
Want a command to do some composite job, but it doesn't exist? You can add new commands into your bash script using
functions ... see example [here] from last week's course.
aliases ... here are the aliases that I'm using to provide my own extra / modified commands on our web server:
|4584||Bash ... some new scripts to - handling user input|
I just completed a three day "bash shell programming" course and have uploaded a whole host of new examples, and updated some older ones too. Here are some examples that relate to inputting from STDIN ... further links to other groups of new examples to follow
Asking a question and read from STDIN ...
|4487||Starting MySQL. ERROR! The server quit without updating PID file - how we fixed it.|
Our MySQL databases are backed up frequently, and I've arranged for our server to email me in the event of a failure. From our /bin/bash script which is run by crontab:
/usr/local/mysql/bin/mysqldump -ufgw -psummat -h127.0.0.1 fgw > /home/backups/$HOUR/fgw.sql
if [ "$?" -eq ...
|4400||Commenting out an echo killed my bash backup script|
"Commenting out an echo killed my bash script" - yes, really!
Here (with password amended!) is part of my bash script which takes a database snapshot from time to time - and it's been running well over a 24 hour cycle, giving me checkpoints to return to. But it was getting a bit verbose, so I added ...
|3791||The Kernel, Shells and Daemons. Greek Gods in computing|
The Greek Gods didn't like washing up or ironing. So they employed mortals to to it. Problem was that those mortals didn't last for ever, and sometimes went on strike over one thing and another. So The Gods did a deal with some of the current batch of mortals, and it went like this: "We will make you ...
|1904||Ruby, Perl, Linux, MySQL - some training notes|
We have just come to the end of a solid 12 days of training ... and we are just getting ready for the next week, with delegates arriving this evening. There's a lot going on behind the scenes, even over this weekend, with the hotel to be prepared as well as the training course. (Picture - our clean ...
|1527||Selecting file names in a shell - one word or another|
If you want to select all file names that include the words "cat" or "dog" in them with file name matching, you can do so using curly braces - that's supported by most modern shells as part of what is known as "globbing".
Here's an example - I've just been copying images off my digital camera and I ...
|1468||Lexical v Arithemetic testing, Bash and Perl|
If you tell a story against someone, best to be telling it against yourself!
One of our web servers (running standard, not our own software behind the scenes) has been having a problem with handling denial of service attacks which are coming in from time to time ... and I have a monitoring script running ...
|1345||Perl and Shell coding standards / costs of an IT project|
There are three major staff costs in the life of an IT project - the specification and development of the system, the maintainance and upgrading of the system though its life, and the investment that's made in data entry and integrity through the life of the system. And although there's a lot of thought ...
|1287||Work and play at Well House Manor - Football and Shell Shortcuts|
We're running a Linux and LAMP course this week - great group and I'm going to be sorry when it's the end of the course.
Yesterday we had a cold buffet lunch for a change, and made the best of the lovely weather and spacious garden to relax for a while - we do a long day, and so a good break at lunch ...
|827||No news is good news with Unix and Linux|
No news is good news ... so says Linux and Unix. All processes return a status code, and you can expect that to be:
0 - success
1 - failure
2 - abject failure
So, for example, the grep utility returns a status as follows:
0 - found what you were looking for!
|749||Cottage industry or production line data handling methods|
If you're running a cottage industry, for efficiency's sake you'll run the first process on each of your raw components first, and store the partially-completed elements in a basket as they're processed. When you've completed that first process, you'll then apply the second process to each element ...
|64||Shell Script for CGI on the web|
In the course of duty (providing simple "how-to" examples), I've come up with a short shell script in the Bourne again shell that allows a rudimentary lookup in a data file on a server running CGI. Nothing special about this, except it's a short example.
Run it from this link and try putting in data ...
Examples from our training material
|another|| Shell read from stdin up to next new line|
|askuser|| select - choose from stdin|
|datcopy|| Simple copy script to run from command line|
|dc4|| Data copy, loop to copy files one by one, checking |
|dc5|| Data copy, calculating statistics |
|dc_checked|| Data copy with conditional check |
|dci|| Data copy, use of shell variables |
|dcif|| Data copy, use of shell if statement |
|dcj|| Data copy, with command line parameter |
|eocl|| Usage line and for loop - bash|
|fnk|| function definition and use|
|help|| Towards bash scripting - series of commands|
|lookup.sh|| Bourne Again Shell script for CGI Web server |
|pex|| textual manipulation of shell variables|
|shelc|| Shell numric and string comparisons. Also backup script|
|skcount|| Skill counter - sample script in alternative Perl language |
|skillcounter|| Perl script - needs setting up to run as Linux command |
|wont|| Stopping ^C in a shell using trap|
|yesterday|| yesterday in a bash script|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
What is shell programming?
Running a shell program from the command line
Conditional statements and variables.
Shell comparisons and arithmentic.
Functions and other features.
Bourne Again Shell scripts on a web page.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
Linux and LAMP
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.