Sponsored Content
Top Forums Shell Programming and Scripting print ip to hostname with array Post 302348756 by daPeach on Saturday 29th of August 2009 01:49:00 PM
Old 08-29-2009
PHP

Here's what can be written without having touched perl for a long once time: a good bad example
Code:
#!/usr/bin/perl

@ipaddr = ("192.1.168.2","172.25.1.13","129.1.2.5");

foreach $ipaddr(@ipaddr){
   $i = $i + 1;
   %myhost->{"$ipaddr"} = "Machine $i";

   $val = %myhost->{$ipaddr};
   print "IP $ipaddr has name $val\n";
}

I wish I could strike that, just to make sense at tyler_durden's post, otherwise I'd be glad to erase it.

Last edited by daPeach; 08-29-2009 at 06:47 PM.. Reason: the given code is an horror of errors
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Solaris - unknown hostname - how can I change hostname?

Hello, I am new to Solaris. I am using stand alone Solaris 10.0 for test/study purpose and connecting to internet via an ADSL modem which has DHCP server. My Solaris is working on VMWare within winXP. My WinXP and Solaris connects to internet by the same ADSL modem via its DHCP at the same... (1 Reply)
Discussion started by: XNOR
1 Replies

2. Shell Programming and Scripting

Print the first four characters of hostname

Hey, I'm trying to print the first four characters of the hostname of a computer. I can get it from using: hostname -s | sed 's/...........$//'" but this is when I know how many characters are in the computer name. I dont understand why some like: hostname -s | sed '/..../p' wont... (7 Replies)
Discussion started by: yxian
7 Replies

3. Shell Programming and Scripting

Print Array function

The code below prints outs each array element, but it always says the array length is 1 even though its not. What am i doing wrong? function printArray(){ #here should check if it is an array and that an arg exits echo "Priting array" myarr="${@}" echo... (2 Replies)
Discussion started by: chrisjones
2 Replies

4. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

5. Shell Programming and Scripting

Print @array content to a file

Hi, as the title, I have an array @f_lines with gene information in it. How can I put the content of @f_lines into a file so that I can read it? I tried this: open(OUTPUT, "file"); # put gene information in this file; @f_lines = ("gene1", "gene2", "gene3"...); # gene information; print... (3 Replies)
Discussion started by: lyni2ULF
3 Replies

6. UNIX for Dummies Questions & Answers

How To Print Array in awk?

Hello, May i please know how do i print the array using awk script. I am using below shell script to start with but not working. #!/bin/bash LOADSTATUS="Line 0" LOADSTATUS="Line 1" LOADSTATUS="Line 2" LOADSTATUS="Line 3" LOADSTATUS="Line 4" awk ' BEGIN { Your File Load Status }... (1 Reply)
Discussion started by: Ariean
1 Replies

7. UNIX for Advanced & Expert Users

Hostname -f hostname: Unknown host

deleted (0 Replies)
Discussion started by: hce
0 Replies

8. Shell Programming and Scripting

Not getting array in .awk file and print it

I have test.sh file as below : set -A IDARR $ID echo | awk -f test.awk -v TempArr="${IDARR }" I have test.awk file as below : BEGIN { Flag = 1; } { print "Hello"; for(i in TempArr) { print i; } } (9 Replies)
Discussion started by: nes
9 Replies

9. Shell Programming and Scripting

How to print last character of hostname and assign to a variable ?

Hi How to pass echo output to a variable ? Does below awk command will get the last character of hostname and assign to a variable - "svr" ? svr=$( echo `hostname` | awk '{print substr($0,length,1)}' ) Thanks. Please use CODE tags when dsplaying code segments, sample input, and sample... (7 Replies)
Discussion started by: Lim
7 Replies

10. Shell Programming and Scripting

awk remote multiple hosts print remote hostname and output

Hi all, i'm trying to gether multiple pattern on remote hosts, and trying to print hostname and the pattern, ssh remoteserver1 -C 'hostname 2>&1;cat /var/log/server1.log | awk -F ";" '"'"'{ print " "$2" "$5}'"'"'| sort | uniq -c | sort -g -r ' The output is the following, remoteserver1 ... (8 Replies)
Discussion started by: charli1
8 Replies
IPCONFIG(8)						      System Manager's Manual						       IPCONFIG(8)

NAME
ipconfig, arpd, rip - Internet configuration and routing SYNOPSIS
ip/ipconfig [-abp] [-e etherdev] [-m ip-mask] [ipaddr] ip/arpd [-pd] [-e etherdev] [-b bcast-addr] ip/rip [-b] DESCRIPTION
Ipconfig configures an Internet connection on an Ethernet. The options are a do not start arpd b do not use BOOTP to discover a gateway address p start arpd in promiscuous mode (see below) e use the Ethernet mounted at /net/etherdev m set the network mask to ip-mask If ipaddr is specified on the command line, use that instead of one found in the local database or via the BOOTP protocol. Arpd performs the Internet Address Resolution Protocol, translating Internet addresses into Ethernet addresses. It is normally started by ipconfig. The options are d print debugging to standard output p (promiscuous) answer ARP requests for any recognized machine. The default is to answer just for the machine running arpd. e use the Ethernet mounted at /net/etherdev b use the IP broadcast address bcast-addr instead of the correct one. Rip runs the routing protocol RIP. It listens for RIP packets on connected networks and updates the kernel routing tables. The only option, -b, broadcasts routing information onto the networks. SOURCE
/sys/src/cmd/ip/ipconfig.c /sys/src/cmd/ip/arpd.c /sys/src/cmd/ip/rip.c SEE ALSO
ndb(6) IPCONFIG(8)
All times are GMT -4. The time now is 05:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy