LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 11:26 AM   #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, 06:37 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 07:10 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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



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 01:33 AM
Perl: Inserting new data into the middle of a file R00ts Programming 5 03-07-2005 06:48 PM
inserting the data thru php in a text file suchi_s Programming 5 02-02-2005 03:28 AM
Inserting data into normalized databases. Travis86 Programming 2 11-19-2004 03:43 PM
inserting data in mysql zuessh Linux - Software 4 05-19-2003 01:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11: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
Open Source Consulting | Domain Registration