dayankoven
Programmer
Hi there fellow experts,
I'm very new to UNIX shell programming and I'm trying to copy a file from an ftp directory to a working directory for processing. The script will accept 2 parameters, one is the filename and the other is the SYSTEM code. The script below works fine when both the parameters passed in are correct. But, when wrong parameters are passed in, the script doesn't throw any message but just executes perfectly. Is there something can i do, to say if there is an error, exit with return code != 1 or throw an error message.
A sample Filename will be ABC.
So, i execute the script with the following command :-
APPL.sh ABC SRS
If ABC is found at /sftp/ftpsrs/SRS/CRM/input/ it will be copied over to /prodlib/CRM/batch_dev11/working/ with the timestamp attached.
If i execute the script with the following command :-
APPL.sh XYZ PPP
The script should throw an error and exit with return code non zero but currently it doesn't.
Would appreciate if someone could help me with this. Thanks a lot. My codes are shown below
mydate=$(date +"%Y%m%d%H%M%S"
exception="00"
myfilename=$1
mypath=$2
if [ $2="SRS" ]
then
if test -f /sftp/ftpsrs/SRS/CRM/input/$1
then
cp -p /sftp/ftpsrs/SRS/CRM/input/$1 /prodlib/CRM/batch_dev11/working/$myfilename$mydate$exception.dat
else
RC=1
fi
fi
if [ $2="AIS" ]
then
if test -f /sftp/ftpais/AIS/CRM/input/$1
then
cp -p /sftp/ftpais/AIS/CRM/input/$1 /prodlib/CRM/batch_dev11/working/$myfilename$mydate$exception.dat
else
RC=1
fi
fi
if [ $2="CLS" ]
then
if test -f /sftp/ftpcls/CLS/CRM/input/$1
then
cp -p /sftp/ftpcls/CLS/CRM/input/$1 /prodlib/CRM/batch_dev11/working/$myfilename$mydate$exception.dat
else
RC=1
fi
fi
I'm very new to UNIX shell programming and I'm trying to copy a file from an ftp directory to a working directory for processing. The script will accept 2 parameters, one is the filename and the other is the SYSTEM code. The script below works fine when both the parameters passed in are correct. But, when wrong parameters are passed in, the script doesn't throw any message but just executes perfectly. Is there something can i do, to say if there is an error, exit with return code != 1 or throw an error message.
A sample Filename will be ABC.
So, i execute the script with the following command :-
APPL.sh ABC SRS
If ABC is found at /sftp/ftpsrs/SRS/CRM/input/ it will be copied over to /prodlib/CRM/batch_dev11/working/ with the timestamp attached.
If i execute the script with the following command :-
APPL.sh XYZ PPP
The script should throw an error and exit with return code non zero but currently it doesn't.
Would appreciate if someone could help me with this. Thanks a lot. My codes are shown below
mydate=$(date +"%Y%m%d%H%M%S"
exception="00"
myfilename=$1
mypath=$2
if [ $2="SRS" ]
then
if test -f /sftp/ftpsrs/SRS/CRM/input/$1
then
cp -p /sftp/ftpsrs/SRS/CRM/input/$1 /prodlib/CRM/batch_dev11/working/$myfilename$mydate$exception.dat
else
RC=1
fi
fi
if [ $2="AIS" ]
then
if test -f /sftp/ftpais/AIS/CRM/input/$1
then
cp -p /sftp/ftpais/AIS/CRM/input/$1 /prodlib/CRM/batch_dev11/working/$myfilename$mydate$exception.dat
else
RC=1
fi
fi
if [ $2="CLS" ]
then
if test -f /sftp/ftpcls/CLS/CRM/input/$1
then
cp -p /sftp/ftpcls/CLS/CRM/input/$1 /prodlib/CRM/batch_dev11/working/$myfilename$mydate$exception.dat
else
RC=1
fi
fi