?
Solved

Need help with a shell script - FTP related

Posted on 2003-03-07
3
Medium Priority
?
467 Views
Last Modified: 2010-04-21
Here's my script, and here is the problem - the script is supposed to re-submit whatever is still missing (it could be 1 to 3 files). Currently the script is not working properly. In a few occasions when more than 1 edi files were missing, the scripts only managed to re-submit ONE file. What I would like to do is capture all the files (up to 3) when necessary. I need an explanation as to why this does not work and a solution to correct this problem. Don't worry about the path's names or passwords too much they have been edited.

myname=`basename $0`
mydate=`date +%Y%m%d`
#
ERROR_DIR=/tmp
#
if [ $# -eq 0 ]; then
     SEND_HOST=192.168.106.12
     SEND_USER=whatever
     SEND_PASS=secret
     SEND_DEST=/
     DOWNDIR=/outbound
     RETRDIR=/retrieve
     echo "$mydate `date +%T`:**Processing for Primary System $OBJECT "
else
     SEND_HOST=192.168.106.11
     SEND_USER=whatever
     SEND_PASS=secret
     SEND_DEST=/
     DOWNDIR=/outbound
     RETRDIR=/retrieve
     echo "$mydate `date +%T`:**Processing for Alternate System $OBJECT "
fi
#
ARCHIVEDIR=/processed
SYSDIR=/
ETCDIR=$SYSDIR/etc
# USERS=`cat $ETCDIR/Mail.notify`
#
shdirname()
{
expr \
  ${1-.}'/' : '\(/\)[^/]*//*$' \
  \| ${1-.}'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \
  \| .
}
#
# Procedure used to send files
#
ftpfile()
{
#
echo "$mydate `date +%T`:$OBJECT:**Processing - Sending $OBJECT.req "
#
cp $RETRDIR/$OBJECT.edi $DOWNDIR/$OBJECT.req
#
/usr/bin/ftp -vin >$ERROR_DIR/$OBJECT.put.summary.$$ 2> /$ERROR_DIR/$OBJECT.put.ERRORS.$$ <<EOF
open $SEND_HOST
user $SEND_USER $SEND_PASS
binary
cd $SEND_DEST
put $OBJECT.req
bye
EOF
}
#
# Procedure may be used to check errors
#
ftpcheck()
{
WARNINGS=`grep '226 Transfer' /tmp/$OBJECT.put.summary.$$ | wc -l`
if [ "$WARNINGS" -ne 1 ]; then
    echo "$mydate `date +%T`:$OBJECT:**Ftp has encountered error.. Check $OBJECT.put.summary.$$"
fi
}
#
# Housekeeping...
#
housekeep()
{
#
echo "$mydate `date +%T`:$OBJECT:**Removing $OBJECT .."
#
rm $DOWNDIR/$OBJECT.[Rr][Ee][Qq]
#
}
#
# Script stuff starts here....
#
echo "$mydate `date +%T`:**Starts .."
#
cd $RETRDIR
OBJECTS=`ls *.edi 2>/dev/null | awk -F\. '{ print $1 }' | sort -u | awk '{ printf " %s", $1 }'`
#
# anything to do ?
#
echo "$mydate `date +%T`:**Scanning for Files To Re-Send.."

if [ -z "$OBJECTS" ]; then
      echo "$mydate `date +%T`:**No Files To Re-Send Ending..."
      exit 1
fi
#
# walk the directory process available files....
#
for OBJECT in $OBJECTS;
    do
    TARGETS=`ls $OBJECT*`
    cd $DOWNDIR
    if [ ! -z "$TARGETS" ]; then
       for TARGET in $TARGETS;
           do
             echo "$mydate `date +%T`:$OBJECT:**Processing File:$TARGET ..."
             if [ "$TARGET" = "$OBJECT.ack" -o "$TARGET" = "$OBJECT.ACK" ]; then
                  echo "$mydate `date +%T`:$OBJECT:**Creating Retrieval Entry for File:$OBJECT.ACK ..."
                  touch $RETRDIR/$OBJECT.ACK
                  mv $TARGET $ARCHIVEDIR/$TARGET.$$
             else
                  ftpfile
                  ftpcheck
                  housekeep
             fi
           done
    fi
    done
#
0
Comment
Question by:stevesm
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
bira earned 600 total points
ID: 8089884
Hi
   The problem seems to be the declaration of the
    variable TARGETS as below:
 
         TARGETS=`ls $OBJECT*`

      You should replace by  
       
          TARGETS=$OBJECT
0
 
LVL 1

Author Comment

by:stevesm
ID: 8090441
I need to test this and let you know.
Cheers
0
 
LVL 1

Author Comment

by:stevesm
ID: 8248850
My apologies for taking so long to get back, no excuses. I changed the variable as you mentioned and it worked like a charm.


Thanks for your help
Steve
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question