LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-12-2008, 12:26 PM   #1
Magius363
LQ Newbie
 
Registered: Feb 2008
Posts: 1

Rep: Reputation: 0
inserting data into an existing file


Situation,

I need to make sure that 7 lines of code exist in every instance of snmpd.conf in our network. I do not want to overwite the files as some customers have added special things to this file for their own monitoring. On top of that I don't want to just willy nilly append the 7 lines in case the data already exists in the file. I need to check the file first for the existence of this code, if so leave it alone if it doesn't exist then it needs to be appended to the file.

any thoughts are welcome.
 
Old 03-12-2008, 07:37 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Definitely a proper program needed in that case.
I'd recommend Perl, easy to write, fast running and has modules avail for dealing with networking, snmp etc.
In fact, that's exactly the sort of thing it was originally designed to handle, way back when.
See:
http://perldoc.perl.org/
http://search.cpan.org/

and ask in prog forum, or www.perlmonks.org
 
Old 03-12-2008, 08:10 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,848

Rep: Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823
Yep, could get ugly. Lines exist, but out of order, or commented out, or have (variable) embedded whitespace, ...
erghh.

Pick a (any ???) language you already know. Perl would work well, but has a fair learning curve (guess how I know ... )
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
info on inserting a new module to existing kernel aus9 Linux - Kernel 1 09-18-2006 02:33 AM
Perl: Inserting new data into the middle of a file R00ts Programming 5 03-07-2005 07:48 PM
inserting the data thru php in a text file suchi_s Programming 5 02-02-2005 04:28 AM
Inserting data into normalized databases. Travis86 Programming 2 11-19-2004 04:43 PM
inserting data in mysql zuessh Linux - Software 4 05-19-2003 02:00 PM


All times are GMT -5. The time now is 06:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration