Operating System - HP-UX
1833776 Members
2522 Online
110063 Solutions
New Discussion

Screipt that will build a .netrc file (in users HOME Directory) on the fly.

 
Richard Hood
Advisor

Screipt that will build a .netrc file (in users HOME Directory) on the fly.

This script is used you need to put/get files from a server on a regular basis.

#!/usr/bin/sh
#
# This script will create the .netrc with the apwropriate information
# to get the customer data file to 1EDISource.
# Once the script is downloaded, the edi will process the file.
#
# Created By: Richard Hood on Oct. 11, 2002
#
#
# The routine (create_netrc) will build the .netrc,
# The .netrc file is used by ftp and when the edi account
# makes a ftp call to EDI SERVER all the instructions inside
# of the .netrc file will be processed.
#
create_netrc() {
ROUTINE="::create_netrc:"
cat > $HOME/.netrc<machine (PUT SERVER NAME HERE)
login (PUT YOUR USERID HERE...)
password (PUT YOPUR PASSWORD HERE)
macdef init
as
prompt
verbose
lcd ${DIR}
get ${FILENAME}
bye

EOF
check_error
}

#
# This routine (get_file) will read the .netrc file. The ftp process will
# perform the instruction inside of the .netrc file, put the appropriate
# file and place the file in the appropriate directory (tovan).
#
get_file() {
ROUTINE="::get_file:"
ftp -g SERVERNAME >$OFILE 2>&1
rm $HOME/.netrc
check_error
}

move_file() {
ROUTINE="::move_file:"
cp $DIR/${FILENAME} $DIR/NEWFILENAME >$OFILE 2>&1
check_error
}

#
# The below routine (error_msg) will email a message to the appropriate parties
# if any errors occur during the building of the .netrc file or in
# the upload process of the file.
#
check_error() {
STATUS=`echo $?`
if [ ${STATUS} != 0 ]
then
mailx -s"`hostname`: Download Failed" root<
The following ERROR CONDITION occured during $ROUTINE: $STATUS

The above error code resulted in the following error message:

*** `cat $OFILE`
EOF

exit $STATUS
fi
}

OFILE="/tmp/call_output"
DIR="/mnt/transfer/output"
DATE=`date +%Y%m%d`
FILENAME="FILE_NAME${DATE}"
create_netrc
get_file
move_file


If it ain't broke - Don't fix it