The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed script help urgent jaganadh Shell Programming and Scripting 5 06-29-2007 02:50 AM
[urgent need help] about script bucci Shell Programming and Scripting 6 12-26-2006 01:21 AM
Script - Urgent Help troy86 Shell Programming and Scripting 4 06-01-2006 06:33 AM
Need a Script(Urgent) udayben Shell Programming and Scripting 7 06-06-2005 10:45 AM
Urgent !!! - Script to Change passwords in unix tofani SUN Solaris 2 09-16-2003 07:58 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-29-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
[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 (permalink)  
Old 01-29-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

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 (permalink)  
Old 01-30-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
hi anbu,

not working


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
  #4 (permalink)  
Old 01-30-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

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?
  #5 (permalink)  
Old 01-30-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
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
  #6 (permalink)  
Old 01-31-2007
bucci bucci is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 81
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
  #7 (permalink)  
Old 01-29-2007
johnf johnf is offline
Registered User
  
 

Join Date: May 2006
Location: England
Posts: 284
if [$count -gt 1 ] ; then

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0