Hi, need help, I would like to know what is this IF statement trying to do? When the script is executing and error out with line 9 which is the IF statement line.
if [[ ${0%/*} == $0 ]]
then
TOPDIR=$(pwd)
else
TOPDIR=${0%/*}
fi
TOPDIR=${TOPDIR%/*}
the log file.
Current system time is 18-FEB-2011 00:54:16
+---------------------------------------------------------------------------+
/mnt/oktnfs1/src101/11itest/u33/applmgr/ww_seagate11i/bin/seaoe_send_mail.prog: line 9: syntax error in conditional expression
/mnt/oktnfs1/src101/11itest/u33/applmgr/ww_seagate11i/bin/seaoe_send_mail.prog: line 9: syntax error near `]]
'
/mnt/oktnfs1/src101/11itest/u33/applmgr/ww_seagate11i/bin/seaoe_send_mail.prog: line 9: `if [[ ${0%/*} == $0 ]]
'
/mnt/oktnfs1/src101/11itest/u33/applmgr/ww_seagate11i/bin/seaoe_send_mail
Program exited with status 2
This is the first time I am working on shell scripting. Could you also advise me how to pick up the shell scripting by self learning? I have no idea on how to create a new script.
I think you are getting the error because you are using a shell that does not recognise double square brackets. Try ksh or bash instead of sh to run the script. The code tries to determine the directory in which the script resides. The variable TOPDIR is given the value of the parent of that directory.
Hi there, thanks and appreciate your reply. But there is #!/bin/ksh in the script, is there anything wrong in the script?
#!/bin/ksh
# ------------------------------------------------------------------
# seaoe_send_mail
# This script will mail a file to a distribution list.
# First parameter = email_address $5
# 2nd parameter = filename $6
# 3rd parameter = email subject line $7
#
# 07-apr-04 cat remove notes from email address.
# 02-jun-05 cat upgrade to 11i
# 15-jul-05 cat change /usr/ucb/mail to /usr/bin/mail
# ------------------------------------------------------------------
# Set the variable $TOPDIR, which is the directory above the
# /bin directory where this shell script resides. This module
# assumes a file structure of:
# $TOPDIR/bin - shell scripts and other control code
# $TOPDIR/srw - reportwriter report .rdf files
# ------------------------------------------------------------------
if [[ ${0%/*} == $0 ]]
then
TOPDIR=$(pwd)
else
TOPDIR=${0%/*}
fi
TOPDIR=${TOPDIR%/*}
# ------------------------------------------------------------------
# Initialize variables.
# ------------------------------------------------------------------
IT_PERSON="beeean.ooi@.seagate.com"
#IT_PERSON="nilesh.shah@seagate.com"
message="Unexpected Shell error in $0"
error_subject="Error in process $$ - $0"
# ------------------------------------------------------------------
# This function will run whenever exit is called, whether from this
# script, the errorexit or an interrupt. It updates the log file
# and cleans up the temporary error file.
# ------------------------------------------------------------------
function normalexit {
print " "
print "Process $1 complete at $(date)"
print " "
}
# ------------------------------------------------------------------
# This function is used to exit gracefully if there are errors.
# It mails the standard error message sent to the error file, along
# with the last value of $message (usually STDIO). It also writes
# the full message sent via E-mail to STDIO for log and test purposes.
# ------------------------------------------------------------------
function errorexit {
# write the error message to STDOUT
print "$1"
# Mail the error to the responsible I.T. person
print "$1" | mail -s "$error_subject" "$IT_PERSON"
exit 1
}
# ------------------------------------------------------------------
# Trap errors and exits from any source (exit commands or interrupts)
# ------------------------------------------------------------------
trap 'errorexit "$message"' ERR
trap 'normalexit $$' EXIT
# ------------------------------------------------------------------
# Submitted from Concurrent Manager - Oracle provides the argument
# as a huge string of the form:
# 'COMMAND FCP_???=val ... "parameter1" "parameter2"'
# print ${1##*FCP_LOGIN=} | nawk '{print $1}' | sed 's/"//g'
# strips the login/password from the Concurrent Manager parameter
# print ${1##*FCP_} removes all FCP_ parameters except the final one
# '???=val "parameter1" "parameter2"
# therefore after the print, the key parameters can be extracted
# from the second and third columns of the print.
# ------------------------------------------------------------------
emdist=$5
ffile=$APPL_DATA/tmp/$6
subject=$7
outpath=$APPL_DATA/$APPLOUT
# ------------------------------------------------------------------
# This process assumes that all E-mail addresses
# should end in @seagate.com. It will add to any
# path that does not have it. Any addresses that do not go to
# non-Notes destinations will fail, so there is no way for an
# E-mail to make it to the Internet from this process
# ------------------------------------------------------------------
# emdist=$(print "$emdist" | sed 's/, /,/g')
# emdist=$(print "$emdist," | \
# sed 's/,/@seagate.com,/g' | \
# sed 's/@seagate.com@seagate.com,/@seagate.com,/g' | \
# sed 's/,@seagate.com,/,/g')
# emdist=${emdist%,}
print "Attempting to mail to:
$emdist"
#
# This code is added by Nilesh P Shah on 19/03/2004
#
line_temp=`wc -l $ffile`
line_cnt=`echo $line_temp | cut -f1 -d' '`
if [ $line_cnt -gt 1 ]
then
{
echo " "
echo " "
echo "Sending CRU mail with an ".DAT" file attachment."
echo ""
echo ""
echo "*********************************"
echo "Shipping Freight Term Audit Report"
echo "*********************************"
echo ""
echo ""
uuencode $ffile repricing_report.csv
} | mail -s "$subject" $emdist
else
{
echo " "
echo " "
echo " *** NO DATA SELECTED *** "
echo ""
echo ""
echo "*********************************"
echo "Shipping Freight Term Audit Report"
echo "*********************************"
echo ""
echo ""
} | mail -s "$subject" $emdist
fi
# /usr/ucb/mail \
# -s "$subject" \
# $emdist <$ffile
print " "
print "Report mailed to the address list"
print " "
exit 0
I'd expect a shell that does not recognise [[ ... ]] to baulk at the [[ rather than ]]. It suggests to me the problem is in the if statement. Do you get any funny characters when you type
I tested the if statement on my OSX machine in both bash and ksh -- no problem.
As apmcd47 said, you might have a funky character in that line. :set list in vi would be another way to check for bogus characters. It's that or the shell you are using is not up to the task.
Oops. I stand corrected. In pure Bourne shell the "[[ ]]" syntax did not exist. As I recall it arrived as executable programs called "[[" and "]]" in later versions.
I'd lost track of what a pure Shell is.
Talking of impure Shells. When did "==" become preferred Posix syntax? This is purely out of interest because I come across so many unix Shells that do not support "==" that I have chosen to ignore the syntax for a while.
line 9: syntax error in conditional expression
line 9: syntax error near `]]
Which looks like a bash shell error when ^M follows the ]]:
$ [[ 1 == 3 ]]^M
-bash: syntax error in conditional expression
'bash: syntax error near `]]
This is what makes me suspect that the script file is in dos format and didn't load the ksh shell because of the ^M, and also explains the error message.
I like Chubler_XL's diagnosis. The end of the error message in post #1 is indeed distorted just like when the script contains MSDOS carriage return characters.
O/P has shebang "#!/bin/ksh" . I don't think that we know what version.
Need to know the Operating System and version.
Hi, thanks for the advice, I managed to run the script now. But I have another question,
for the statement below extracted from above script,
how to do if I do not want to hardcode the repricing_report.csv filename. How to get the filename from $ffile?
uuencode $ffile repricing_report.csv }| mail -s "$subject" $emdist
Regards,
BE