The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Performance issue with ftp script. Shiv@jad Shell Programming and Scripting 7 07-03-2009 12:01 PM
Issue with the shell script viv1 Shell Programming and Scripting 2 02-19-2008 12:02 AM
SFTP script issue sdhalepaska UNIX for Dummies Questions & Answers 0 07-05-2007 01:24 PM
please help ftp script issue mgirinath Shell Programming and Scripting 4 04-28-2006 10:33 AM
Issue with sed in script bthomas Shell Programming and Scripting 3 04-14-2005 04:21 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-26-2006
chiru_h chiru_h is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 72
Issue in my script

Hello !!

I have a config file with all the server values. I am looking to write a script which edits the file with command line parameters passed to the script. Here is the script:

Code:
function Usage {
  echo "Usage: $0 -thrdcnt <count> -initHeap <init> -maxHeap <max> "
  }
##########
if [[ $# -lt 1 ]];
  then
      Usage
      exit 1
fi
# Now process positional parameters"
while [ $# -gt 0 ]
do
        case "$1" in
            -thrdcnt)
                thrdcnt=$2;shift
                ;;
            -initHeap)
                initHeap=$2;shift
                ;;
            -maxHeap)
                maxHeap=$2;shift
                ;;
	    --)  shift; break;;
            -*)
                Usage
                exit 1;;
             *) break;; # terminate while loop
        esac
        shift
done
###################
ConfigFile=bw_config.xml
temp=
echo $thrdcnt
if [ $thrdcnt -ne $temp ]; then
   sed 's/<threadCount>[-[:alnum:]./]\{1,\}<\/threadCount>/<threadCount>'${thrdcnt}'<\/threadCount>/' "$ConfigFile" > ./tmpfile
   mv ./tmpfile "$ConfigFile"
fi
echo $initHeap
if [ $initHeap -ne $temp ]; then
   sed 's/<initHeapSize>[-[:alnum:]./]\{1,\}<\/initHeapSize>/<initHeapSize>'${initHeap}'<\/initHeapSize>/' "$ConfigFile" > ./tmpfile
   mv ./tmpfile "$ConfigFile"
else
  echo " "
fi
echo $maxHeap
if [ $maxHeap -ne $temp ]; then
   sed 's/<maxHeapSize>[-[:alnum:]./]\{1,\}<\/maxHeapSize>/<maxHeapSize>'${maxHeap}'<\/maxHeapSize>/' "$ConfigFile" > ./tmpfile
   mv ./tmpfile "$ConfigFile"
else
  echo " "
fi
I must be able to use only few parameters or all parameters depending on what is being changed.
I put temp as blank so as to ignore the argument if not specified. not sure if it is right.
With the above script, I am getting the following error:
./configchanges1.sh[65]: [: -ne: missing second argument

I tried several ways, it is working in bits, not working as a whole.
Need help in knowing if my argument passing is right and where am I going wrong with the if statement.

Thanks
Chiru
  #2 (permalink)  
Old 09-26-2006
Andrek Andrek is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 122
Try trplacing your while loop and case statment with the following.

while getopts t:h:m: opt
do
case $opt in
t) thrdcnt=$OPTARG ;;
h) initHeap=$OPTARG ;;
m) maxHeap=$OPTARG ;;
*) Usage ;;
esac
done

your usage would be ....

"configchanges1.sh -t xx -h yy -m xx"
  #3 (permalink)  
Old 09-26-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Code:
temp=
echo $thrdcnt
if [ $thrdcnt -ne $temp ]; then
Think you might have a problem here?
  #4 (permalink)  
Old 09-27-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
Modify your tests :
Code:
if [ -n "$thrdcnt" ] ; then
or
Code:
if [ "$thrdcnt" ] ; then

Jean-Pierre.
  #5 (permalink)  
Old 09-27-2006
chiru_h chiru_h is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 72
I had to give the parameters not just letters as there are several options and couldn't assign a meaningful letter for each argument.
I believe, by assigning 'temp=' , it is not taking it as argument, but even when I said "if [ $thrdcnt -ne "" ]; then" still it didn't work.

Thanks Jean-Pierre. Your statement works perfectly fine.

Chiru
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:10 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