Solved

Gwting info from a file and using that info

Posted on 2000-05-11
8
125 Views
Last Modified: 2010-03-05
here is how my config file looks like:
==========================
#Config info
#
#
DATABASE,NODE,file1,user1,passwd1
DATABASE,NODE,file2,user2,passwd2
#
#
===========================
HERE IS WHAT I WANT TO DO:

(1). OPEN THE CONFIG (ITS IN THE DIRECTORY: A/B/CONFIG/configfile)
(2). parse the each line that begis with DATABASE
(3). get all the file(S), user(s) and passwd(s)

(4). Then I need to connect to the files cause they are databases..
       i know how to do that already all i need is the parsing of the file to get
      the desired info.

THANKS ALOT.
CODER
0
Comment
Question by:CODER
  • 3
  • 3
  • 2
8 Comments
 
LVL 16

Expert Comment

by:maneshr
ID: 2801096
try this.
i does what you want.

=================coder.pl
#!/usr/local/bin/perl

open(CONF,"/A/B/CONFIG/configfile") || die $!;
@lines<CONF>;  ## Read all the lines in the file
close(CONF);

foreach $line (@lines){
  next if $line=~ /^#/; ##  Ignore comment lines
  chomp($line); ##  Remove the \n
  ($db,$node,$file,$user,$pass)=split(/,/,$line);
  if ($db=~ /^DATABASE$/){
    print $user," & ",$pass,"\n";
    ## Add your connect code here!!
  }
}
0
 

Author Comment

by:CODER
ID: 2801193
it does not work
this is what i get:
=====================
35 sciris!PERL> perl test.pl
syntax error at test.pl line 4, near "CONF>"
Execution of test.pl aborted due to compilation errors.      
================================

whats the problem
will this retrieve all the info that I want
0
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2801252
try using
 
@lines = <CONF>;


instead of

@lines<CONF>



and use

if ($db=~ /^DATABASE/){

instead of
   

if ($db=~ /^DATABASE$/){
   
0
 
LVL 16

Accepted Solution

by:
maneshr earned 25 total points
ID: 2801304
the error is cause of the line..
@lines<CONF>;  ## Read all the lines in the file

it should be...
@lines=<CONF>;  ## Read all the lines in the file

Sorry :-0
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:CODER
ID: 2801401
why chris??? shoul I use =~/^DATA/ as opposed to putting a $ at the end of DATABASE???
what's the diff?   I thouhgt $ means end of string?
0
 

Author Comment

by:CODER
ID: 2801405
thanks maneshr...
0
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2801413
2). parse the each line that begis with DATABASE



You wanted the above isnt it ?

Only at the BEGINNING there must be a match ..isnt it ?
0
 
LVL 6

Expert Comment

by:christopher sagayam
ID: 2801425
oops sorry Maneshr and you are right ..

Im wrong ...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now