?
Solved

Need help with a shell script - FTP related

Posted on 2003-03-07
3
Medium Priority
?
450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 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