title: Run wget and other commands in shell script
body: <p>I'm trying to create a shell script that I will download the latest Atomic gotroot rules to my server, unpack them, copy them to the correct folder, etc., </p>
  
  <p>I've been reading shell tutorials and forum posts for most of the day and the syntax escapes me for some of these. I have run all these commands and I know they work if I manually run them. </p>
  
  <p>I know I need to develop some error checking, but I'm just trying to get the commands to run correctly. The main problem at the moment is the syntax of the wget commands, i've got errors about missing semi-colons, divide by zero, unsupported schemes - I've tried various quoting (single and double) and escaping - / " characters in various combinations.</p>
  
  <p>Thanks for any help.
  The raw wget command is</p>
  
  <p><code>wget --user="jim" --password="xxx-yyy-zzz" "http://updates.atomicorp.com/channels/rules/subscription/VERSION"</code></p>
  
  <pre><code>#!/bin/sh
  update_modsec_rules(){
  
  wget=/usr/bin/wget
  tar=/bin/tar
  apachectl=/usr/bin/apache2ctl
  
  
  TXT="Script Run Finished"
  WORKING_DIR="/var/asl/updates"
  TARGET_DIR="/usr/local/apache/conf/modsec_rules/"
  EXISTING_FILES="/var/asl/updates/modsec/*"
  EXISTING_ARCH="/var/asl/updates/modsec-*"
  WGET_OPTS='--user=jim --password=xxx-yyy-zzz'
  URL_BASE="http://updates.atomicorp.com/channels/rules/subscription"
  
  
  # change to working directory and cleanup any downloaded files and extracted rules in modsec/ directory
  cd $WORKING_DIR
  rm -f $EXISTING_ARCH
  rm -f $EXISTING_FILES
  rm -f VERSION*
  
  # wget to download VERSION file
  $wget ${WGET_OPTS} "${URL_BASE}/VERSION"
  
  # get current MODSEC_VERSION from VERSION file and save as variable
  source VERSION
  TARGET_DATE=$MODSEC_VERSION
  echo $TARGET_DATE
  
  # wget to download current archive
  $wget ${WGET_OPTS} "${URL_BASE}/modsec-${TARGET_DATE}.tar.gz"
  
  # extract archive
  echo "extracting files . . . "
  tar zxvf $WORKING_DIR/modsec-${TARGET_DATE}.tar.gz
  
  echo "copying files . . . "
  cp -uv $EXISTING_FILES $TARGET_DIR
  
  echo $TXT
  }
  
  update_modsec_rules $@ 2&gt;&amp;1 | tee -a /var/asl/modsec_update.log
  
  RESTART_APACHE="/usr/local/cpanel/scripts/restartsrv httpd"
  $RESTART_APACHE
  </code></pre>