Page 1 of 1

Error with Script

Posted: Tue Nov 18, 2008 8:23 pm
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

Posted: Tue Nov 18, 2008 8:44 pm
by ray.wurlod
Why are you trying to run a Korn shell script in a Bourne shell?

Posted: Tue Nov 18, 2008 10:28 pm
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

Posted: Tue Nov 18, 2008 10:55 pm
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.

Posted: Wed Nov 19, 2008 8:44 am
by chulett
From using syntax specific to one shell in another that doesn't support it.

Posted: Wed Nov 19, 2008 11:21 am
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

Posted: Wed Nov 19, 2008 11:35 am
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.

Posted: Thu Nov 20, 2008 9:14 am
by uegodawa
mailx should work for this case.
example :

echo "This is a testing msg." | mailx -s "Subject Line" abc@xyz.com

Posted: Thu Nov 20, 2008 9:54 am
by pradkumar
Hi Everyone,

It worked .. Thanks a lot for sharing the knowledge..

Posted: Thu Nov 20, 2008 10:21 am
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..

Posted: Thu Nov 20, 2008 10:28 am
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.

Posted: Thu Nov 20, 2008 12:44 pm
by pradkumar
ok Chulett..