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.

Do the required printing at the different conditions.

And do exit(0), exit(1) as required.

What's the contents of the configuration file? ... I think that's easier with bash.

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.

I don't really get what you're after but here's some hint for bash:

#!/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
1 Like

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.

#!/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