I need a shell script which will automatically update a file.

I need a shell script which will automatically update a file.

Post by Melinda Mallor » Thu, 12 Sep 2002 20:37:16



Hi Guys

I need to update a config file automatically.  I currently update this
file manually.

Does anyone have a script which will update a file?  Is sed, awk, or
some other tool the best way to go?  Opinions?

Specifically,  I need to update iPlanet's obj.conf and mime.types
files.  The existing files do not need to be updated,
I just need to add objects, etc.

i.e.: obj.conf

line1
line2
------
# shell script adds these lines
newly added line3
newly added line 4
------
line 5 (was line 3 before update)
etc....

Thank You, and God Bless America!!!

Regards,

Melinda

 
 
 

I need a shell script which will automatically update a file.

Post by Melinda Mallor » Fri, 13 Sep 2002 01:21:16


I am real upset that this message posted soo many times.  My husband
sent it this morning and got an error due to pop3 email not being
set up correctly, but I insisted that it did not work.  So I kept
resending it, getting the error, and thinking it didn't work.  then
finally I figured out that it was the 'cc:' that was not working and
didn't realize that the message actually got posted a 'gazillion'
times.

My extreme apologies to the group, and sorry to waste even more
bandwidth......

:-(

On Wed, 11 Sep 2002 11:37:16 GMT, Melinda Mallory


>Hi Guys

>I need to update a config file automatically.  I currently update this
>file manually.

>Does anyone have a script which will update a file?  Is sed, awk, or
>some other tool the best way to go?  Opinions?

>Specifically,  I need to update iPlanet's obj.conf and mime.types
>files.  The existing files do not need to be updated,
>I just need to add objects, etc.

>i.e.: obj.conf

>line1
>line2
>------
># shell script adds these lines
>newly added line3
>newly added line 4
>------
>line 5 (was line 3 before update)
>etc....

>Thank You, and God Bless America!!!

>Regards,

>Melinda


 
 
 

I need a shell script which will automatically update a file.

Post by Dan » Fri, 13 Sep 2002 02:19:46



Quote:> Hi Guys

> I need to update a config file automatically.  I currently update this
> file manually.

> Does anyone have a script which will update a file?  Is sed, awk, or
> some other tool the best way to go?  Opinions?

> Specifically,  I need to update iPlanet's obj.conf and mime.types
> files.  The existing files do not need to be updated,
> I just need to add objects, etc.

> i.e.: obj.conf

> line1
> line2
> ------
> # shell script adds these lines
> newly added line3
> newly added line 4
> ------
> line 5 (was line 3 before update)
> etc....

> Thank You, and God Bless America!!!

> Regards,

> Melinda

If all you are doing is adding lines then I would just use the ">>" to
append to the file.  echo "line3" >> obj.conf
If the lines were in a file obj_upd.txt,  cat obj_upd.txt >> obj.conf

Of course that does absolutely no checking or anything, so I am sure you may
want to add that.

 
 
 

I need a shell script which will automatically update a file.

Post by David Thompso » Fri, 13 Sep 2002 08:09:39



Quote:> >I need to update a config file automatically.  I currently update this
> >file manually.

> >Does anyone have a script which will update a file?  Is sed, awk, or
> >some other tool the best way to go?  Opinions?

> >Specifically,  I need to update iPlanet's obj.conf and mime.types
> >files.  The existing files do not need to be updated,
> >I just need to add objects, etc.

> >i.e.: obj.conf

> >line1
> >line2
> >------
> ># shell script adds these lines
> >newly added line3
> >newly added line 4
> >------
> >line 5 (was line 3 before update)
> >etc....

> >Thank You, and God Bless America!!!

Yes, God Bless America!  And please don't top-post!

Well, without having any idea what line2 and/or line3 looks like,
the only help you can get is general solutions.  As long as you
know regular expressions well, and vi/ex commands, try this model,

  ex - filename << EOF
  w! %.orig
  <editing-commands>
  q
  wq
  EOF

I designed many a here document with different editing-commands
using this technique.  In fact I wrote a script called exauto
(now too big to post here) that alows you to store these ex editing
commands in a separate file, so that you could type,

  exauto -f excmds filename

and filename would be edited with commands from excmds file.  The
exauto script built a * here document, inserted contents of
file called excmds in place of <editing-commands> and executed it.

exauto was kinda a poor man's sed, but has proven advantagous over
the years for sed-like editing that needed to be automated over
really REALLY large amount of files.

An explanation of the here document contents:

 w! %.orig  -- saves copy of original filename with .orig extension.

 <editing-commands>  -- are your ex editing commands.

 q  -- will exit if no changes were made, effectively skips the wq

 wq  -- if changes were made, the q fails, so this wq saves the changes

The editing-commands usually require you to position yourself, then
type a, add the lines to insert, then close with a single .

If you need help on the editing-commands, provide an example of what
line2 and line3 look like.  You need to tell us plainly why line2/3
was chosen.  Why did you insert between line2 & line3 in your example?
Is it based upon line number, or based upon a regular expression?

The advantage I've found in using this technique is that I don't
always have to be an expert at sed.  I can use ex, which most vi
folks know better than they think.

I also like the positioning of the 'cursor' that ex provides.  sed
is one pass only, but ex commands will 'move' the cursor around
using the same thought processes that your vi brain cells follow.

--
David Thompson

 
 
 

I need a shell script which will automatically update a file.

Post by Andreas K?h?r » Fri, 13 Sep 2002 08:23:04


Submitted by "David Thompson" to comp.unix.shell:
[cut]

Quote:> Well, without having any idea what line2 and/or line3 looks like,
> the only help you can get is general solutions.  As long as you
> know regular expressions well, and vi/ex commands, try this model,

>   ex - filename << EOF
>   w! %.orig
>  <editing-commands>
>   q
>   wq
>   EOF

> I designed many a here document with different editing-commands
> using this technique.  In fact I wrote a script called exauto
> (now too big to post here) that alows you to store these ex editing
> commands in a separate file, so that you could type,

>   exauto -f excmds filename

> and filename would be edited with commands from excmds file.  The
> exauto script built a * here document, inserted contents of
> file called excmds in place of <editing-commands> and executed it.

> exauto was kinda a poor man's sed, but has proven advantagous over
> the years for sed-like editing that needed to be automated over
> really REALLY large amount of files.

> An explanation of the here document contents:

>  w! %.orig  -- saves copy of original filename with .orig extension.

> <editing-commands>  -- are your ex editing commands.

>  q  -- will exit if no changes were made, effectively skips the wq

>  wq  -- if changes were made, the q fails, so this wq saves the changes

> The editing-commands usually require you to position yourself, then
> type a, add the lines to insert, then close with a single .

> If you need help on the editing-commands, provide an example of what
> line2 and line3 look like.  You need to tell us plainly why line2/3
> was chosen.  Why did you insert between line2 & line3 in your example?
> Is it based upon line number, or based upon a regular expression?

> The advantage I've found in using this technique is that I don't
> always have to be an expert at sed.  I can use ex, which most vi
> folks know better than they think.

> I also like the positioning of the 'cursor' that ex provides.  sed
> is one pass only, but ex commands will 'move' the cursor around
> using the same thought processes that your vi brain cells follow.

Why not use ed directly?  Yes, ed, not ex.  It reads editing
commands from stdin by default...  That's what sed is based on
after all.

--
Andreas K?h?ri
--------------------------------------------------------------
Stable, secure, clean, free:  www.netbsd.org

 
 
 

I need a shell script which will automatically update a file.

Post by David Thompso » Fri, 13 Sep 2002 08:59:28



[snip]

Quote:> > I also like the positioning of the 'cursor' that ex provides.  sed
> > is one pass only, but ex commands will 'move' the cursor around
> > using the same thought processes that your vi brain cells follow.

> Why not use ed directly?  Yes, ed, not ex.  It reads editing
> commands from stdin by default...  That's what sed is based on
> after all.

I can only think of one reason: vim understands ex commands,
so if I needed some vim specific feature I could use vim's
ex mode to process it.

But, even without vim, I've never found ex lacking as a tool.

Btw, vim has this cool -w option, that records all your keystrokes
in a script file.  I haven't had the need to master this just yet,
but it sounds like a worthy successor to my exauto technique.

--
David Thompson

 
 
 

I need a shell script which will automatically update a file.

Post by Bruce Burhan » Fri, 13 Sep 2002 10:56:50



Quote:> Hi Guys

> I need to update a config file automatically.  I currently update this
> file manually.

> Does anyone have a script which will update a file?  Is sed, awk, or
> some other tool the best way to go?  Opinions?

> Specifically,  I need to update iPlanet's obj.conf and mime.types
> files.  The existing files do not need to be updated,
> I just need to add objects, etc.

> i.e.: obj.conf

> line1
> line2
> ------
> # shell script adds these lines
> newly added line3
> newly added line 4
> ------
> line 5 (was line 3 before update)
> etc....

> Thank You, and God Bless America!!!

> Regards,

> Melinda

     I think that the solutions offered up here are the
result of inadequate information from you two.....They
are way more complex than they need to be....

    From whence comes the new obj file and mime type
info that you need to add to these files?  How often
does it come in?  Is your system always up so that we
can use a cronjob?

    If they are  simple entries in other files,  then you
could run an endless loop checking the source files, a script something like
this:

(this is untested and I hope it will be criticized by the experts here)

#/bin/bash

OBJ="path/to/file/with/new/obj"
OLD1="path/to/file/needing/update
MIME=/........
OLD2=/............

K=0

            Until   [  $K  -eq   10 ] ;  # attempt to set up
# and endless loop to keep checking $OBJ  & $MIME
                do

                    if  [ $OBJ  -nt   $OLD1 ] ;   then

                            tail  -1  $OBJ  >>  $OLD1

                    fi

                    if  [  $MIME  -nt   $OLD2 ] ; then

                            tail -1   $MIME  >>  $OLD2

                    fi
done

Hope I am somewhere in the ballpark ........

Bruce<+>

 
 
 

1. Script that automatically updates your plan file?

Anyone,

I am need of a way to update my .plan file on a remote system after I
connect to my ISP via SLIP/PPP.  I  have looked into writing scripts for
this using telnet to go to port 21 (ftp).  However, I can't get it to
receive commands like in a script format.  

The reason I want to do this is that my ISP has dynamic IP number
assignment, and I would like to let everyone know where I am.

Any help is greatly appreciated...

James Wilson

-----------------------------------------------------------
--> James Wilson <--

2. Solaris <=> NT users equivalence

3. Korn/Perl Shell Script to Find Updated Files and E-mail?

4. TekRam DC-680CD controller

5. Shell Script to update Zone Files

6. slocate lockup under RH 7.2

7. Shell script to copy updated files?

8. Major Clock Drift

9. Shell script for updating files ?

10. Anyone have a sample shell script for updating a file?

11. Concurrent Updates of the Same File by 2 Instances of the Same Shell Script

12. Copy files using filenames from text files with shell script or bash script

13. C shell command to use 'file' command to automatically scale a file