Perl script to check uname options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script to check uname options
# 1  
Old 04-22-2012
Perl script to check uname options

I am trying to read the /etc/security/limits.conf file to match with my specifications.

Specification should match below :
Code:
nofile=131072
noproc=131072
memlock=3500000

I have written a perl script to read the file:


Code:
#!/usr/bin/perl
$FILE1 = "/home/sriram/perl_scripts/limits.conf";
open(FILE, "$FILE1"); 
# or die("Could not open limits.conf file.");
while (<FILE>){
chomp;
foreach $word (split)
{
print "$word \n";
}
}
close(FILE);



I am not sure how to check for matching values as stated in specification.

Any help appreciated..
Moderator's Comments:
Mod Comment Please use code tags instead of quote tags

Last edited by Scrutinizer; 04-23-2012 at 04:48 AM.. Reason: code tags
# 2  
Old 04-22-2012
Wrench

Code:
#!/usr/bin/perl

$LimitsFile = "/home/sriram/perl_scripts/limits.conf";

my $RefValue = {
                            nofile => 131072,
                            noproc => 131072,
                            memlock => 3500000,
                         } ;

open(FILE, '<',"$FILE1") or die("Could not open limits.conf file.");
while (<FILE>)
{
      chomp;
      foreach my $line ($_)
     {
          next if ( $_ !~ /^(nofile|noproc|memlock)=$/ ) ; 
          my($key,$val) = split(/=/,$_,2) ; 
          print "Error MESSAGE\n" if ($RefValue->{$key} != $val )  ;
     }
}
close(FILE);

I have one query though, why perl script ? i mean functionality you are looking after can be achieved easily in Bash/Ksh shell as well
# 3  
Old 04-23-2012
It is a lot easier with awk

Code:
#! /bin/sh

awk '
NR==FNR {
        split($0, a, "=")
        var[a[1]]=a[2]
        next
}
NR!=FNR && $0!~/^#/ && NF==4 {
        if ( $3 in var && var[$3]==$4) {
                print
        }
}
' /home/sriram/perl_scripts/limits.conf /etc/security/limits.conf

If you want perl, just run 'a2p' to convert it to perl. BTW, there is no 'noproc'. It should be 'nproc'.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell/perl script to check for files

Hi, I am trying to write a script for following scenario: I have a list of countries from where I receive files...eg. (Indonesia, Thailand, Australia...etc) For each country, I have a list of files that they send. IND -- a,b,c TH -- p,q,r AU -- x,y,z The path for these files could... (2 Replies)
Discussion started by: neil.k
2 Replies

2. Shell Programming and Scripting

How to check if printer is out of paper using perl script ?

Hello, I need to chack if the printer is out of paper, and send message to operator. I need to do this from perl script. The printer have mechanism to check if it have paper. However, the cups does not report "printer out of paper" when I remove the paper, and try to print. Is there any... (1 Reply)
Discussion started by: +Yan
1 Replies

3. Shell Programming and Scripting

Help with Perl script that can check a URL and notifiy when changes occur

I'm a scripting newbie and I'm trying to learn. No better way than being assigned a project. So basically, I'm trying to come up with a script that can periodically check a URL and then notify when changes occur to the file. So what I'm thinking is that I need to devise a PERL script that... (3 Replies)
Discussion started by: adam1mc
3 Replies

4. Shell Programming and Scripting

Run perl script, with command-line options

Hello everyone, I have a perl script which takes various command line options from user like : test.pl -i <input_file> -o <output_file> -d <value> -c <value> Now I have multiple input files in a directory: <input_file_1> <input_file_2> <input_file_3> <input_file_4> ..... .... ...... (6 Replies)
Discussion started by: ad23
6 Replies

5. Shell Programming and Scripting

perl check email script not seeing attachment

The following script does pull the sender and Subject of the email but it is not seeing the attachment name. I know there is an attachment. I line in red SHOULD pull the filename out. this line is in the message: Content-Disposition: attachment; filename="Picture 243.jpg" ... (1 Reply)
Discussion started by: Ikon
1 Replies

6. Shell Programming and Scripting

Please check perl script

#!/usr/local/bin/perl #$path = perl; #use File::stat; use Time::localtime; sub ExampleFiles{ $today = time; $today -= $today % 86400; $return_value = 0; $mtime = (stat("$_")) || die "cannot stat file $!"; $size = (stat("$_")); # size in... (3 Replies)
Discussion started by: ellechim
3 Replies

7. Shell Programming and Scripting

Perl Variable Check Script

I am working on a perl script that is used to update a list of hosts to a certain file but I am having an issue when I try to perform a check to make sure the user enters valid information. The following is what I have currently written for the script: IPINPUT: print "Enter IP Address: ";... (2 Replies)
Discussion started by: Takau
2 Replies

8. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

9. UNIX for Advanced & Expert Users

how to check the options used in mount command

hi , I want to check that what options i have used in mount command ... or what switches i have used while mounting .. is there any method to check ? thanks (1 Reply)
Discussion started by: tahir23
1 Replies

10. UNIX for Dummies Questions & Answers

executing uname through shell script

Hi, I need to write a shell script that executes the command uname -a the output i get is of the format : FreeBSD test.trial.machine.com 4.5-RELEASE FreeBSD 4.5-RELEASE #0: Mon Jan 28 14:31:56 GMT 2000 tester@builder.freebsdmall.com:/usr/src/sys/compile/GENERIC i386 (this is all in a... (3 Replies)
Discussion started by: HIMANI
3 Replies
Login or Register to Ask a Question