RE: Perl Script as a Cron Job

2006-10-11 Thread Jason Wozniak
Here is what I use for a perl script I use to restart the oracle
listener if it goes down, to set the oracle environment.

 

00,10,20,30,40,50 * * * * (. $HOME/.bash_profile;
$HOME/hdpjfw_scripts/dbping.pl) $HOME/spool/db_ping.out 21

 



From: Mazhar [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 11, 2006 11:05 AM
To: Beginner
Cc: beginners perl
Subject: Re: Perl Script as a Cron Job

 

 

On 10/11/06, Beginner [EMAIL PROTECTED] wrote: 

On 11 Oct 2006 at 17:14, Mazhar wrote:

 From the help above i created a new perl code and i was successfull in

 running the code by typing the command /scripts/newxxx.pl but the same
is
 not executed by cron i have the cron entry as below

  10 * * * * /scripts/newxxx.pl


This as to be the longest running thread since the great Good 
answer/bad answer debate.

So Mazhar:

1) In who's crontab file have you put this entry?
2) Does this user exist in cron-allow?
3) Do you need to HUP crond to get the cron -rescheduled?
4) Have you any access to the cron log, if so what does that say? 
5) Try printing out the environment variables at the start of the
script incase there is something restricting the job. Something like
the bit below (untested).

foreach my $k (%ENV) {
   print $k - $ENV{$k}\n; 
}


Is there any any output from the command, either from cron or from
the command line? Can we see a sample please and the output from the
above.
Thanx.
Dp.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/ 
http://learn.perl.org/first-response




Dear DP,

 

Your answers to the questions above are here as follows,

 

1) In who's crontab file have you put this entry?

  In Root Login
2) Does this user exist in cron-allow?

 Yes 
3) Do you need to HUP crond to get the cron -rescheduled?

No
4) Have you any access to the cron log, if so what does that say?

How can i found the log file for cron job

 

5) Try printing out the environment variables at the start of the
script incase there is something restricting the job. Something like
the bit below (untested).

foreach my $k (%ENV) {
   print $k - $ENV{$k}\n; 
}

Attached is the file containing the output of the above script (op.log)

 

Regards

Mazhar



RE: Environment variables

2005-02-22 Thread Jason Wozniak
The following works:

use DBI;

my $database;
my $address = [EMAIL PROTECTED];
my %attr;
my $dbh;
my $sid;
open MAIL, |mail $address;
open DBFILE, /u01/app/oracle/check_list.txt;

while ($sid = DBFILE) {
chomp($sid);
$ENV{ORACLE_SID} = $sid;
print $ENV{ORACLE_SID}\n;
$dbh = DBI-connect( dbi:Oracle:$database, , , \%attr)
or print MAIL Could not connect to database: $ENV{ORACLE_SID}
$DBI::errstr\n;
}
close MAIL;


The == was wrong, I couldn't remember the rule, and = produced a result
of 1, ie. I realized now the chomp evaluated to true or 1.  I'm not
masquerading as multiple users, only 1 user externally identified.  This
simply means the user is authenticated by the OS, and not the database.
This also allows the script to be run by any externally identified user.
Once connected normal database security takes over.

The problem now is that the script won't connect to any remote
databases.  I assume this is probably because of the external
identification.  While the oracle user is externally identified on all
servers, I probably have to log in to each server before connecting.


