Sponsored Content
Top Forums Shell Programming and Scripting Perform an action if certain text exist in output (PERL) Post 302777897 by spartan22 on Friday 8th of March 2013 03:36:52 PM
Old 03-08-2013
I figured out a solution in Perl. it's a little sloppy but it gets the job done.

Code:
#!/usr/bin/perl
use warnings;
$seperator = "===============================================\n";
$ping = "100%";
open MYFILE, ">ips.txt" or die $!;
while (defined($line = <>)) {
	print "$line\n";
	$line =~ s/^\s+|\s+$//g;
	chomp($line);
	my $nslookupOut = `nslookup $line`;
	print $nslookupOut;
		if ($nslookupOut =~ /NXDOMAIN/) {
    my $pingOut = `ping -c 1 -w 1.0 $line`;
	print $pingOut;
    if ($pingOut =~ /$ping/) {
		print MYFILE "$line is available.\n"
		}
	}
}
close MYFILE;
print $seperator;
if (open MYFILE, "ips.txt") {
	chomp(my @lines = <MYFILE>);
	foreach (@lines) {
		print "$_\n";
		}
	}

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perform action file name written to the pipe

Hello, I have a script that monitors files uploaded via ftp. After a successful upload, the file name is written to the pipe. There is another program that reads this pipe and allows automatically run any program or script ( say test.sh ) to process the newly uploaded file. cat test.sh... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies

2. Shell Programming and Scripting

Need help in searching 2 files for strings then perform an action

I have 2 files. I basically want to search both of them to see if the 1st column ($1) matches and if it matches then check to see if the 2nd column ($2) matches, then execute some code showing the results of the matches. File 1: AAA 123 misc blah BBB 456 CCC 789 File 2: ... (2 Replies)
Discussion started by: streetfighter2
2 Replies

3. Shell Programming and Scripting

How to perform action on newest line in log using tail?

I don't quite know what I'm doing, so this simple script is proving a challenge. Here is some pseudo code that doesn't work yet: if tail -1 "WORKING.txt" >/dev/null | egrep "^NMBR=*" > /dev/null then curl -k 'http://www.myserver.com/log.cgi?input=$?' echo "hi there" fi Purpose:... (3 Replies)
Discussion started by: dihewidd
3 Replies

4. Shell Programming and Scripting

create dir in main &subdirs,perform action

Hi, I have one dir which has N subdirs.For ex: /home/user/Project_Src /home/user/Project_Src/Dir_A /home/user/Project_Src/Dir_A/subdir/sub_dir2 /home/user/Project_Src/Dir_A/subdir/sub_dir3 /home/user/Project_Src/Dir_B /home/user/Project_Src/Dir_B/Build i want to create a folder with... (2 Replies)
Discussion started by: dragon.1431
2 Replies

5. Shell Programming and Scripting

shell script - search a file and perform some action

hi, i have a service on unix platform, it will generate traces in a particular folder i want to check using shell script if traces exist, then perform some action else continue to be in loop. filename is service.tra can you please help? thanks (4 Replies)
Discussion started by: gauravah
4 Replies

6. Shell Programming and Scripting

Perl: One action if an element doesn't exist in array

Hello, I want to run one (not multiple) action if an element doesn't exist in array. for example: @array = (1..10); foreach $el (@array) { if ($el != 11) { print "number not found\n"; } } the output of this simple script: number not found (3 Replies)
Discussion started by: ahmed_zaher
3 Replies

7. Shell Programming and Scripting

How to access files from different directories and to perform search action in those files?

Hi, I want to access files from different directories (for example: /home/dir1/file1 , /home/dir2/file2 ...) Like this i have to access these files(file1, file2...). (3 Replies)
Discussion started by: bangarukannan
3 Replies

8. Shell Programming and Scripting

Script to monitor for new file with ext .err and size > 0 bytes and perform a action or command

Hi All, I need to create a script to monitor a dir for new files with ext .err and also it should b a non empty files. and perform a action or command . We have a new ETL application that runs on a linux server, every times a etl fails it creates a .err file or updates the existing .err... (4 Replies)
Discussion started by: MAKHAN
4 Replies

9. Shell Programming and Scripting

awk script to perform an action similar to vlookup between two csv files in UNIX

Hi, I am new to awk/unix and am trying to put together an awk script to perform an action similar to vlookup between the two csv files. Here are the contents of the two files: File 1: Date,ParentID,Number,Area,Volume,Dimensions 2014-01-01,ABC,247,83430.33,857.84,8110.76... (9 Replies)
Discussion started by: Prit Siv
9 Replies
ARES_PARSE_PTR_REPLY(3) 				     Library Functions Manual					   ARES_PARSE_PTR_REPLY(3)

NAME
ares_parse_ptr_reply - Parse a reply to a DNS query of type PTR into a hostent SYNOPSIS
#include <ares.h> int ares_parse_ptr_reply(const unsigned char *abuf, int alen, const void *addr, int addrlen, int family, struct hostent **host); DESCRIPTION
The ares_parse_ptr_reply function parses the response to a query of type PTR into a struct hostent. The parameters abuf and alen give the contents of the response. The parameters addr, addrlen, and family specify which address was queried for; they are not used to verify the response, merely used to fill in the address of the struct hostent. The resulting struct hostent is stored in allocated memory and a pointer to it stored into the variable pointed to by host. It is the caller's responsibility to free the resulting host structure using ares_free_hostent(3) when it is no longer needed. RETURN VALUES
ares_parse_ptr_reply can return any of the following values: ARES_SUCCESS The response was successfully parsed. ARES_EBADRESP The response was malformatted. ARES_ENODATA The response did not contain an answer to the query. ARES_ENOMEM Memory was exhausted. SEE ALSO
ares_gethostbyaddr(3), ares_free_hostent(3) AUTHOR
Greg Hudson, MIT Information Systems Copyright 1998 by the Massachusetts Institute of Technology. 25 July 1998 ARES_PARSE_PTR_REPLY(3)
All times are GMT -4. The time now is 11:33 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy