An example of a shell script from UMBC that I wrote. I have removed identifying / security risk information. Basically the script finds a dir with todays date contained in it, and then is able to download files from two directories with todays date in them.


# filename = collegenet_download.sh
# usage:  sh collegenet_download.sh
# Initialization variables FIXME find better way of storing password 
TODAYSDATE=$(date '+%y%m%d')
# Show todays date for logging purposes
echo "====== SCRIPT RUN ON ======"
echo $(date)
echo -e "====== SCRIPT RUN ON ======\n\n"
# FIXME Take into account that there may not be a date directory for all instances that this is run
# Get long and medium date/dir/file names from todays date 
# this is needed because each date/file name provided by collegenet includes hours, minutes
# and seconds in the file/dir name. We cannot exactly predict these numbers, as they differ
# slightly each time. So, we use todays date, to find out what the full file names truly are, 
# then use these full file names later throughout the script.
# We have to do this two times, because there is a slightly different run date, and therefore
# different file names for the archived dir (which contains PDFs) vs the data files 
for file in `wget -O - -nd -q -r --user=$USERNAME --password=$PASSWORD 'https://admin.applyweb.com/ft/client?action=ls&dir=GradPDFs/archive&mode=text&filetype=all'` ;
  # if archive directory name equals todays date, set date/dir name to the found directory's name
  if [ ${file:0:6} = $TODAYSDATE ]; then # dir is of format YYMMDDhhmmss , so the substring 0:6 gives YYMMDD 
    echo "====== FOUND TODAYS DATE DIRECTORY ======"
    echo $file
    echo -e "====== FOUND TODAYS DATE DIRECTORY ======\n\n"
for file in `wget -O - -nd -q -r --user=$USERNAME --password=$PASSWORD 'https://admin.applyweb.com/ft/client?action=ls&dir=UMBCG-DataFiles&mode=text&filetype=all'` ;
  # if datafile name contains todays date, set file postfix name to the found file's name
  if [ ${file:7:6} = $TODAYSDATE ]; then
    echo "====== FOUND TODAYS DATE FILE POSTFIX ======" 
    echo ${file:5:14} # file is of format UMBCGYYYYMMDDhhmmss.psv , so the substring 5:14 gives YYYYMMDDhhmmss
    echo -e "====== FOUND TODAYS DATE FILE POSTFIX ======\n\n"
# initialization, get to working dir and make new archive dir
cd /var/blah/cnettesting
mkdir $DateDirName
# FIXME get files onto UMBC Active Directory share
# get todays archive-directory PDF files 
echo "====== PDFs ======"
for file in `wget -O - -nd -r --user=$USERNAME --password=$PASSWORD ' https://admin.applyweb.com/ft/client?action=ls&dir=GradPDFs/archive/'$DateDirName'&mode=text&filetype=file'`;
  do wget -nd -q -O ./$DateDirName/$file --user=$USERNAME --password=$PASSWORD 'https://admin.applyweb.com/ft/client?action=get&dir=GradPDFs/archive/'$DateDirName'&filename='$file ;
echo -e "====== PDFs ======\n\n"
# get todays SISIMPRT file
echo "====== SISIMPRT file ======"
wget -nd -O ./SISIMPORT/SISIMPRT$DateFilePostfix.psv --user=$USERNAME --password=$PASSWORD 'https://admin.applyweb.com/ft/client?action=get&dir=UMBCG-DataFiles&filename=SISIMPRT'$DateFilePostfix'.psv '
echo -e "====== SISIMPRT file ======\n\n"
# get todays UMBCG file
echo "====== UMBCG file ======"
wget -nd -O ./UMBCG$DateFilePostfix.psv --user=$USERNAME --password=$PASSWORD 'https://admin.applyweb.com/ft/client?action=get&dir=UMBCG-DataFiles&filename=UMBCG'$DateFilePostfix'.psv '
echo -e "====== UMBCG file ======\n\n"
technology/unix/shell_scripting.txt · Last modified: 01.19.2009 03:00 by
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki