Error with Script
Moderators: chulett, rschirm, roy
Error with Script
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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
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
mailx should work for this case.
example :
echo "This is a testing msg." | mailx -s "Subject Line" abc@xyz.com
example :
echo "This is a testing msg." | mailx -s "Subject Line" abc@xyz.com
Thanks,
Upul
Upul