![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 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 |
|
||||
|
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" |
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|