My Recent Shell Scripting Posted by: John in Linux on
Recently I have been working on some shell scripts to aid in the installation of applications. One of the scripts I have been working on is a LAMP (linux, apache, mysql, and php) installer. For almost two years I ran a local WAMP server (same as LAMP but the operating system is Windows) which was installed by clicking some executable (XAMPP / VertigoServ). However, Linux shows no sympathy for lazy Windows users, and thus forces us to use a restrictive package manager or install form source. Moreover, since I often need to recompile php to add new modules, I have decided to make my own LAMP installer. Below are some snippets of code that I have so far found useful in my shell script.
 
Determine if a user is root:

 
  1. if [ "$(whoami)" != "root" ]; then  
  2.     echo "Sorry, you are not root."  
  3.     exit 1  
  4. fi

 
Determine if a directory exists:

 
  1. if [ ! -e /usr/local/src ]; then  
  2.      mkdir /usr/local/src  
  3. fi

 
Pass arguments to the shell script:

 
  1. if [ "$1" == "apache" ]; then  
  2.     apache  
  3. elif [ "$1" == "php" ]; then  
  4.     php  
  5. else  
  6.     apache  
  7.     php  
  8. fi

 
john@pluto:~#./myscript php

Here you are passing the script the argument “php.” This would cause the script to only run the php function.
Trackback(0)
feed0 Comments

Write comment
 
 
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger
 

security image
Write the displayed characters


busy