SOLVED: reading config file in a perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SOLVED: reading config file in a perl script
# 1  
Old 08-21-2010
SOLVED: reading config file in a perl script

Hi!

I have a need to do this in Perl.

script.pl -config file

The script would be doing a wget/LWP on a URL which is defined in the config file.

So when I run the script it should return either one of these conditions -

1) OK with exit status 0.
Should also print "wget URL"

2) WARN with exit status of 1.
Should also print "wget URL"

3) ERROR/FATAL with exit status of 2.
Should also print "wget URL"

4) If the script doesnt return anything (no output, times out) -
Timed Out with exit status 2.
Should also print "wget URL"

So the output can be:

script -config file
OK
wget URL-used

#echo $?
0

Thanks,
Jack.

Last edited by Yogesh Sawant; 08-24-2010 at 05:03 AM..
# 2  
Old 08-22-2010
Do the required printing at the different conditions.

And do exit(0), exit(1) as required.
# 3  
Old 08-22-2010
What's the contents of the configuration file? ... I think that's easier with bash.
# 4  
Old 08-22-2010
Hi TG,

Thanks for replying, yes thats true.

Thanks,
Jack

---------- Post updated at 11:59 AM ---------- Previous update was at 11:58 AM ----------

Hi Konsole,

Thanks for replying , the config file just contains a URL.

Thanks,
Jack.
# 5  
Old 08-22-2010
I don't really get what you're after but here's some hint for bash:
Code:
#!/bin/bash

CONFIGFILE=<path to file>
LOGFILE=<path to log file>

read URL < "$CONFIGFILE"

echo "Fetching $URL..."
wget -o "$LOGFILE" "$URL"

# examine based from return value

case "$?" in
0)
    ....
    ;;
1)
    echo "WARN"
    ;;
2)
    echo "ERROR/FATAL"
    ;;
esac

# examine from logfile

if grep '<expression>' "$LOGFILE" >/dev/null; then
    ...
elif grep ...; then
    ...
...
fi

This User Gave Thanks to konsolebox For This Post:
# 6  
Old 08-24-2010
Thanks for the reply but I need to have URL in a config file outside of the script, dont want to change the script if the URL changes.

script.pl -config file

Thanks,
Jack.

---------- Post updated at 01:34 AM ---------- Previous update was at 12:33 AM ----------

thanks found the answer.
# 7  
Old 08-24-2010
Code:
#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;
my $filename="data.txt";
open(FILE, $filename) or die ("could not open $filename!") ;
while (my $data = <FILE>)
{
	chomp $data;
	my $status = getstore($data,my $file1);
	print "The status of the URL $data  is $status\n"	
}
close (FILE);

the data.txt file contains the url list.

Thanks
Namish
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error while reading variable from a file in perl script

I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error. File abc.ini content # database name DBname =UATBOX my $ex_stat; my $cmd_output; $ex_stat = "\Qawk '/^DBname/{print... (2 Replies)
Discussion started by: Devesh5683
2 Replies

2. Shell Programming and Scripting

Need help with perl script with a while loop reading file

Good morning, I appreciate any assistance that I can get from the monks out there. I am able to get this to work for me so that I can do a hostname lookup if I only specify one hostname in the script. What I want to do is have a file with hostnames and do lookups for each name in the file. Here is... (1 Reply)
Discussion started by: brianjb
1 Replies

3. Shell Programming and Scripting

[Solved] Reading the last word in a file from a script

Hello everybody, My first time here and my english is not very good I hope you understand me. I'm trying to read a file that contains two zip archive names. Here my file content is: package1.zip package2.zip At the end of the line there is a \n character. I read this file from a... (2 Replies)
Discussion started by: Aurea
2 Replies

4. Shell Programming and Scripting

[Solved] Get username, etc. from config file

how can i get the database name from a config file its like this: // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'userabc_wrdp1'); (there might be spaces in the front of "define") i want to store... (0 Replies)
Discussion started by: vanessafan99
0 Replies

5. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

6. Shell Programming and Scripting

[Solved] perl and grep: get a script to look at more then one file

hi guys i have this very messy script, that looks in /var/log/messages.all for an error and reports if it finds the key works how can i get it to look at more then one file, i.e /var/log/message.all * so it looks in old logs as well thanks exit 0 if (isRenderNode(hostname)); my... (4 Replies)
Discussion started by: ab52
4 Replies

7. 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

8. Shell Programming and Scripting

Help need in perl script reading from file

Need perl script, data file will be csv format. I have text file contains 2 colums. Filename Foldernumber aaaa 13455 bbbb 23465 cccc 26689 I have two location 1. files present and 2. folders present. I need to search for file and folder if folder... (3 Replies)
Discussion started by: hnkumar
3 Replies

9. Shell Programming and Scripting

Help with perl script while reading a file

Hi Everyone, I am very new to perl, but came across a situation wherein I have to read a c++ header file and write the datatype, its identifier and also the length to an excel file. There can be other header files, in the directory but I should browse through the file which has only "_mef:" string... (9 Replies)
Discussion started by: ramakanth_burra
9 Replies

10. Shell Programming and Scripting

Reading each line of a file in perl script

HI I need to read each line (test.txt) and store it in a array (@test) How to do it in perl. Suppose i have a file test.txt. I have to read each line of the test.txt file and store it in a array @test. How to do it in perl. Regards Harikrishna (3 Replies)
Discussion started by: Harikrishna
3 Replies
Login or Register to Ask a Question