[urgent need help] unix script....

hi experts,

i'm new in scripting unix i have some problem with my script below is shown my script :

#!/bin/sh

BASEDIR=/export/home/mapadm
BINDIR=$BASEDIR/bin
LOGDIR=$BASEDIR/log
TDRDIR=$LOGDIR/TDR
BACKUPDIR=/data/log
export BASEDIR BINDIR LOGDIR TDRDIR BACKUPDIR

YEAR=`date '+%Y'`
MONTH=`date '+%m'`
DAY=`date '+%d'`
HOUR=`date '+%H'`

if [ $HOUR -eq 00 ] ; then
HOUR=23
LASTDAY=`/export/home/mapadm/bin/lastdate 1 | nawk '{print $1}'`
filename="$LASTDAY$HOUR.TDR"

else
cd $TDRDIR/200701
HOUR=`expr $HOUR - 1`
HOUR=`printf "%02d" $HOUR`
filename="$YEAR$MONTH$DAY$HOUR.TDR"
#grep "$YEAR$MONTH$DAY $HOUR" $BINDIR/TDR.LOG > $TDRDIR/$filename
#count = `nawk '$12 == "00008001" { cnt++;cs_cd[$11] } END { print "Count:"cnt;for(cd in cs_cd) print cd }' $filename`
count=`nawk '$12 == "00008001" { cnt++;cs_cd[$11] } END { print cnt }' $filename`
if [$count -gt 1 ] ; then
countsend=`nawk '$12 == "00008001" { cnt++;cs_cd[$11] } END {for(cd in cs_cd) print cd }' $filename`
cd $BINDIR
msggen msggen_SMClient.txt 1 "[1234567890]" "[$countsend not bind]"

fi
fi

the script name is "countsms.sh"

i try to run script but having some error like below :
%countsms.sh
countsms.sh: test: argument expected

please advices

Regards,

bucci

if [ $count -gt 1 ] ; then

The error might occur in this line if the count variable does not contain any value.

To avoid the error you can use double square brackets

if [[ $count -gt 1 ]] ; then

if [$count -gt 1 ] ; then

If this is how it really is then enter a space between the first [ and the $.

hi anbu,

not working :frowning:

HOUR=`date '+%H'`

Check whether %H option is there in date command in your unix system.
If the option exist and still you get the error , can you show the trace of your script?

Put set -x at the beginning of your script and you can see exactly which test generated the error

So:

#!/bin/sh

set -x

rest of script

hi,

below is the result:

BASEDIR=/export/home/mapadm
BINDIR=/export/home/mapadm/bin
LOGDIR=/export/home/mapadm/log
TDRDIR=/export/home/mapadm/log/TDR
BACKUPDIR=/data/log
+ export BASEDIR BINDIR LOGDIR TDRDIR BACKUPDIR
+ date +%Y
YEAR=2007
+ date +%m
MONTH=01
+ date +%d
DAY=31
+ date +%H
HOUR=18
+ [ 18 -eq 00 ]
+ cd /export/home/mapadm/log/TDR/200701
+ expr 18 - 1
HOUR=17
+ printf %02d 17
HOUR=17
filename=2007013117.TDR
+ nawk $12 == "00008001" { cnt++;cs_cd[$11] } END { print cnt } 2007013117.TDR
count=
+ [ -gt 1 ]
countsms.sh: test: argument expected

any idea?

thank you for your attention

Regards,

bucci

You are getting this error because count variable is null.
Try this

if [ -n "$count" ] &&  [ $count -gt 1 ] ; then

hi anbu,

got this error below :

BASEDIR=/export/home/mapadm
BINDIR=/export/home/mapadm/bin
LOGDIR=/export/home/mapadm/log
TDRDIR=/export/home/mapadm/log/TDR
BACKUPDIR=/data/log
+ export BASEDIR BINDIR LOGDIR TDRDIR BACKUPDIR
+ date +%Y
YEAR=2007
+ date +%m
MONTH=02
+ date +%d
DAY=01
+ date +%H
HOUR=11
+ [ 11 -eq 00 ]
+ cd /export/home/mapadm/log/TDR/200701
+ expr 11 - 1
HOUR=10
+ printf %02d 10
HOUR=10
filename=2007020110.TDR
+ nawk $12 == "00008001" { cnt++;cs_cd[$11] } END { print cnt } 2007020110.TDR
nawk: can't open file 2007020110.TDR
source line number 1
count=
+ [ -n ]

please advices..

thank you so much

Regards,

bucci

Check whether the file 2007020110.TDR present in the directory /export/home/mapadm/log/TDR/200701

hi anbu,

if you review back to my script the file is present on the directory,

cd $TDRDIR/200701 -----> define to change to directory which the file logged

any idea?

thank you

Best Regards,

bucci

check whether you have read permission for that file

hi anbu,

yes have a read permission for that file :

-rw-r--r-- 1 mapadm staff 470076 Feb 1 10:59 2007020110.TDR

idea?

thank you

Regards,

bucci

Can you show the first few lines of the file?

try this and check whether the file has blank in its name

ls | sed 's/.*/(&)/'

hi anbu,

below is the few lines of the files :

20070201 095953.862 20070201 100000.167 006.305 62123456789 00000F8D 059 02 002 123 00010022 51234567890 ---
20070201 095845.081 20070201 100000.237 075.156 62123456789 00000F51 037 06 002 999 00010022 51234567890 ---
20070201 095801.511 20070201 100001.945 120.434 62123456789 00000F28 063 02 002 123 00010022 51234567890 ---

any advice?

thank you anbu

can you check my previous post and check whether filename contain blanks

hi anbu,

i have checked it the file contain data.
why the script not working? or you have your own way script for this solution?

any idea?

Thank you so much

Best Regards,

bucci

He asked you to check if there are any blanks in the fileNAME.

just put the command he mentioned in you script just before the nawk command

filename=.........
ls | sed 's/.*/(&)/'
nawk ...........

hi anbu and sb008,

sorry for miscommunication, i'd try to put the ls | sed 's/.*/(&)/' below is the result i have run the script:

BASEDIR=/export/home/mapadm
BINDIR=/export/home/mapadm/bin
LOGDIR=/export/home/mapadm/log
TDRDIR=/export/home/mapadm/log/TDR
BACKUPDIR=/data/log
+ export BASEDIR BINDIR LOGDIR TDRDIR BACKUPDIR
+ date +%Y
YEAR=2007
+ date +%m
MONTH=02
+ date +%d
DAY=04
+ date +%H
HOUR=10
+ [ 10 -eq 00 ]
+ cd /export/home/mapadm/log/TDR
+ expr 10 - 1
HOUR=9
+ printf %02d 9
HOUR=09
filename=2007020409.TDR
+ sed s/.*/(&)/
+ ls
(200610)
(200611)
(200612)
(200701)
(200702)
+ nawk $12 == "00008001" { cnt++;cs_cd[$11] } END { print cnt } 2007020409.TDR
nawk: can't open file 2007020409.TDR
source line number 1
count=
+ [ -n ]

please advices

Thank you so much

Regards,

bucci