Need help wrt Perl scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help wrt Perl scripting
# 1  
Old 07-12-2014
Question Need help wrt Perl scripting

I need some assistance with respect to perl script for checking files.

I have near about 100 path for which I need to check whether the give path does have file or not .
I have created a script but it is not working the way I want
My requirement is :-
Script should check if the file exist or not , if yes it should print “asking us to check whether batch is running or not “ else nothing . apart from that if files exist is more than 5 than it should trigger us an email


My script is able to search the path and able to check but the counter which has been used is not getting incremented if the file exist or not .


script which i have created :-
Code:
#!/bin/perl 
$filename = 'D:/Exploit/file_test/path_files.txt'; 

open (FILE, "$filename") or die "couldn't open the file!"; 
open (NOEMPTYFILE, '>D:/Exploit/file_test/data1.txt'); #open the temp file1 in write mode 
open (EMPTYFILE, '>D:/Exploit/file_test/data2.txt'); #open the temp file2 in write mode 

while (<FILE>) 
{ 
      chomp; 
      ($path1, $schedname) = split("\t");   
      print $path1;                                # To print the directory name in screen
        opendir DIR, $path1 or die "cannot open dir $path1:$!"; 
        readdir DIR; # reads . 
        readdir DIR; # reads .. 
           if (readdir DIR)        #If the directory is non empty then only it will go inside

            {       
                   print NOEMPTYFILE "$path1\n"  #Write the name of non empty directory in data1

                @files = glob('$path1*.txt');  # To get the text files
                $a = 0; 
                foreach $file (@files) 
               { 
                       $a++; 
                       print NOEMPTYFILE  "$file\n";   #Write the file names

               } 
               print "Total in directory $path1 is: $a\n";   # To print the output in screen

   if ($a > 2) 
  { 

  print NOEMPTYFILE  " Number of text files present in the $path1 directory is: $a , Kindly check $schedname \n.";  #When more than two text files are present

    } 
   else 
   { 
    print NOEMPTYFILE  " Number of text files present in the $path1 directory is: $a , Kindly check $schedname \n.";  #When text files are less than 2
   }

           } # End of if

else                              #If the directory does not contain the third file it will come to else loop
{ 
print EMPTYFILE  " $path1 directory is empty, Kindly check $schedname \n.";  # Write the empty directory name in data 2
}             # Reading is complete for the current directory

closedir DIR;  # Closes the current directory and opens another directory

}   # End of  While

close (NOEMPTYFILE); 
close (EMPTYFILE);


Output coming in data1 will have those path where file exist and the same file will be sent as an email .


Could you please assist me what needs to be corrected in order to achive below objective

1) script should check all the path mention in file "path_file.txt".
2) if any of the path mention has files , it should write it in to data1.txt with DIR
3) after completion of entire script i want that file to be sent as an email
4) if their are not files in any of the path data1.txt should not be created .


please advice .

Last edited by Franklin52; 07-12-2014 at 03:52 PM.. Reason: Please use code tags
# 2  
Old 07-13-2014
Is this a homework assignment?
# 3  
Old 07-13-2014
Smilie No not at all
We use TWS to support our customer and most of time whenever we have files in place jobs which are schedule to process doesn't work , I would not say most of the time but very frequent .

So we came up with an idea of having a script in place which will check the Path and if we have more than 5 files in place it should trigger an alert via sending an email. Once email is send we have support team who check respective job , whether its in execution or not , if not they will reach us . In few occasion this has really help us to identify the problem before customer reaches us . That's what we been paid for.

I have created a script which just checks 1 path and it works fine. if the same thing needs to be implemented than I have to created approx 100 plus script to check different path . to overcome I have created a script which I have posted, it check all the path mention in the file.
Master server is a windows and it only support Perl and I have very little experience in PERL. The script which I have worked on is able to identify everything but only problem is it is not getting incremented.
I would have used the same script and would have published the output which is getting generated in data1.txt.

Reason for this post is if someone would come up with different idea or expertise which I was missing in my script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

GTK C development; question/concern wrt gtk_dialog_run

I'm new to GTK development, so I've been going through the examples just to capture the basics. I've done a lot of Unix GUI development before, but it was all Xt/Motif stuff. So, the GTK scheduler is something new to me. That said, I was going through the color selection example here, and was... (8 Replies)
Discussion started by: DreamWarrior
8 Replies

2. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

3. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

4. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

5. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

6. Post Here to Contact Site Administrators and Moderators

Please review this thread wrt o/p

https://www.unix.com/unix-dummies-questions-answers/117633-top-output-specific-process-file-2.html (2 Replies)
Discussion started by: methyl
2 Replies

7. Shell Programming and Scripting

Compare 2 huge files wrt to a key using awk

Hi Folks, I need to compare two very huge file ( i.e the files would contain a minimum of 70k records each) using awk or sed. The comparison needs to be done with respect to a 'key'. For example : File1 ********** 1234|TONY|Y75634|20/07/2008 1235|TINA|XCVB56|30/07/2009... (13 Replies)
Discussion started by: Ranjani
13 Replies

8. Shell Programming and Scripting

Problems in sorting wrt Date

Hi, Please help me in the below: I am trying to sort it in date order but I am failing somewhere L . Can anyone please help me on this? Your help is most appreciated on this. $ autorep -j EDSPME% | grep ' OI' | grep -v '^ ' |awk '{print $4 " " $1}'| sort -r -t/ -k 3 -k 2 -k 1 04/29/2008... (1 Reply)
Discussion started by: christineida
1 Replies

9. Programming

WRT counter show me that line from a txt file

Hello Experts, I am beginner to C language.. I know I am making a simple mistake but I dont know what the problem here #include <stdlib.h> #include <stdio.h> int main(void) { FILE* fh; char s; int i; int count =10; double a,b; printf("COUNT=... (6 Replies)
Discussion started by: user_prady
6 Replies

10. Cybersecurity

Web site Security WRT MySql - how set up?

Hiya all, Newbie here - hope you can help Trying to set up a login authorization on my website. Reading away - it says works well with MySql database. Apache book goes onto to explain how to install Mysql etc.... But How do I set up the login page tho? Please assist Cheers... (5 Replies)
Discussion started by: marty 600
5 Replies
Login or Register to Ask a Question