Shell script to change a value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to change a value
# 1  
Old 05-19-2009
Shell script to change a value

I have a shell script that has following entry.

MEM_ARGS="-Xms256m -Xmx512m"
export MEM_ARGS

if [ "${JAVA_VENDOR}" = "Sun" ] ; then
if [ "${PRODUCTION_MODE}" = "" ] ; then
MEM_DEV_ARGS="-XX:CompileThreshold=8000 -XX:PermSize=48m "
export MEM_DEV_ARGS
fi
fi

# Had to have a separate test here BECAUSE of immediate variable expansion on windows

if [ "${JAVA_VENDOR}" = "Sun" ] ; then
MEM_ARGS="${MEM_ARGS} ${MEM_DEV_ARGS} -XX:MaxPermSize=512m"
export MEM_ARGS
fi

if [ "${JAVA_VENDOR}" = "HP" ] ; then
MEM_ARGS="${MEM_ARGS} -XX:MaxPermSize=128m"
export MEM_ARGS
fi

I want to change the line MEM_ARGS="-Xms256m -Xmx512m" to new value lets say MEM_ARGS="-Xms512m -Xmx1024m" . The intention is tha twhetever the value to be given it should go and set Xms and Xmx values.The problem here is that I can't find for word MEM_ARGS= and replace then becuase MEM_ARGS= is existing multiple places. So probably I need to search for "MEM_ARGS="-Xms" in this file and then replace the value that I want. Can you please suggest the best possible commands?

Thanks in advance,
Rijesh.
# 2  
Old 05-19-2009
To more about the problem

I could use cat setDomainEnv.sh | sed -e 's/MEM_ARGS="-Xms.*/MEM_ARGS="-Xms=256m Xmx=1024m"/' > setDomainEnv.sh_tmp , where as I want to the variable in sed. For example

replaceString="-Xms=${JVM_MIN} -Xmx=${JVM_MAX}" and assume JVM_MIN and JVM_MAX is being set already.

cat setDomainEnv.sh | sed -e 's/MEM_ARGS="-Xms.*/MEM_ARGS=${replaceString}/' > setDomainEnv.sh_tmp

This will not replace value ${replaceString} inside sed. Sed require double quote instead of single quotes to get variable replaced. However my string contains replaceString="-Xms=${JVM_MIN} -Xmx=${JVM_MAX}", so the below simply will not work.

cat setDomainEnv.sh | sed -e "s/MEM_ARGS="-Xms.*/MEM_ARGS=${replaceString}/" > setDomainEnv.sh_tmp

Please help on this.
# 3  
Old 05-19-2009
Can u Pls Post the input file content and output ur expecting.
# 4  
Old 05-19-2009
Code:
cat setDomainEnv.sh | sed "s/\(MEM.*Xms\)[0-9][0-9]*\(m -Xmx\)[0-9][0-9]*\(m\"\)/\1$JVM_MIN\2$JVM_MAX\3/g"



cheers,
Devaraj Takhellambam
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script for Auto IP Change

Hi, I am newbie to Linux/Asterisk. I am trying to write a shell script that would look for my SIP trunk registration, if found UNREACHABLE then it would execute a command and check my local IP, if my local IP is 192.168.1.106 then it would change the IP to 192.168.1.150 and vice versa, after... (8 Replies)
Discussion started by: jeetz
8 Replies

2. Shell Programming and Scripting

Shell script to change the ip

I am writing a simple DHCP server application that gets ip from a server at boot up ! i wrote a shell script to run the java program that obtains ip from server on another machine... The problem is when i have obtained the ip i store it in a file ! using awk i retrieve the... (1 Reply)
Discussion started by: dinesh17
1 Replies

3. Shell Programming and Scripting

script to change shell's pwd

Hi there, i was presented with a challenge that is beyond my current shell knowledge: how can you have a script that executed interactive will change your current working directory? Example (under MacOS): 1. start Terminal and my current working directory is my home folder 2. execute a... (3 Replies)
Discussion started by: gigagigosu
3 Replies

4. Shell Programming and Scripting

Shell Script to change a user password using script

Hi Experts, I had tried to executes this script to change the user password through script: No lines in buffer #!/bin/ksh cat /etc/passwd | grep -v userid >> /tmp/pass.tmp1 cat /etc/passwd | grep userid >> /tmp/pass.tmp2 PASS1=`cat /tmp/pass.tmp2 | cut -d ":" -f2` PASS2=`q2w3e4r5` sed... (3 Replies)
Discussion started by: indrajit_renu
3 Replies

5. Shell Programming and Scripting

How to change a directory in shell script?

HI, I need to change the working directory by using the shell script /Export/home/user_name I have to go one step back like /Export/home Please help on this.:confused: (3 Replies)
Discussion started by: thelakbe
3 Replies

6. Shell Programming and Scripting

directory change in shell script

Hi, I am trying to change the directory in my script, & want to check if the directory is present or not . Ex: cd /home/xyz/temp/logs if the logs directory is not present i want to show the error in script instead of shell script error. Can anybody please help me on the same Thx in... (2 Replies)
Discussion started by: vls1210
2 Replies

7. Shell Programming and Scripting

Change the Windows Batch script to UNIX shell script.

Hi, When I run the below script in UNIX it's throwing syntax errors. Actually it's a windows batch script. Could anyone change the below Windows Batch script to UNIX shell script... Script: REM :: File Name : Refresh_OTL.bat REM :: Parameters : %1 - Region REM :: : %2 - Cube Type REM ::... (5 Replies)
Discussion started by: tomailraj
5 Replies

8. UNIX for Dummies Questions & Answers

Change the fonts in the shell script

Hi All, I want to change the font and colour while writing them to a .rtf file using a shell script. How can i do this? Thanks & Regards Dilip (1 Reply)
Discussion started by: DilipPanda
1 Replies

9. Linux

Change directory in a shell script

How do u change ur directory using a shell script?? (12 Replies)
Discussion started by: laxmi
12 Replies

10. Shell Programming and Scripting

script to change shell and prompt

I want to write a shell script which will change the current shell (say from csh to bsh) and my Prompt (say my name) as desired.pls help (1 Reply)
Discussion started by: SHYAM
1 Replies
Login or Register to Ask a Question