bucci
January 29, 2007, 5:44am
1
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
anbu23
January 29, 2007, 6:27am
2
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
johnf
January 29, 2007, 6:37am
3
if [$count -gt 1 ] ; then
If this is how it really is then enter a space between the first [ and the $.
anbu23
January 30, 2007, 1:18am
5
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?
sb008
January 30, 2007, 10:10am
6
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
bucci
January 31, 2007, 6:13am
7
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
anbu23
January 31, 2007, 6:33am
8
You are getting this error because count variable is null.
Try this
if [ -n "$count" ] && [ $count -gt 1 ] ; then
bucci
January 31, 2007, 10:43pm
9
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
anbu23
February 1, 2007, 12:33am
10
Check whether the file 2007020110.TDR present in the directory /export/home/mapadm/log/TDR/200701
bucci
February 1, 2007, 2:50am
11
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
anbu23
February 1, 2007, 3:23am
12
check whether you have read permission for that file
bucci
February 1, 2007, 3:42am
13
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
anbu23
February 1, 2007, 3:43am
14
Can you show the first few lines of the file?
anbu23
February 1, 2007, 3:51am
15
try this and check whether the file has blank in its name
ls | sed 's/.*/(&)/'
bucci
February 1, 2007, 4:05am
16
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
anbu23
February 1, 2007, 4:37am
17
can you check my previous post and check whether filename contain blanks
bucci
February 3, 2007, 11:30am
18
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
sb008
February 3, 2007, 2:10pm
19
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 ...........
bucci
February 3, 2007, 10:12pm
20
sb008:
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