Sponsored Content
Top Forums Shell Programming and Scripting Script to find available IP address Post 302969101 by nemesis911 on Friday 18th of March 2016 04:39:09 AM
Old 03-18-2016
hmmm...it doesn't work, this is awk science fiction for me. Reading trough man to try figure out

Code:
#!/bin/bash

NETSTAT=$(netstat -ntp | awk '{ print $4 }' | grep -v "127.0.0.1" | cut -d ":" -f1 | grep "^[0-9]")
APACHE=$(grep -R "<VirtualHost " /etc/apache2/* | cut -d ":" -f2 | cut -d " " -f2 |  cut -d ">" -f1 | grep "^[0-9]")

USE=("${NETSTAT[@]}\n${APACHE[@]}")
USED=$( printf "${USE[@]}" | sort | uniq)
IFCONFIG=$(ifconfig -a | grep -v "127.0.0.1" | grep addr | awk '{ print $2 }' | cut -d ":" -f2 | grep "\.")


awk '{
    c=split(ENVIRON["USED"], used, "\n");
    d=split(ENVIRON["IFCONFIG"], ifconfig, "\n");
 
    for (i=1; i<=c; i++) {use[used  [i]]=used[i]; all[used[i]]=used[i];}
    for (i=1; i<=d; i++) {ifc[ifconfig[i]]=ifconfig[i]; all[ifconfig[i]]=ifconfig[i];}

    for (i in all) {
       if (i in ifc && i in use) common[i]=i;
       if (i in ifc && !(i in use)) ifc_only[i]=i;
       if (!(i in ifc) && i in use) use_only[i]=i;
    }
 
    for (i in common  ) print "Common IPs      : " i;
    for (i in use_only) print "In APACHE only  : " i;
    for (i in ifc_only) print "In IFCONFIG only: " i;
}'


Last edited by nemesis911; 03-18-2016 at 06:03 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

Find the IP address that a telnet session uses

Hello Experts, Happy New Year to all of us, In AIX 4.3.3 I am trying to figure out how is possible to find out the IP address that a telnet session - user uses to login in to host machine. My objective is by finding the login IP address to allow the user to login or not. All users uses the... (6 Replies)
Discussion started by: sszago
6 Replies

2. UNIX for Dummies Questions & Answers

How to find i.p address of our server

I don't have root access. How do I find i.p address of our sun server? Thanks. (4 Replies)
Discussion started by: vpotluri
4 Replies

3. UNIX for Advanced & Expert Users

Find LAN Address

Hi, I am wondering how I can find the network address under following situation. Things available: 1. An active network drop without knowing any details about the network. 2. I have windows, Linux, and Solaris machine available to use. Things to achieve: 1. Find out the... (5 Replies)
Discussion started by: jiashi2
5 Replies

4. HP-UX

how to find the IP address of a printer

I'm trying to find the IP address of a print queue. I tried this, but nada. cat /etc/hosts | lp -d lp01 Looked in the hosts file but it's not there (2 Replies)
Discussion started by: abNORMal
2 Replies

5. UNIX for Advanced & Expert Users

Find IP Address of a Printer Q in Hp-Unix

Could anyone help me to identify the IP address of a printer queue with its printer queue name information . (1 Reply)
Discussion started by: lenin1985
1 Replies

6. AIX

How to find the router IP address

How to find the router IP address (2 Replies)
Discussion started by: AIXlearner
2 Replies

7. IP Networking

How to find the IP address of a computer that I am connected to?

Hi all, One of my computers (an iMac) was recently stolen, but I have been able to connect to it over the internet through Apple's 'back to my mac' feature. In order for the police to find these people they need to know the IP address of the stolen computer. I suspect that I will have find the... (6 Replies)
Discussion started by: RJFoulston
6 Replies

8. Red Hat

How to find file which stores IP address

Hi all, I am new to this forum and this is my first question :). Using Red hat Linux.I tried to find file which stores IP address based on different helps given in this forum but did not get success. Here is the system details: -bash-3.2$ lsb_release -a LSB Version: ... (2 Replies)
Discussion started by: Barkha
2 Replies

9. UNIX for Dummies Questions & Answers

How to Find another IP address

Hi Guys, I want to find another(Local host) machine IP address from my machine.. We are all connected in the same server, I mean same LAN. What i done is Connected with that user machine using SSH and SU.. After that i used IFCONFIG but it shows my Ip address. Can not able to get the... (8 Replies)
Discussion started by: Adhi
8 Replies

10. Shell Programming and Scripting

HELP simple script to find e-mail address on a file

Hello guys, im new to to unix/linux i have a text file like this: person1@test.com iisiiasasas person2@test.com 123w2 3233 sajsja person3@test.com jsajjsa sajsjasaj person4@test.com I want to extract only e-mail address and get rid of all other stuff, i want an output like this ... (4 Replies)
Discussion started by: RazorMX
4 Replies
AMANDA-SCRIPTS(7)						    Miscellanea 						 AMANDA-SCRIPTS(7)

NAME
amanda-scripts - Configuring and using the Script API DESCRIPTION
The Script API is a flexible system for invoking user-supplied scripts at various points in the execution of Amanda. This manual page describes the operation and configuration of the API. For help writing Script API scripts, see http://wiki.zmanda.com/index.php/Script_API. SCRIPTS
This section lists the scripts included with Amanda, see the individual man page for instructions on using them. For complete How-To information, consult the Amanda wiki at http://wiki.zmanda.com. o amzfs-snapshot(8), - create/destroy zfs snapshot. o script-email(8), - send email. Script properties work just like application properties: they are insensitive to case, and - (dash) and _ (underscore) may be used interchangeably. SCRIPTS OUTPUT PROPERTY
A pre-dle-amcheck, pre-dle-estimate or pre-dle-backup executed on the client can output property on stdout that are sent to the application. If the output line matches "PROPERTY str1 str2", Amanda sets a property called "str1" by the value of "str2", that property is sent to the application. SEE ALSO
amanda(8), amanda.conf(5) The Amanda Wiki: : http://wiki.zmanda.com/ AUTHORS
Jean-Louis Martineau <martineau@zmanda.com> Zmanda, Inc. (http://www.zmanda.com) Dustin J. Mitchell <dustin@zmanda.com> Zmanda, Inc. (http://www.zmanda.com) Amanda 3.3.1 02/21/2012 AMANDA-SCRIPTS(7)
All times are GMT -4. The time now is 08:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy