Re: FTP: 421 Service not available....



Could be time sensitivity on the ftp server.
Or environment dependencies in your script. cron jobs get a much smaller
set of env vars than do interactive jobs.
Try cron for 8:35 to tell for sure.
Check your scripts for env dependencies.
Post your script for further input.- Hide quoted text -

- Show quoted text -

OK, so here is my script that runs from the crontab. This script calls
another one (x.putcook) also posted below:

#!/bin/ksh

# Extract Cook orders that have been staged and send them to company

############################### CHANGE HISTORY
################################
# 06/14/07 Adapted to run properly on Linux.
# 01/10/07 Added logging.
# 11/12/04 Original version?
###############################################################################

function usage {
print "\nUsage: $Prog [ <date> [ <database> ] ]" >&2
print "\t<date> - Date to extract as mm/dd/yy. Default is current
date." >&2
print "\t<database> - Name of the database to use. Default is
$DB." >&2
print "\nExample:" >&2
print "\t$Prog 01/05/07 tfhtst" >&2
print "\nExtract for Jan 5, 2007 using database tfhtst." >&2
print "" >&2
}

# Parm 1 = Date in the form MM/DD/YY
# Parm 2 = (optional) tfhtst (If you want to use the test database)
# ex: x.autoextract 03/01/04 tfhtst
# RUNNING WITH NO PARMS WILL EXTRACT FOR TODAY AND tfhbiz
# Setting some env vars...

# Log an event with date and time. Variable $LOG specifies the log
file.
function logit {
if [[ $1 = '-' ]]
then
shift
else
print -- "$@" >&2
fi
print "$( date +'%Y-%m-%d %T' ) $@" >>$LOG
}

# Trap various errors
function irupt {
case $1 in
1 ) logit "1. Disconnect"
trap "" 1
;;
2 ) logit "2. Interrupt by user"
trap "" 2
;;
15 )
logit "15. Operator (root) kill."
trap "" 15
;;
* ) logit "$1. Unrecognized interrupt."
trap "" $1
;;
esac
exitfunc $1
}

function exitfunc {
logit "End $Prog, Status $1, $NERR errors."
rm -f $ERRTMP
exit $1
}

# ############################### START MAIN
##################################

Prog=$( basename $0 )
Pname=$( basename $0 .sh )

ExtDir=/export/extracts/cook # Location of extract file.
DB=tfhbiz # Default database.
ERRTMP=/tmp/$Pname.err # Temp file for error output.
LOG=/var/local/log/$Pname.log # Log file
let NERR=0 # Number of errors
encountered.


print "" >&2
if [[ $1 = '--' ]]
then
print "Extract order for company, and send them to company's
computer." >&2
usage
exit 0
fi

# Trap various errors.
trap "irupt 1" 1
trap "irupt 2" 2
trap "irupt 15" 15

DTG=$( date +'%m/%d/%y' ) # The current date.
print "" >>$LOG # Put blank line in the log.
logit "Begin $Prog $@"

# Set some environment variables, if needed.
if [[ -z ${INFORMIXSERVER:-''} ]]
then
logit "Setting Informix environment."
. /etc/hudgins1.profile # Set the Informix environment
fi
if [[ -z ${fg:-''} ]]
then
logit "Setting FG environment."
. /etc/fg.profile # Set the FG environment
fi

DT=${1:-$DTG} # Get date argument, if any.
DB=${2:-$DB} # Get 2nd argument, if any.

case $DB in
tfhtst )
CookDir=/m1/fourgen/accounting/oe.4gm/x_cook.tst
;;
tfhbiz )
CookDir=/m1/fourgen/accounting/oe.4gm/x_cook.tfh
;;
* ) print "**** Unrecognized database \"$DB\"." >&2
(( NERR += 1 ))
;;
esac

if [[ $NERR -ne 0 ]]
then
usage
exitfunc 17
fi

mm=$( print ${DT}|cut -c1-2 )
dd=$( print ${DT}|cut -c4-5 )
yy=$( print ${DT}|cut -c7-8 )
FileDate=${yy}${mm}${dd} # Date stamp
FileName=TFH$FileDate.txt # Extract file name.

# moving to the working directory...
cd $CookDir
logit "Running company Auto-Extract for $DT using $DB."
sleep 3
fglgo ./x_cook.4gi AUTOEXTRACT DB=$DB PRIN=C DATE=$DT >$ERRTMP 2>&1
let es=$?
if [[ $es -eq 0 && -s $ExtDir/$FileName ]]
then
let NL=$( cat $ExtDir/$FileName | wc -l )
let NL=$NL-1
logit "Successfully extracted $NL orders."
else
logit "**** Problem running x_cook.4gi [$es]."
(( NERR += 1 ))
let es=$es+16
exitfunc $es
fi

chmod 664 $ExtDir/$FileName
logit "Transferring orders to company for $DTG."
sleep 3
/usr/local/bin/x.putcook $FileDate >$ERRTMP 2>&1
let ES=$?
if [[ $ES -eq 0 ]]
then
logit "Successfully transferred extracted orders to company."
else
logit "**** Problem transferring orders to company [$ES]."
(( NERR += 1 ))
fi

exitfunc $ES

x.putcook <================this script starts here

#!/bin/ksh

# Send Extracts to the company computer.

################################## CHANGE HISTORY
#############################
# 06/14/07 Adapted to run under Linux.
# 02/28/07 Fix typo in function stmt. Add usage function.
# 03/12/04 Original version.
###############################################################################

function usage {
print "\nUsage: $Prog <date>" >&2
print "\t<date> - Date for file in the form yymmdd." >&2
print "" >&2
}

# Parm 1 = YYMMDD file name
# x.putcook `date +%y%m%d`

function logit {
if [[ $1 = '-' ]]
then
shift
else
print -- "$@" >&2
fi
print "$( date +'%Y-%m-%d %T' ) $@" >>$LOG
}

# Trap various errors
function irupt {
case $1 in
1 ) logit "1. Disconnect"
trap "" 1
;;
2 ) logit "2. Interrupt by user"
trap "" 2
;;
15 )
logit "15. Operator (root) kill."
trap "" 15
;;
* ) logit "$1. Unrecognized interrupt."
trap "" $1

;;
esac
exitfunc $1
}

function exitfunc {
logit "End $Prog, Status $1, $NERR errors."
rm -f $ERRTMP
exit $1
}

################################## START MAIN
###############################

Prog=$( basename $0 ) # Program name.
Pname=$( basename $0 .sh ) # Program name w/o .sh extension,
if any.

ERRTMP=/tmp/$Pname.err # Temp file for error output.
LOG=/var/local/log/$Pname.log # Log file
let NERR=0 # Number of errors encountered

if [[ $1 = '--' ]]
then
print "\nTransmit the Cook extract file to the company computer."
&2
usage
exit 0
fi

trap "irupt 1" 1
trap "irupt 2" 2
trap "irupt 15" 15

print "" >>$LOG # Put blank line in the log file
logit "Begin $Prog $@."

case $# in
1 ) FILE=TFH${1}.txt # Extract file to upload.
;;
* ) logit "**** Missing required date argument."
(( NERR ++ ))
;;
esac

if [[ $NERR -ne 0 ]]
then
exitfunc 17
fi

cd /export/extracts/cook # Move to the extract directory.
if [[ ! -s $FILE ]]
then
logit "**** Cannot fine $PWD/$FILE."
(( NERR += 1 ))
exitfunc 29
fi

let nb=$( cat $FILE | wc -l ) # Get byte count, just for the
record.

# The following FTP attempts two times to connect and send the file.
The first
# will probably fail with "421 Service not available...Turning off
passive
# mode." Upon reconnecting and logging in, the second put will
succeed.

ftp -n companyserver <<-EOF >$Pname.out 2>&1
user username password
cd /var/fs/home/branch/hudginsftp
ascii
put $FILE
open companyserver
user username password
cd /var/fs/home/branch/hudginsftp
ascii
put $FILE
dir
bye
EOF

let es=$? # Capture the exit status from
FTP.

# The following grep command looks for the updloaded file in companys
directory.
# If found (exit status = 0), the transfer is assumed to be
successful.

if grep $FILE $Pname.out >/dev/null
then
logit "Successfully uploaded $FILE to companyserver, $nb bytes."
else
logit "**** Problem uploading $FILE [$es]."
(( NERR += 1 ))
let es=$es+64
fi
exitfunc $es

This script used to work with HP-UX, now that we moved to a Linux
server we tried to adapted but somehow is not working the right way.
Again this is the x.autoextract script that runs from the crontab. I
ran it yesterday at 20.30 and same result, it stop at: logit "****
Problem running x_cook.4gi [$es]." So it look like the problem/error
is in the x.putcook script. The weird thing is when i run it manually
in the morning and type the date argument for the last day, runs just
fine.
If you can take a quick look at this and let me know if you find
something out of place, please let me know.

Thanks in advance

.



Relevant Pages

  • Re: transfering signals to a subshell
    ... > If you are at the command line and enter the command above, ... trap 2 3 ... Now I run test1 and press ^C immediately: ... The Script is rather long. ...
    (comp.unix.shell)
  • Re: Why does the system hungs?
    ... I tested that script on an linux machine, ... > In this case, we know what you mean (you have a trap message), but you ... That would be HTFS file system corruption, ... Dump not complete ...
    (comp.unix.sco.misc)
  • Re: Running a command for a limited time
    ... This does happen automatically, the signal is SIGCHLD. ... trap exit SIGCHLD ... trap "exit" SIGCHLD ... I adapted the latest script to bash and it works as advertised. ...
    (comp.unix.shell)
  • RE: Active Directory Password Script Error Trapping
    ... I wrote a similar asp page for our company. ... You should put an On Error Resume Next in your script, ... > What I would like to know is how do I error trap this? ... > Policy complexity rules (no idea what the error code for this is yet as this ...
    (microsoft.public.windows.server.scripting)