02-25-2009
(Perl) GetOptions
hi all -
i'm trying to teach myself some perl, and my first project is to take a bash script i wrote to process some logfiles and port it. that script works well, it's just slow, and the whole thing seemed like a good way to learn.
one really nice thing about my bash script is that it looks at any arguments passed, assigns values to variables, and if it finds something's missing, prompts the user for that information before proceeding. i believe i can make the same logic work using perl, but i'm stumped about some specifics. my googling tells me that i probably want to use Getoptions::Long to handle command line arguments; i've gotten fair results using Switch, but i think GetOptions is likely cleaner. i am, of course, open to suggestions.
anyway, since the script will do a few different operations (a basic find, count occurrences of $string, etc.), i'm using $operation to hold, well, the operation we're performing, and $string to hold the string we're looking for. i believe i can use GetOptions to process arguments properly if i call the script like, for example, this:
logChecker --operation find --address me@domain.com
but what i'd really like to do is to call it like this:
logChecker.pl -f me@domain.dom
(so, find (-f) all instances of the supplied email address)
but i can't figure out how to tell GetOptions to assign values to multiple variables based on one pair of options like that. so that's my question: am i asking too much of GetOptions? is it possible for GetOptions to look at something like '-f me@domain.dom' and assign $operation=find AND $string=me@domain.dom?
i'm hoping it's possible, but i haven't found an example of it yet.
thanks in advance,
-john.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows:
$count = 0;
while ( $count < $#test )
{
`sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`;
`cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies
2. Shell Programming and Scripting
Hi ,
This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated.
use Time::Local;
my $d = $ARGV;
my $t = $ARGV;
my $m = "";
@d = split /\//, $d;
@t = split /:/, $t;
if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies
3. Shell Programming and Scripting
I need to process a file line-by-line using some value from a shell variable
Something like:perl -p -e 's/$shell_srch/$shell_replace/g' input.txt
I can't make the '-s' work in the '-p' or '-n' input loop (or couldn't find a syntaxis.)
I have searched and found... (4 Replies)
Discussion started by: alex_5161
4 Replies
4. Shell Programming and Scripting
How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ?
Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies
5. Shell Programming and Scripting
I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense.
... (4 Replies)
Discussion started by: kittyluva2
4 Replies
6. Shell Programming and Scripting
Hi all,
Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM.
Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers.
At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies
7. UNIX for Advanced & Expert Users
we create a HP-UX software depot with a new perl-modul. after installation of the software depot, the perl module
i can't find with instmodsh in the inventory for installed Perl modules.
- i have learned of using instmodsh command : i find out what modules are already installed on my system.
... (0 Replies)
Discussion started by: bora99
0 Replies
8. Shell Programming and Scripting
Hi all,
I have written a perl code and stored the data into Data structure using Data::Dumper module.
But not sure how to retreive the data from the Data::Dumper.
Eg.
Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies
9. Programming
My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence.
I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have
... (2 Replies)
Discussion started by: alex_5161
2 Replies
10. Programming
I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open())
I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
LEARN ABOUT DEBIAN
checksendmail
CHECKSENDMAIL(8) BSD System Manager's Manual CHECKSENDMAIL(8)
NAME
checksendmail -- verify sendmail address transformations.
SYNOPSIS
checksendmail [-a] [-d] [-b] [-C file.cf] [-b sendmail_binary] [-l log_file] [-r resolve] [-T test.address]
DESCRIPTION
The checksendmail program is a perl script that aids the testing of sendmail(8) 's various configuration files. checksendmail passes typical
addresses (supplied in input files) through sendmail and prints the results of the resolution and transformation routines.
The input files contain a list of addresses, one per line. For example:
user
user@site
user@site.com
The input file can contain comments started with a # and blank lines.
OPTIONS
-a Show aliasing of local addresses in mail address resolution phase of testing
-d Preceed each address translation line with ruleset sequence summary
-C file.cf Use the sendmail configuration file file.cf instead of the default /etc/sendmail.cf file.
-b sendmail_binary
Use the specified sendmail_binary as the path to invoke sendmail (instead of /usr/sbin/sendmail).
-l log_file
Log sendmail address test mode debugging output to log_file
-r resolve Use resolve as the input file for the addresses to be used for mail resolving. Defaults to address.resolve.
-T test.address
Use test.address as the single address to test. Cannot be used in conjunction with file setting flags.
EXAMPLES
The following command will pass the addresses in address.resolve through sendmail using the configuration information in myconfig.cf.
example% cat address.resolve
user
user@site
user@site.com
example% checksendmail -C myconfig.cf
system: myhost.gadget.com current dir: /tmp/Checksendmail
resolve file: address.resolve
sendmail binary: /usr/sbin/sendmail sendmail version: 8.9.3
config file: /etc/sendmail.cf config file version: V8/Berkeley
Mail address resolution
user --(ether )--> user[rmtc]
user@site --(ether )--> user@site[rmtc]
user@site.com --(ether )--> user@site.com[rmtc]
`To' address transformations for mailer ether:
user ----> user
user@site ----> user@site
user@site.com ----> user@site.com
`From' address transformations for mailer ether:
user ----> user
user@site ----> user
user@site.com ----> user
The first section of the output shows how the addresses in the input files are resolved by sendmail(8). Consider the following output line:
user@site.com --(ether )--> user@site.com[rmtc]
The input address user@site.com resolves to use the ether mailer. That mailer is directed to send the mail to to the user user@site.com at
site rmtc (as indicated in the square brackets).
The two later sections of output show how the addresses specified as the To and From address are transformed in the text of the headers. In
the example above, the To addresses are untouched. The From addresses, however, all lose their machine information on the way through the
mailer:
user@site ----> user
This may be desirable when using a configuration file on a workstation which is to be hidden as a mailhost from the rest of the network.
The following is a set of addresses used at one site for the purposes of testing address resolution. Comments after the addresses detail why
particular addresses are present:
user Standard trivial address
user@rmtc qualified at one level
user@rmtc.central
qualified at two levels
user@rmtc.central.sun.com
qualified all the way
rmtc!user local but specified as uucp
user@summit a workstation (normally delivered locally, though)
user@summit.central
same but more qualified
user@summit.central.sun.com
same but fully qualified
summit!user same but specified as uucp
user@prisma Backward compatibility tests
user@prisma.com
prisma!user
user@central Superior domain testing
user@machine.central
more qualified, but unknown
user@summit.central
more qualified and known
user@eng name in faraway domain
user@machine.eng unknown machine in faraway domain
user@summit.eng local machine, far away domain
user@hoback far away machine
user@machine apparently local but unknown machine
user@sun.com Standard trivial address
user@machine.dom.sun.com
fully qualified but unknown machine
user@foo.com standard, known, really far away domain
user@foo.dom standard, unknown, really far away domain
site!user Single level uucp
site1!site2!user Double level uucp
user@foo.dom@bar.dom
Trickier address
site!user@foo.dom
Mixed uucp/domain
site!user@uunet.uu.net
Mixed double uucp/domain
NOTES
Note that checksendmail is a perl script. If your site does not have perl(1), it can be obtained via anonymous ftp from ftp.uu.net.
sendmail requires that the user have access to directory specified by the OQ parameter in the configuration file (normally
/usr/spool/mqueue). checksendmail verifies that the user has access to this directory before allowing the test to continue.
AUTHORS
Gene Kim
Rob Kolstad
Jeff Polk
Modified by Robert Harker
SEE ALSO
sendmail(8)
BSD
November 14, 2000 BSD