Sam Gleske on 27 Apr 2012 05:44:49 -0700

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] First shell script for deployment...

I found this discussion helpful.  There are somethings I noticed but for the most part but Bergman covered them.  Another good thing to add to the comments is your kernel and environment information to the comments depending.  This is relatively easy to do if you're using vim, not sure how to do it in emacs.

:r!uname -a
:r!bash --version

And if you're calling a python script or it is a python script then list the version of the interpreter you're using
:r!python --version

Rather than using cd at the beginning of the script I prefer to specify a base source and destination working directory in full paths at the beginning and use variables.  e.g.

And then doing all of the commands in order.

if [ ! -d "$src" ];then
    mkdir "$src"
    # I enjoy reusing other peoples functions
    checkandexit 1 "public_html_deploy1 already exists so the last run must have failed."

If you've never seen dst=${dst:-/home/sam/public_html} a variable assigned like that before then read the bash man page and search for Parameter Expansion.  The advantage of setting it that way is you can do things like this outside the script...
export src="" myscript

And your script will take that new value.

Another advantage to using variables like that is when you mkdir "$src" at the beginning of your script you're less likely to make a critical error like you did at the end when you rm -rf "$src".

A lot of that is my style as a programmer too.

Philadelphia Linux Users Group         --
Announcements -
General Discussion  --