-Original Message-
From: Jay [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 22, 2005 10:41 AM
To: Jason Wozniak
Cc: beginners@perl.org
Subject: Re: Environment variables

On Mon, 21 Feb 2005 16:14:43 -0500, Jason Wozniak [EMAIL PROTECTED]
wrote:
 That's what I thought, but it doesn't work, which is why I tried
system.
 
 The below code:
 
 use DBI;
 
 my $database;
 #my $address = [EMAIL PROTECTED];
 my $address = [EMAIL PROTECTED];
 my %attr;
 my $dbh;
 open MAIL, |mail $address;
 open DBFILE, /u01/app/oracle/check_list.txt;
 
 while (DBFILE) {
 $ENV{ORACLE_SID} == chomp($_);
 print $ENV{ORACLE_SID}\n;
 $dbh = DBI-connect( dbi:Oracle:$database, , , \%attr)
 or print MAIL Could not connect to database: $ENV{ORACLE_SID}
 $DBI::errstr\n;
 }
 close MAIL;
 
 produces the following output:
 
 P01
 P01
 P01
 P01
 P01
 
 The file /u01/app/oracle/check_list.txt contains several different
sids,
 and if I print $_ it is reading them in.
 

Jason,

I'm not sure about this, but it seems to me that ORACLE_SID is
probably set by some system process after you log into the database,
and can't be reset by the user.  Have you tried resetting from the
shell using export (or whatever command is appropriate for your
shell)?  Allowing what you're trying to do--a combination of
passwordless login and masquerading as multiple users--would be a very
insecure.  I certainly wouldn't want my data stored anywhere you could
get away with this.

That said, try actually assigning the variable in the loop.  == is a
test for numerical equality. = is for variable assignment.  Turn on
use strict and use warnings to help you clean up your code; you may
find there aren't as many problems as you think there are.  On the
other hand, the shell has read only variables; this may be one of
them.  Getting this to work may require writing the script to run as
root (or the oracle user) using Perl::IPC or similar to manipulate the
tty/pty info.  You'll probably have to feed it passwords at some
point, though.  A server that just takes your word for your user id is
a server you want to steer very clear of.

--jay



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Environment variables

2005-02-21 Thread Jason Wozniak
Hello,

I'm trying to write a paging script that connects to several
databases in succession, and was attempting to write the script such
that I would not have to hard code any user names, or passwords, by
using an externally identified user.

 

I can connect to the first database in the list ok, but I can't figure
out how to change my ORACLE_SID environment variable, so it simply
reconnects to the same database each time through the loop for every sid
in the file.  I tried setting $ENV{ORACLE_SID} to no effect.  I even
tried using:

 

System(export ORACLE_SID = $_);  and verified $_ was being read in
correctly, as seen below.  Is there no way to modify your shell
environment from within a perl program?  I saw a module called
Env-Bash-0.04, but it doesn't seem to say if you can update an
environment variable, it just makes sure you can access them all.

 

use DBI;

 

my $database;

my $address = [EMAIL PROTECTED];

my %attr;

my $dbh;

open MAIL, |mail $address;

open DBFILE, /u01/app/oracle/check_list.txt;

 

while (DBFILE) {

system(export ORACLE_SID = $_);

$dbh = DBI-connect( dbi:Oracle:$database, , , \%attr)

or print MAIL Could not connect to database: $ENV{ORACLE_SID}
$DBI::errstr\n;

}

close MAIL;

 

 



RE: Environment variables

2005-02-21 Thread Jason Wozniak
That's what I thought, but it doesn't work, which is why I tried system.

The below code:

use DBI;

my $database;
#my $address = [EMAIL PROTECTED];
my $address = [EMAIL PROTECTED];
my %attr;
my $dbh;
open MAIL, |mail $address;
open DBFILE, /u01/app/oracle/check_list.txt;

while (DBFILE) {
$ENV{ORACLE_SID} == chomp($_);
print $ENV{ORACLE_SID}\n;
$dbh = DBI-connect( dbi:Oracle:$database, , , \%attr)
or print MAIL Could not connect to database: $ENV{ORACLE_SID}
$DBI::errstr\n;
}
close MAIL;

produces the following output:

P01
P01
P01
P01
P01

The file /u01/app/oracle/check_list.txt contains several different sids,
and if I print $_ it is reading them in.


-Original Message-
From: Scott Pham [mailto:[EMAIL PROTECTED] 
Sent: Monday, February 21, 2005 4:05 PM
To: Jason Wozniak
Subject: Re: Environment variables

You want use ENV hash (%ENV). The reason why system or `` doesn't work
is due to them being forked off.

$ENV{ORACLE_SID} = whateva;

will do it for you.


On Mon, 21 Feb 2005 15:51:06 -0500, Jason Wozniak [EMAIL PROTECTED]
wrote:
 Hello,
 
I'm trying to write a paging script that connects to
several
 databases in succession, and was attempting to write the script such
 that I would not have to hard code any user names, or passwords, by
 using an externally identified user.
 
 I can connect to the first database in the list ok, but I can't figure
 out how to change my ORACLE_SID environment variable, so it simply
 reconnects to the same database each time through the loop for every
sid
 in the file.  I tried setting $ENV{ORACLE_SID} to no effect.  I even
 tried using:
 
 System(export ORACLE_SID = $_);  and verified $_ was being read in
 correctly, as seen below.  Is there no way to modify your shell
 environment from within a perl program?  I saw a module called
 Env-Bash-0.04, but it doesn't seem to say if you can update an
 environment variable, it just makes sure you can access them all.
 
 use DBI;
 
 my $database;
 
 my $address = [EMAIL PROTECTED];
 
 my %attr;
 
 my $dbh;
 
 open MAIL, |mail $address;
 
 open DBFILE, /u01/app/oracle/check_list.txt;
 
 while (DBFILE) {
 
 system(export ORACLE_SID = $_);
 
 $dbh = DBI-connect( dbi:Oracle:$database, , , \%attr)
 
or print MAIL Could not connect to database: $ENV{ORACLE_SID}
 $DBI::errstr\n;
 
 }
 
 close MAIL;
 




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




regex matching in a nested loop

2004-10-29 Thread Jason Wozniak
I wrote the following as a quick script to find all files on the system
that contain any hard coded passwords for our database.  For testing
purposes I used a file called testing123 in my find string, so as not to
search the entire directory tree for each test.  The problem I'm having
lies in the while loop of my search subroutine.  If I use a for loop to
iterate over all the passwords for each line of the input file, $_ is
overwritten with a numeric value before the matching can take place, so
I can't match the line I'm reading in from the file.  If I get rid of
the for loop and use a counter like $count to iterate through my array,
the file I'm reading often has more lines then the array, so the looping
gets messy, having to reset the counter each time through the array for
each line in the file, and I can't use shift of course, because I need
to iterate through the array multiple times.  So I'm hoping maybe
someone might know a more elegant solution to my problem?
 
#!/usr/bin/perl -w
# Author: Jason Wozniak
# Purpose: To find any hard coded passwords in shell scripts, so they
can be changed.
 
use File::Finder;
my $prod_pass_file = /u01/app/oracle/orausers.prod;
my $test_pass_file = /u01/app/oracle/orausers.test;
my $tmpfile = /u01/app/oracle/hdpjfw_scripts/tempfile.tmp;
my $user;
my $pass;
my $newline;
my $count = 0;
my @passwords;
 
print This program will search for passwords in all regular text files
in the directory specified\n;
print for all passwords listed in either $prod_pass_file or
$test_pass_file\n;
print depending on the database specified\n;
print Enter a directory to search\n;
chomp(my $search_dir = STDIN);
my @file_list = File::Finder-name('testing123')-in($search_dir);
#foreach (@file_list) {
#my $vartest = shift(@file_list);
#print my file list is $vartest\n;
#}
 
print Enter Database SID\n;
chomp(my $database = STDIN);
my $passfile =
($database eq P01) ? $prod_pass_file :
($database eq R01) ? $prod_pass_file :
($database eq T01) ? $test_pass_file :
($database eq X01) ? $prod_pass_file :
($database eq D01) ? $test_pass_file : Invalid;
if ($passfile eq Invalid) {
  print Invalid database SID\n;
  exit;
  }
else {
  open (PASSFILE, $passfile)
or die Could not open $passfile: $!\n;
  }
 
while (PASSFILE) {
  ($user, $pass, $newline) = split( /:/, $_);
  $passwords[$count] = $pass;
  $count++;
  }
 
open (TMPFILE, $tmpfile)
  or die Could not open temporary file: $!\n;
 
foreach $file_list (@file_list) {
search();
  }
 
close TMPFILE;
 
sub search {
  my $file = shift(@file_list);
  open (FILE, $file)
or die Could not read $file: $!\n;
  print $file opened\n;
  while (FILE) {
for (0..$#passwords) {
  if (/$passwords[$_]/) {
print Match found!\n;
print TMPFILE $file
  or die Could not write to file: $!\n;
}
  }
}
}
 
 
Jason Wozniak
Systems Administrator,
Oracle DBA
Henkels  McCoy
985 Jolly Road
Blue Bell PA, 19422
 
 


File::Finder syntax

2004-10-22 Thread Jason Wozniak
I appreciate the earlier tip on using the file finder module, but I'm
having some trouble figuring out the right syntax to do what I want...
 
I can't seem to limit the search to a specified directory or directories
with the maxdepth parameter.  Assuming it has that parameter, as I don't
see it in the documentation.
 
I've tried
 
My @file_list =
File::Finder-type('f')-in('$search_dir')-maxdepth('0');
 
In differing order, but nothing works.
 
Most often I get the error
 
Can't call method maxdepth without a package or object reference.  Am
I correct in assuming that this is telling me File::Finder does not have
a maxdepth option?
 
Without the maxdepth it works just fine, but it searches a lot of
unnecessary files for my purpose, and I can't seem to decipher the docs
well enough to construct what I need.  If anyone can shed some light on
the syntax for this module it would be greatly appreciated.
 
Jason Wozniak
Systems Administrator,
Oracle DBA
Henkels  McCoy
985 Jolly Road
Blue Bell PA, 19422
 
 


qx operator

2004-10-20 Thread Jason Wozniak
Can anyone tell me why
 
@file_list = qx/find $search_dir -name test1.txt/;
 
returns a file list consisting of every file below the value of
$search_dir?
 
Back tics do the same thing.
 
I'm trying to search input file directories for shell scripts with hard
coded passwords and replace them with new values.  Ultimately I'll
probably use something like find / -type f
But I can't seem to get this test to work, so I'll save any questions
regarding the search and replace code for later.  Any suggestions for a
better way to do this than the shell find command would be great as
well.
 
Thanks in advance
 
Jason Wozniak
Systems Administrator,
Oracle DBA
Henkels  McCoy
985 Jolly Road
Blue Bell PA, 19422
 
 


Help with input streams

2003-02-01 Thread Jason Wozniak
I am trying to put together a search and replace program that I can string
together with typical unix shell commands like find, and grep.  However, I
can't get past the initial read of the files I want to process, using the
diamond operator.  I lose the first argument in the list every time.  I put
the below code together for debugging purposes to figure out what's going
on.

while () {  
@files = STDIN; 
} 
$count = scalar @files;   
print There are $count files in the process list!\n;
print @files; 


When I run this with the command:  find /u06 -name glog.log.bak* |
/export/home/jwozniak/fm.pl
It drops the first file in the list for output.

The find command by itself returns 10 files as follows:

/u06/logs/glog.log.bak.3 
/u06/logs/glog.log.bak.4 
/u06/logs/glog.log.bak.1 
/u06/logs/glog.log.bak.2 
/u06/logs/glog.log.bak.5 
/u06/logs/glog.log.bak.6 
/u06/logs/glog.log.bak.7 
/u06/logs/glog.log.bak.8 
/u06/logs/glog.log.bak.9 
/u06/logs/glog.log.bak.10

However the output piped to my perl program drops the first line of input
every time.  For some reason /u06/logs/glog.log.bak.3  does not make it into
the files array?  Regardless of whether if I pipe it in from the find
command or simply read the same data in from a file, and instead the output
from perl is as follows

There are 9 files in the process list!
/u06/logs/glog.log.bak.4  
/u06/logs/glog.log.bak.1  
/u06/logs/glog.log.bak.2  
/u06/logs/glog.log.bak.5  
/u06/logs/glog.log.bak.6  
/u06/logs/glog.log.bak.7  
/u06/logs/glog.log.bak.8  
/u06/logs/glog.log.bak.9  
/u06/logs/glog.log.bak.10 

What am I missing?

Regards,

Jason Wozniak



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Replacing a string in a bunch of files

2003-02-01 Thread Jason Wozniak
I was attempting to produce the file list by piping the output of a find
command.  See my previous email for the problem I'm having with that...

I guess the question I would have is how you are producing the list in
myfiles?

in my case I suppose I could go to the directory that has the glog.log files
and say I wanted to replace bob with charlie I could do this on the command
line without needing to cat a file with a list of the files I wanted to
modify:

#perl -p -i.bak -w -e 's/bob/charlie/g' glog.log*

This is straight from the book Learning Perl pg. 231

If nobody can tell me why, when I redirect the standard output stream of the
find command into my program, I lose the first argument, then I guess I'll
have to do the same thing you did with cat...

It sounds like we are both trying to produce something a little more robust
that could be used in a variety of situations without having to create a new
input file every time.

-Original Message-
From: Richard Fernandez [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 31, 2003 4:01 PM
To: [EMAIL PROTECTED]
Subject: Replacing a string in a bunch of files


I just had a situation where I needed to replace one string with another
string in 200 files.
This is what I came up with, but I know there has to be a better way. Below
is my code.

myfiles contains a list of the files I need to scrub, one per line.

---8-8---
#!/usr/local/bin/perl -w
use strict;
$|++;


my @files = `cat myfiles` or die;
for (@files) {

chomp;
push @ARGV, $_;
}


$^I = .bak;   # Got this from a previous message; thanks Peter!
while () {

s#/u01/app/webMethodsFCS#/u02/app/webMethodsFCSclone#g;
print;

}
-8--8---

Seems to me there should be a way to provide the filenames on the command
line
w/o having to read the list into an array first, but I tried using xargs
(this is unix) and a couple
of other things but couldn't figure it out.

Thanks for the help!


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




FW: Help with input streams

2003-02-01 Thread Jason Wozniak
Well as a followup to my own email..

This works where the while loop does not, so at least now I've found a way
to pipe the output of the unix find command into my program :)  I'm still
not sure I understand why though...

chomp(@files = );

I had also tried:

while () {
@files = $_;
}

but that had the same problem, so somehow the while loop causes the first
argument to be dropped from the input stream?

  -Original Message-
 From: Jason Wozniak  
 Sent: Friday, January 31, 2003 3:05 PM
 To:   '[EMAIL PROTECTED]'
 Subject:  Help with input streams
 
 I am trying to put together a search and replace program that I can string
 together with typical unix shell commands like find, and grep.  However, I
 can't get past the initial read of the files I want to process, using the
 diamond operator.  I lose the first argument in the list every time.  I
 put the below code together for debugging purposes to figure out what's
 going on.
 
 while () {  
 @files = STDIN; 
 } 
 $count = scalar @files;   
 print There are $count files in the process list!\n;
 print @files; 
 
 
 When I run this with the command:  find /u06 -name glog.log.bak* |
 /export/home/jwozniak/fm.pl
 It drops the first file in the list for output.
 
 The find command by itself returns 10 files as follows:
 
 /u06/logs/glog.log.bak.3 
 /u06/logs/glog.log.bak.4 
 /u06/logs/glog.log.bak.1 
 /u06/logs/glog.log.bak.2 
 /u06/logs/glog.log.bak.5 
 /u06/logs/glog.log.bak.6 
 /u06/logs/glog.log.bak.7 
 /u06/logs/glog.log.bak.8 
 /u06/logs/glog.log.bak.9 
 /u06/logs/glog.log.bak.10
 
 However the output piped to my perl program drops the first line of input
 every time.  For some reason /u06/logs/glog.log.bak.3  does not make it
 into the files array?  Regardless of whether if I pipe it in from the find
 command or simply read the same data in from a file, and instead the
 output from perl is as follows
 
 There are 9 files in the process list!
 /u06/logs/glog.log.bak.4  
 /u06/logs/glog.log.bak.1  
 /u06/logs/glog.log.bak.2  
 /u06/logs/glog.log.bak.5  
 /u06/logs/glog.log.bak.6  
 /u06/logs/glog.log.bak.7  
 /u06/logs/glog.log.bak.8  
 /u06/logs/glog.log.bak.9  
 /u06/logs/glog.log.bak.10 
 
 What am I missing?
 
 Regards,
 
 Jason Wozniak
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]