Sponsored Content
Top Forums Shell Programming and Scripting Perform an action if certain text exist in output (PERL) Post 302777907 by in2nix4life on Friday 8th of March 2013 04:21:09 PM
Old 03-08-2013
Corona speaks the truth. If you're going to use a language, go all in and use if fully. I'm surrounded by system admins that write scripts in such a way. Better to adapt the good habits early on. Here's an example of what you're doing in pure Perl (with the help of a couple of modules):

Code:
#!/usr/bin/perl
#

use strict;
use Net::DNS;
use Net::Ping;

# create dns instance
my $ptr = Net::DNS::Resolver->new();

# create ping instance
my $do_ping = Net::Ping->new();

# prompt for ip address to lookup
print "IP Address -> ";
chomp(my $ip = <STDIN>);

# format ip address for reverse dns lookup
my $dns_suffix = ".in-addr.arpa";
my $reverse_ip = join('.', reverse(split /\./, $ip)) . $dns_suffix;

# perform dns lookup
my $response = $ptr->query($reverse_ip, 'PTR');
if($response) {
    print "PTR Record Found For $ip\n";
} else {
    print "PTR Not Found For $ip\n";
    print "Checking For Response From $ip\n";
    if($do_ping->ping($ip)) {
        print "$ip Is Responding To Pings\n";
    } else {
        print "$ip Is Not Responding To Pings\n";
    }
}

# done
exit(0);

 

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
ALL-KNOWING-DNS(1p)					User Contributed Perl Documentation				       ALL-KNOWING-DNS(1p)

NAME
all-knowing-dns - Tiny DNS server for IPv6 Reverse DNS SYNOPSIS
all-knowing-dns [--configfile <path>] [--querylog] DESCRIPTION
AllKnowingDNS provides reverse DNS for IPv6 networks which use SLAAC (autoconf), e.g. for a /64 network. The problem with IPv6 reverse DNS and traditional nameservers is that the nameserver requires you to provide a zone file. Assuming you want to provide RDNS for a /64 network, you have 2**64 = 18446744073709551616 different usable IP addresses (a little less if you are using SLAAC). Providing a zone file for that, even in a very terse notation, would consume a huge amount of disk space and could not possibly be held in the memory of the computers we have nowadays. AllKnowingDNS instead generates PTR and AAAA records on the fly. You only configure which network you want to serve and what your entries should look like. OPTIONS
--configfile=path Use path instead of /etc/all-knowing-dns.conf as configuration file. --querylog Enable logging every query to stdout (for debugging). CONFIGURATION FILE (/etc/all-knowing-dns.conf) The configuration file is wonderfully simple: # Configuration file for AllKnowingDNS v1.3 listen 79.140.39.197 listen 2001:4d88:100e:1::3 # RaumZeitLabor network 2001:4d88:100e:ccc0::/64 resolves to ipv6-%DIGITS%.nutzer.raumzeitlabor.de with upstream 2001:4d88:100e:1::2 # Chaostreff network 2001:4d88:100e:cd1::/64 resolves to ipv6-%DIGITS%.treff.noname-ev.de This example contains all configuration directives. Let's go over them one by one: listen address Listens on the given address (IPv4 and IPv6 is supported) on port 53. network network Specifies that queries for PTR records within the given network should be answered (any query for an unconfigured network will be answered with NXDOMAIN). You need to specify at least the resolves to directive afterwards. resolves to address Specifies the address to which PTR records should resolve. The address needs to contain %DIGITS% exactly once. When answering AAAA queries, %DIGITS% will be parsed and converted back to an IPv6 address. Example: network 2001:4d88:100e:ccc0::/64 resolves to ipv6-%DIGITS%.nutzer.raumzeitlabor.de Example query: The PTR query 2001:4d88:100e:ccc0:216:eaff:fecb:826 will resolve to ipv6-0216eafffecb0826.nutzer.raumzeitlabor.de with upstream address Before answering a PTR query for this network, AllKnowingDNS will ask the DNS server at address first, appending .upstream to the query. Example: network 2001:4d88:100e:ccc0::/64 resolves to ipv6-%DIGITS%.nutzer.raumzeitlabor.de with upstream 2001:4d88:100e:1::2 Example query: The PTR query 2001:4d88:100e:ccc0:219:dbff:fe43:2ec5 will make AllKnowingDNS ask for 5.c.e.2.3.4.e.f.f.f.b.d.9.1.2.0.0.c.c.c.e.0.0.1. 8.8.d.4.1.0.0.2.ip6.arpa.upstream. at 2001:4d88:100e:1::2 and relay the answer, if any. DELEGATING ZONES
This section shows you how to delegate a zone in BIND9 or any DNS server with a compatible zone file syntax. To use AllKnowingDNS, you need to delegate the appropriate .ip6.arpa zone for your network and one regular domain. REVERSE DELEGATION (.ip6.arpa) $ORIGIN . $TTL 604800 ; 1 week e.0.0.1.8.8.d.4.1.0.0.2.ip6.arpa IN SOA infra.in.zekjur.net. hostmaster.zekjur.net. ( 20 ; serial 604800 ; refresh (1 week) 86400 ; retry (1 day) 2419200 ; expire (4 weeks) 604800 ; minimum (1 week) ) NS libri.sur5r.net. NS infra.in.zekjur.net. ; net for RaumZeitLabor 0.c.c.c.e.0.0.1.8.8.d.4.1.0.0.2.ip6.arpa. IN NS ipv6-rdns.zekjur.net. FORWARD DELEGATION (.nutzer.raumzeitlabor.de) $TTL 6h raumzeitlabor.de IN SOA ns1.jpru.de. hostmaster.jpru.de. ( 2012030701 3h 30m 7d 1d ) IN NS ns1.jpru.de. IN NS ns2.jpru.de. IN A 195.49.138.121 IN MX 10 rzl.uugrn.org. IN MX 20 up.uugrn.org. IN MX 50 mail.uugrn.org. IN MX 100 rzl.uugrn.org. nutzer.raumzeitlabor.de. IN NS ipv6-rdns.zekjur.net. VERSION
Version 1.3 AUTHOR
Michael Stapelberg, "<michael at stapelberg.de>" LICENSE AND COPYRIGHT
Copyright 2012 Michael Stapelberg. This program is free software; you can redistribute it and/or modify it under the terms of the BSD license. perl v5.14.2 2012-03-28 ALL-KNOWING-DNS(1p)
All times are GMT -4. The time now is 02:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy