[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

SUN Solaris 10 - if-then syntax error

Need help debugging if-then logic in unix shell script.
Script runs on Sun Solaris 10 64 bit - I have KSH as my shell.

Here is the script:
#######################################################################
#!/bin/ksh
# set -xv
#
PATH=$PATH:/usr/bin:/usr/sbin/:/sbin:/bin:/usr/opt/networker/bin; export PATH
LOGPATH=/usr/local/oracle; export LOGPATH
#
DATED=`date "+%m%d%y"`;export DATED
LOGFILE=$LOGPATH/b31.log; export LOGFILE
#
#######################################################################
#
echo $DATED                                              > $LOGFILE 2>&1
echo Start: `date +"%d/%m/%y %H:%M"`                    >> $LOGFILE 2>&1
DOM=`date '+%d'`; echo $DOM                             >> $LOGFILE 2>&1
DOM31='03';export DOM31
#
# For TEST change 03 to current day#
if [["$DOM" == "$DOM31"]];
then
source='25';export source
else source=`date |awk '{print $3}'`;export source
export source
fi
#
#######################################################################
#
#
echo  $DOM  $DOM31  $source                             >> $LOGFILE 2>&1
#
####################### End of Script #################################

Here is the command run and the output ......................
 sh +xv ./b31.sh
./b31.sh: [[03: not found

Here is what is in the log file.........................................
080307
Start: 03/08/07 15:57
03
03 03 3


___________________________
can you explain my syntax error?

Thanks

0
bkreynolds48
Asked:
bkreynolds48
  • 5
  • 5
1 Solution
 
NukfrorCommented:
Well, first thing ... notice how you called the script:

sh +xv ....

That's Bourne shell.  Bourne shell has no close what [[ means.  That's a ksh construct.

You should run the script as:

ksh +xv ...
0
 
bkreynolds48Author Commented:
Same results...............

ksh +xv ./b31.sh
./b31.sh[19]: [[03:  not found
0
 
NukfrorCommented:
Put a single space after the opening [[ and a single space before the closing ]] and try it again.

e.g.  if [[ "$DOM" == "$DOM31" ]];
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bkreynolds48Author Commented:
Nukfror,

Thanks - that got rid of the error
0
 
bkreynolds48Author Commented:
Even though the script runs without error from the command line now
If I run it from cron I get the following error.............

/usr/local/oracle/b31.sh: [[: not found

Any ideas?
0
 
NukfrorCommented:
Crontab script as traditionally Bourse shell based as crontab does a "sh <scriptname>".  I'm almost positive it doesn't use the link loader which would see your #!/bin/ksh at the top.
0
 
bkreynolds48Author Commented:
I changed the script to be
/bin/sh

but the results are the same
0
 
NukfrorCommented:
That's not the point ... crontab - not the link loader - runs the script as BOURNE shell.  So your modification does #!/bin/sh does nothing.

What you'll have to do is create a simple bourne shell script that calls your ksh script.  Something like this:

/my/directory/script1.sh:
#!/bin/sh
ksh /my/directory/script2.ksh

/my/directory/script2.ksh:
<the script you posted above>
0
 
NukfrorCommented:
wait ... sorry I'm a complete dork.

Your crontab entry for your script should look like this:

MM HH  * * * ksh <FQN of whatever your script is called>

Also the #!/bin/ksh line in your script should be the FIRST line in the script.  The ###### line in front of it will make the link loader have not clue how to execute the script - should the script ever be attempted to be run the by link loader.
0
 
bkreynolds48Author Commented:
Nukfror putting the ksh in cron solved the issue

Thanks so much!

Bev
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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