Shell Programming

From FamilySearch Wiki
Revision as of 13:53, 16 February 2012 by Cottrells (talk | contribs) (add cat)

Jump to: navigation, search

The shell is Unix-speak for the interface with the operating system. If you connect to your web hosting service using a protocol like telnet or ssh (using a terminal emulation software package like PuTTy) you will be interacting with the shell.

This is not an area for the faint of heart... if your only experience with computers has been with Windows or a Mac you are going to find that blinking dollar sign to be very unhelpful. You can do very powerful things here, but it does require a basic understanding of the file structure, some of the basic shell commands and familiarity with an editor like vi.

Note that many hosting services do not allow access to the shell by default. You may need to contact them and request permission.

Once you have access to the shell you can create files with valid commands in them. One common use is to create backup files.Here is a typical sample presented only to illustrate the basic concepts.

MON=`date | cut -c5-7`
DAY=`date | cut -c9-10`
YR=`date | cut -c25-28`

TIM=`date | cut -c12-19 | sed 's/:/_/g'`
DAT_TIM=`echo $DAY"_"$MON"_"$YR"_"$TIM`

cd /home8/dallasge/public_html
tar --create --gzip --file=$FILENAME Production

After creating and saving this file (say, for example, in a file named DailyBackups) you would tell the shell that it was an executable program my changing the file attributes using the chmod command:

chmod +x DailyBackups

You could then run the file by typing this at the shell prompt (from the same directory):


This would tell the system to run your shell and create a backup file named 29_Jan_2011_01_30_02_public_html_Production.tar.gz

Return to Genealogical Society Webmasters