issue on dynamic config script


 
Thread Tools Search this Thread
Operating Systems Linux issue on dynamic config script
# 1  
Old 01-27-2011
issue on dynamic config script

I have one issue with my existing code.Actually i want to write parameter's at the end of the section not begin of section.please find my code snapshots...
Code:
while read cfgfilename sectionname parameter
do
  case "$cfgfilename" in
    cfgfilename)
      FILE=$HOME/config/$parameter
      unset SECT
      [-f $FILE] || {echo -e $FILE is not found under $CFGFILEPATH directory...} | tee -a $LOGFILE
    ;;
    sectionname)
      [-z $FILE] && continue
      SECT="$parameter"
      while true
      do
        N=$(grep -Fwnx "$SECT" $FILE | cut -d ':' -f1)
        ((N)) && break
        echo -e $SECT section not found in $FILE ,adding section | tee -a $LOGFILE
        echo -e "$SECT\n" >> $FILE
      done
    ;;
    *)
      if [-n "$FILE"] && [-n "$SECT"]
      then
        ((N++))
        sed -i"{$N}" 'i\' "$cfgfilename $sectionname $parameter" $FILE

Actually abobe code take cfgfilename and section name and patrameter from a input file and check in config director for specific cfgfilename if found take sectionnmae and searcg in cfgfilename ,if section found it's simply added parameter's begin of section,and if not found then add it at end of file along with parameter's.
Actually i want,if section is found in existing filename,then it should write at end of section not the begn...like example..
common.cfg
Code:
[section1]
p1
p2
p3
[section2]
p4
p5
p6

If i want to add parameter's in common.cfg file's section1,it shoul write after parameter p3 not before p1.


Please help me..
thnks
surya

Last edited by Scott; 01-27-2011 at 04:17 AM.. Reason: Code tags
# 2  
Old 01-27-2011
This doesn't look like all your code... where are you actually writing the new settings to the file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

T4-2 - Memory DIMM issue - ldom config resets to factory-default

Which basically means the ldoms that were on there are not starting (not even showing). If I do ldm list-config it shows live config as next reboot. But, of course, next reboot it reverts back to factory default again. I must admit I'm wondering if its doing this becasue (with the... (3 Replies)
Discussion started by: psychocandy
3 Replies

2. Shell Programming and Scripting

Script to detect dynamic ip change and update to config file

Hi All, I am newbie here and request your assistance. I have a service running on public ip, but since I have a dynamic IP it keeps on changing and every time I need to manually get the new ip and add to the config file and restart the service. This has become bit time consuming. Hence, I... (4 Replies)
Discussion started by: Shaan_Shaan
4 Replies

3. Shell Programming and Scripting

Shell script that will compare two config files and produce 2 outputs 1)actual config file 2)report

Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated. script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made. OS :Susi linux ver 10.3. ... (4 Replies)
Discussion started by: muraliinfy04
4 Replies

4. IP Networking

DHCP config issue?

I searched the forum and found a similar question (https://www.unix.com/ip-networking/119108-dhcpd-related-questions.html), but my config is already utilizing the suggested fix... :( My setup: eth0 connected to Motorola DSL Modem via bridged mode (giving the public IP to the interface), IP... (1 Reply)
Discussion started by: macwunder
1 Replies

5. UNIX for Dummies Questions & Answers

Issue with parsing config variables

I am using MKS tool kit on windows server. One config variable is defined in windows environment and I am trying to use that variable. # Below RootDir is defined in windows RootDir="\\f01\var" # in unix script details="$RootDir/src|$RootDir/tgt" src=`echo $details|awk -F '|' '{print... (1 Reply)
Discussion started by: madhukalyan
1 Replies

6. Solaris

Syslog config Issue.

Hi All, I have configured a centralised system log server. The /etc/syslog.conf file in my client(Sol 5.10) looks like this. e1011605: cat /etc/syslog.conf # # Copyright (c) 2000-2002 by Sun Microsystems, Inc. # All rights reserved. # #ident "@(#)syslog.conf 2.3 ... (2 Replies)
Discussion started by: Hari_Ganesh
2 Replies

7. UNIX for Advanced & Expert Users

Sql dynamic table / dynamic inserts

I have a file that reads File (X.txt) Contents of record 1: rdrDESTINATION_ADDRESS (String) "91 971502573813" rdrDESTINATION_IMSI (String) "000000000000000" rdrORIGINATING_ADDRESS (String) "d0 movies" rdrORIGINATING_IMSI (String) "000000000000000" rdrTRAFFIC_EVENT_TIME... (0 Replies)
Discussion started by: magedfawzy
0 Replies

8. Solaris

Tape drive config issue

I have a server/domain on a m5000 running Solaris 10. It is part of a cluster. The other cluster member sees tape drives, but this one does not. It is zoned correctly, and I can see the drives are binded in lputil. The st.conf, and devlink.tab are identical. ST.CONF: - # # Copyright... (2 Replies)
Discussion started by: pfwhufc
2 Replies

9. Solaris

Apache config issue

I want to build a little website on a Sun Blade 100 running Solaris 10. I just went out to apache.org and downloaded Unix Source: httpd-2.2.8.tar.gz After unpacking the tarball, I CD'd into the subdirectory and ran the configure utility. Of course, it crapped out. I see that it is... (17 Replies)
Discussion started by: BrewDudeBob
17 Replies

10. Shell Programming and Scripting

Dynamic Array Issue

Could one of you, please, provide some input regarding my problem below and it is as follows: I have 2 files that I need to make sure are identical before processing: First, I sort both files Second, I do a diff file1 file2 > File 3 This provides me with the difference. Now, I need to... (6 Replies)
Discussion started by: ddedic
6 Replies
Login or Register to Ask a Question