Sponsored Content
Full Discussion: Need help wrt Perl scripting
Top Forums Shell Programming and Scripting Need help wrt Perl scripting Post 302908965 by bharats08 on Saturday 12th of July 2014 06:35:10 AM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
All times are GMT -4. The time now is 05:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy