[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

PASSING SCHELL SCRIPT WITH ARGUMENT

Hi experts,
I have written a shell script to FTP a file from a remote site. When the script is invoke with an argument, it should assign it to  FTP_FILE_TO_GET, else it should assign FTP_FILE_TO_GET to FTPIED_FILE. This is the error I get when I execute the script.

oracle[mad1qdr1:goof]$ procall_transtats_test.sh
procall_transtats_test.sh[55]: =USC_DAILY.0519:  not found.

**********************************************************************************
#!/bin/ksh
USAGE="usage: procall_transtats_test.sh arg1"
# This script experts to receive exactly one argument.

# If it doesn't, the file name is generated by the FTP.

##############################################################################This part of the script get yesterday's date in YYYY-MM-DD format.
#########################################################################

OFFSET=${1:-1}
case $OFFSET in
  *[!0-9]* | ???* | 3? | 29) print -u2 "Invalid input" ; exit 1;;
esac

eval `date "+day=%d; month=%m; year=%Y`
typeset -Z2 day month
typeset -Z4 year
# Subtract offset from day, if it goes below one use 'cal'
# to determine the number of days in the previous month.
day=$((day - OFFSET))
if (( day <= 0 )) ;then
  month=$((month - 1))
  if (( month == 0 )) ;then
    year=$((year - 1))
    month=12
  fi
  set -A days `cal $month $year`
  xday=${days[$(( ${#days[*]}-1 ))]}
  day=$((xday + day))
fi
###################################################################
#End of code for date
###################################################################
#Mention the path where the file to FTP is lying in the current server
myname=`basename $0`
verbose="verbose"
#date of FTP - Current date
#dd=`date +%m%d`
dd=$month$day
#USAGE="usage: procall_transtats_test.sh arg1"

typeset -i FTP_FILE_TO_GET
FTPIED_FILE=USC_DAILY.$dd
if (($# > 0 ))
  then $FTP_FILE_TO_GET= $arg1
else
 $FTP_FILE_TO_GET=$FTPIED_FILE
fi

#input_file=USC_DAILY.0423
#input_file=USC_DAILY.$dd
# Creating a log file with datestamp
 LOGS=/users/oracle/PROCALL/test/log
LOGFILE=$LOGS/USC_DAILY$dd.log
host=`hostname`
rc=0
rd=0
boj=`date`
#ftp block starting - all will be written to log file
exec 1>$LOGFILE 2>&1
echo "---------------------------------------------------"
echo "              Begin FTP Parameters  "
echo "---------------------------------------------------"
echo "Email Sent To        $Email1 "
echo "Destination Machine: $IP"
echo "User ID:             $user"
echo "Password:            ##############"
echo "Destination File:    $ofile"
echo "---------------------------------------------------"
echo "                End FTP Parameters  "
echo "---------------------------------------------------"
echo "                Begin FTP Session  "
echo "---------------------------------------------------"
export ORACLE_SID=drdmqa_b
sqlplus -s procall/procall <<EOT
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY/MM/DD';
SELECT DISTINCT JOBDATE FROM TRANSTATS Where JOBDATE = TO_DATE(SYSDATE, 'YYYY/MM/DD');
EOT
FILE_DIR="cd /users/oracle/PROCALL/test"
$FILE_DIR
#FTP_FILE_TO_GET="USC_DAILY."$dd
$FTP_FILE_TO_GET
FTP_TYPE="ASCII"
FTP_HOSTNAME="111111111"
FTP_USER="admin"
FTP_PASSWORD="admin"
FTP_DIR="cd /public"
ftp -n -v $FTP_HOSTNAME<< EOF
user $FTP_USER $FTP_PASSWORD
$FTP_DIR
$FTP_TYPE
get $FTP_FILE_TO_GET
quit
EOF

exit 0
0
jkopoku
Asked:
jkopoku
  • 3
  • 2
1 Solution
 
ozoCommented:
#typeset -i FTP_FILE_TO_GET
FTPIED_FILE=USC_DAILY.$dd
if (($# > 0 ))
  then FTP_FILE_TO_GET= $1
else
 FTP_FILE_TO_GET=$FTPIED_FILE
fi
0
 
jkopokuAuthor Commented:
I am still getting the same error:

oracle[mad1qdr1:goof]$ procall_transtats_test.sh
procall_transtats_test.sh[55]: =USC_DAILY.0519:  not found.
0
 
ozoCommented:
Did you make the changes I suggested?
0
 
jkopokuAuthor Commented:
Yes. This is waht is in the script now:

typeset -i FTP_FILE_TO_GET

FTPIED_FILE=USC_DAILY.$dd

if (($# > 0 ))
  then $FTP_FILE_TO_GET= $1
else

 $FTP_FILE_TO_GET=$FTPIED_FILE

fi
0
 
jkopokuAuthor Commented:
My bad, I didn't  put all your suggestions. It now works thanks.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now