[urgent need help] unix script....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [urgent need help] unix script....
# 1  
Old 01-29-2007
[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
# 2  
Old 01-29-2007
Code:
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
Code:
if [[ $count -gt 1 ]] ; then

# 3  
Old 01-29-2007
if [$count -gt 1 ] ; then

If this is how it really is then enter a space between the first [ and the $.
# 4  
Old 01-30-2007
hi anbu,

not working Smilie


Quote:
Originally Posted by anbu23
Code:
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
Code:
if [[ $count -gt 1 ]] ; then

# 5  
Old 01-30-2007
Code:
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?
# 6  
Old 01-30-2007
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
# 7  
Old 01-31-2007
Quote:
Originally Posted by sb008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. UNIX for Dummies Questions & Answers

Unix Command Urgent Help!

Hi All, i am new on this forum, can someone please answer the following questions as i am also new for UNIX, you help would be much appreciated: 1. How do you delete the full directory hierarchy? 2. How do you find out all process run by user Kamran ? 3. how would you extract something... (1 Reply)
Discussion started by: kami151
1 Replies

3. Emergency UNIX and Linux Support

UNIX script URGENT!!!

#!/bin/sh INPUT () { echo "Please enter line number: " read LINE echo "Please enter column number that you want to modify: " read COLUMN head -$LINE dataf > line1; LINE=`expr $LINE + 1` head -$LINE dataf > line2; diff line1 line2 > tmp; sed -e... (18 Replies)
Discussion started by: beginner1988
18 Replies

4. UNIX for Advanced & Expert Users

Need a unix script - very urgent

Hi All, I need a script that invokes the sql query every 14 days and send email Very Very urgent this one to me.... (6 Replies)
Discussion started by: bujjisveeru
6 Replies

5. Shell Programming and Scripting

(Urgent):Creating flat file using sql script and sqlplus from UNIX Shell Script

Hi, I need help urgently for following issue. Pls help me to resolve this issue. I am calling sql script file(file1.sql) from UNIX Shell Script(script1.ksh) using sql plus and trying to create flat file that contains all records returned from SQL query in SQL script(file1.sql) I given... (6 Replies)
Discussion started by: praka
6 Replies

6. HP-UX

HP Unix | Urgent Need Help

Hi, I'm new to unix and i'm using HP Unix I tried the following and getting error like 1. $sam sh:sam not found 2.Also i want to monitor/trace other user's command what they are using when am in to the same server Appreciate if any one help on this (4 Replies)
Discussion started by: msgobinathan
4 Replies

7. Shell Programming and Scripting

Urgent Need your help --New to Unix

I am getting data like this in a flat file seg No Test A4 0000002595, A2, test ,Datatest Test, A1 0000002595, A1,SELF , Employed,1,2,3,400.50 Test, A2 0000002595, A2, test ,Data,eurp Test, A3 0000002595, A2, test ,Data I need to produce a flat file so that output file... (0 Replies)
Discussion started by: nikeng
0 Replies

8. Solaris

Urgent !!! - Script to Change passwords in unix

I have SunOs 5.8. I need to change password using a unix shell script. I have tried to pipe the passwords to the passwd command but does not work. Pls provide a script to change passwds of a list of users using a shell script. ( I have also tried crypt() but did not work) The flow of the... (2 Replies)
Discussion started by: tofani
2 Replies

9. UNIX for Dummies Questions & Answers

I am in urgent need of all UNIX-derivates...

Hi, could anybody name all the different UNIX versions, producer, historie, etc? need a short briefing... THX a lot in advance... Greetings, PatrickXXO (2 Replies)
Discussion started by: PatrickXXO
2 Replies

10. UNIX for Dummies Questions & Answers

Urgent UNIX problem for newbie!

I think someone hacked my UNIX account and I cannot get back into MY OWN account!!!!!! :( I was wondering if any of the experts here would be able to help me either get back into my account or change my password back to what it was or find out what it is now so I can get back in and change it. ... (2 Replies)
Discussion started by: speedemn
2 Replies
Login or Register to Ask a Question