Error with Script

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Error with Script

Post by pradkumar »

Hi Everyone,

Below is the script which is used to get files from FTP share site. The script is working fine on AIX environment but when i try to excute the same script on Sunos5.9 its throwing an error

> sh ./GetFile.ksh
SetEnv()
{
logDir=/export/home/vvivek
PasswordCtl=/export/home/vvivek/FTPPassword.ctl
FTPInDir=/export/home/vvivek
emailGroup=vvivek@amtech.com
}
FTPFile()
{
rcFTP=0
\echo "Receiving $FileName from ftphost ($ServerName)..."
\ftp -inv <<EOF > $ftpLog
open $ServerName
user "$Ftpusername" $Ftppassword
lcd $Ftplocaldir
get $DataFile $FileName
quit
EOF
#--------------------------------------------------------------
# checking for the errors during FTP process
#--------------------------------------------------------------
if [[ -s $ftpLog ]]; then
if [[ -n $(./GetFile.ksh: syntax error at line 41: `(' unexpected
>

Please any one can suggest where iam going wrong with the below script.what changes has to be made to run this script.



***********************Script*************
# name: GetFile.ksh
#
# purpose:
#
# Script to get files from FTP share site.
# One control file is used
#
# /ds/etc/FTPPassword.ctl (text file in secured location)
#
# revisions:
#
# 11-18-08, vvivek, Initial Version
# -----------------------------------------------------------------------------
# set environment
# -----------------------------------------------------------------------------
set -vx
SetEnv()
{
logDir=/export/home/vvivek
PasswordCtl=/export/home/vvivek/FTPPassword.ctl
FTPInDir=/export/home/vvivek
emailGroup=vvivek@amtech.com
}

FTPFile()
{
rcFTP=0

\echo "Receiving $FileName from ftphost ($ServerName)..."
\ftp -inv <<EOF > $ftpLog
open $ServerName
user "$Ftpusername" $Ftppassword
lcd $Ftplocaldir
get $DataFile $FileName
quit
EOF
#--------------------------------------------------------------
# checking for the errors during FTP process
#--------------------------------------------------------------
if [[ -s $ftpLog ]]; then
if [[ -n $(\grep "^226 Transfer complete." $ftpLog) ]]; then
rcFTP=0
else
rcFTP=1
fi
else
\echo "****** unknown error with FTP while getting file ($FileName)! ********"
rcFTP=1
fi
}

# -----------------------------------------------------------------------------
# main
# -----------------------------------------------------------------------------

Me=$(\echo $0 | \awk -F"/" '{print $NF}')
mypath=$(\echo $0 | \awk -F"$Me" '{print $1}')
SetEnv
pid=$$
logFile=$logDir/$(\echo $Me | \awk -F. '{print $1}').log.$(\date +%Y%m%d)
exec 1>$logFile
exec 2>&1
ftpLog=$logDir/$(\echo $Me | \awk -F. '{print $1}')_FTPLog_$pid.log
tmpFile=$logDir/$(\echo $Me | \awk -F. '{print $1}').tmp

if [ ! -f $PasswordCtl ]
then
echo "******** Password file $PasswordCtl not found. Aborting the job ************"
subject="$Me FAILED - Password file not found"
print 'Pls check the attached log file \n\nThanks' >$tmpFile
mutt -a $logFile -s "$subject" $emailGroup < $tmpFile
exit 1
fi

#-------------------------------------------------------
# Reading parameters from Password.ctl file
#-------------------------------------------------------
ServerName=`grep '^FTPIn1' $PasswordCtl | cut -f2 -d'|'`
Ftpusername=`grep '^FTPIn1' $PasswordCtl | cut -f3 -d'|'`
Ftppassword=`grep '^FTPIn1' $PasswordCtl | cut -f4 -d'|'`
DataFile=`grep '^FTPIn1' $PasswordCtl | cut -f5 -d'|'`
FileName=$(\echo $DataFile | \awk -F"/" '{print $NF}')
Ftplocaldir="$FTPInDir"
#-------------------------------------------------------------
# Transferring the data file
#-------------------------------------------------------------
FTPFile

if [[ $rcFTP != 0 ]]; then
echo "********* unable to get the file ($FileName) from ftphost ($ServerName)! *********"
subject="$Me FAILED - FTP of file failed"
print 'Pls check the attached FTP log for errors \n\nThanks' >$tmpFile
mutt -a $logFile -a $ftpLog -s "$subject" $emailGroup < $tmpFile
exit 1
fi

echo "File $FileName successfully transferred from $ServerName at $(\date '+%m-%d-%y %H:%M:%S')"

exit 0



Thanks In Advance
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Why are you trying to run a Korn shell script in a Bourne shell?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So what happens if you either try launching it in the expected shell:

ksh ./GetFile.ksh

Or add this to the top of the script:

#!/usr/bin/ksh
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Thanks for your reply chulett. I will post the result once after adding those variables. But just want to know why is it an error at line 41 with unexpected error.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

From using syntax specific to one shell in another that doesn't support it.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Hi Chulett,

Gr8 the script has worked. Thanks for you suggestion. But again i got a warning ./GetFile.ksh[73]: mutt: not found.
After searching the forum with the key word mutt i understand that mutt is email client on unix machine. i guess we dont have mutt installed on our sunOS 5.9. so how can i get email if the file is not found ? can replace mutt with any other keyword. Please let me know.


Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Right, either get 'mutt' installed on the server or replace the call to it in the script with whatever Sun uses for email... sendmail? If you are unsure, check with your SysAdmins.
-craig

"You can never have too many knives" -- Logan Nine Fingers
uegodawa
Participant
Posts: 71
Joined: Thu Apr 27, 2006 12:46 pm

Post by uegodawa »

mailx should work for this case.
example :

echo "This is a testing msg." | mailx -s "Subject Line" abc@xyz.com
Thanks,
Upul
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Hi Everyone,

It worked .. Thanks a lot for sharing the knowledge..
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

Hi ,

In my requirement i will also need to log audit data. For example the file name , file size . record count in the file etc.. How can i do that ?

Could you please give some suggestions ..

Thanks in Advance..
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

:!: New topic = new post. Please mark this one as Resolved (button at the top of the page) and start a new one for this question.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradkumar
Charter Member
Charter Member
Posts: 393
Joined: Wed Oct 18, 2006 1:09 pm

Post by pradkumar »

ok Chulett..
Post Reply