Full Discussion: Hostsfile generator
Top Forums Shell Programming and Scripting Hostsfile generator Post 303040999 by Marti95 on Tuesday 12th of November 2019 02:36:16 AM
Originally Posted by RudiC
It does, as you can see in my post.
- What's your result with the array shown in post #1?
- What exactly does your array look like (index / element)?
- What's yoour bash version?
Run the code with the -x (--xtrace) option set and post the output.

Thanks for your answer

GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

This is How the Array Looks:
declare -p
declare -A ENTRIES='([415,COMMENT]="# CentOS " [55,HOST1]="123imm1" [55,HOST2]="imm1" [414,IP]="# x.x.x.41 - x.x.x.50 Server" [35,IP]="" [14,COMMENT]="" [205,HOST1]="unas123" [1925,HOST2]="toschiba2" [1925,HOST1]="123toschiba2" [14,IP]="# x.x.x.001 - x.x.x.020 ----- Gateway, Switch, Picco und Sicherung" [205,HOST2]="unas" [35,HOST2]="switch2" [25,HOST1]="123switch1" [414,COMMENT]="" [55,COMMENT]="# IMM 1 " [35,HOST1]="123switch2" [25,HOST2]="switch1" [9995,HOST2]="rowa" [1915,HOST2]="toschiba1" [505,HOST2]="pharma" [1614,HOST1]="" [1614,HOST2]="" [9995,IP]="" [9995,HOST1]="123rowa" [1915,IP]="" [1915,HOST1]="123toschiba1" [505,IP]="" [505,HOST1]="123propharma" [1645,HOST2]="mps4" [1635,COMMENT]="# Netzwerkdrucker 3" [9995,COMMENT]="# Rowa (DMZ)" [1915,COMMENT]="# Toshiba WPS 1" [1645,HOST1]="123mps4" [505,COMMENT]="#  Server" [205,COMMENT]="# UNAS Sicherung" [410,IP]=" " [10,COMMENT]="" [9990,HOST2]="" [1910,HOST2]="" [9990,HOST1]="" [9994,COMMENT]="" [1910,HOST1]="" [1914,COMMENT]="" [1925,IP]="" [25,IP]="" [9994,IP]="# 10.168.123.xxx ----- DMZ" [1914,IP]="# #x.x.x.191 - x.x.x.199 ----- WPS Drucker und PreisChecker" [410,HOST1]="" [1635,HOST2]="mps3" [15,HOST1]="123wan" [415,IP]="" [9990,COMMENT]="" [1910,COMMENT]="" [1635,HOST1]="123mps3" [15,HOST2]="wan" [410,HOST2]="" [25,COMMENT]="# Switch 1" [414,HOST1]="" [1625,HOST1]="123mps2" [15,IP]="" [1625,HOST2]="mps2" [1645,IP]="" [414,HOST2]="" [1615,COMMENT]="# Netzwerkdrucker 1" [9994,HOST2]="" [1914,HOST2]="" [15,COMMENT]="# Opensystem Gateway" [55,IP]="" [9994,HOST1]="" [1914,HOST1]="" [1615,IP]="" [35,COMMENT]="# Switch 2" [1625,COMMENT]="# Netzwerkdrucker 2" [1610,HOST1]="" [1614,IP]="# x.x.x.161 - x.x.x.190 ----- Netzwerkdrucker" [1925,COMMENT]="# Toshiba WPS 2" [1610,HOST2]="" [10,IP]=" " [14,HOST1]="" [410,COMMENT]="" [1625,IP]="" [1614,COMMENT]="" [205,IP]="" [1645,COMMENT]="# Netzwerkdrucker 4" [14,HOST2]="" [9990,IP]=" " [1910,IP]=" " [10,HOST1]="" [1610,COMMENT]="" [415,HOST1]="123virtsrv1" [415,HOST2]="virtsrv1" [10,HOST2]="" [1635,IP]="" [1615,HOST1]="123mps1" [1610,IP]=" " [1615,HOST2]="mps1" )'

This is the output with the -x option:
++ date +%Y%m%d
+ d=20191111
+ touch /tmp/hosts.20191111
++ sort -u
+++ echo '210,IP 210,HOST2 415,COMMENT 55,HOST1 210,HOST1 115,IP 55,HOST2 414,IP 14,COMMENT 205,HOST1 14,IP 205,HOST2 115,COMMENT 414,COMMENT 55,COMMENT 9995,HOST2 505,HOST2 1614,HOST1 1614,HOST2 210,COMMENT 9995,IP 9995,HOST1 505,IP 505,HOST1 9995,COMMENT 505,COMMENT 205,COMMENT 410,IP 215,IP 10,COMMENT 9990,HOST2 9990,HOST1 9994,COMMENT 225,COMMENT 214,COMMENT 9994,IP 225,IP 410,HOST1 15,HOST1 415,IP 9990,COMMENT 15,HOST2 410,HOST2 115,HOST1 414,HOST1 1625,HOST1 15,IP 1625,HOST2 115,HOST2 414,HOST2 1615,COMMENT 214,IP 9994,HOST2 225,HOST2 15,COMMENT 55,IP 9994,HOST1 1615,IP 225,HOST1 1625,COMMENT 1610,HOST1 1614,IP 1610,HOST2 10,IP 215,HOST2 14,HOST1 410,COMMENT 1625,IP 1614,COMMENT 214,HOST2 214,HOST1 205,IP 215,HOST1 14,HOST2 9990,IP 10,HOST1 1610,COMMENT 415,HOST1 415,HOST2 215,COMMENT 10,HOST2 1615,HOST1 1610,IP 1615,HOST2'
+++ tr , '\n'
+ for IN in '$(sort -u <<< $(echo "${!ENTRIES[*]}" | tr '\'','\'' '\''\n'\''))'
+ '[' '!' 210 = 210 ']'
+ printf '%s %s %s %s\n' ' ' '' '' ''

+ for IN in '$(sort -u <<< $(echo "${!ENTRIES[*]}" | tr '\'','\'' '\''\n'\''))'
+ '[' '!' P = IP ']'
+ break
+ echo 'Script finished'

As you see i got no output from the array.

Last edited by Marti95; 11-12-2019 at 04:43 AM..
Test Your Knowledge in Computers #920
Difficulty: Medium
The Unix time number is zero at the Unix epoch, and increases by exactly 86400 per day since the epoch.
True or False?

9 More Discussions You Might Find Interesting

1. Cybersecurity

Password Generator

I need a great Password Generator program. I looked at a few of them, but none of them seemed to be what I wanted. So I have decided to write my own. (That's the cool thing about being a programmer....I always get what I want in software :) ) Do you have any password generators that you... (13 Replies)
Discussion started by: Perderabo
13 Replies

2. UNIX for Dummies Questions & Answers

date generator

Is there a command to generate the unix date that is in theshadow file?>? (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies

3. Shell Programming and Scripting

How to compare result lpstat with hostsfile

Hi there all, I got a long list of printers installed and a longer list of printers in my hosts file. In the hosts file I got a even longer list of printers in the hosts file I got the IP adress of all printers next to the printer name. How can I get a script working to get the printers... (0 Replies)
Discussion started by: draco
0 Replies

4. Shell Programming and Scripting

Range generator

Dear All, I have a sorted file like 1 2 3 8 9 10 45 46 47 78 The output will be range like 1 3 8 10 45 47 78 78 (9 Replies)
Discussion started by: saifurshaon
9 Replies

5. Shell Programming and Scripting

Random Sentence Generator

Hi, I need to create a table with random sentences. I need lines that are upto 1000 characters in lenght. I need a random sentence generator that will create sentences and output it to a text file. The sentences should be of lenght varying from 1 to 1000. Does anyone know how this can be... (7 Replies)
Discussion started by: kaushys
7 Replies

6. What is on Your Mind?

Barcode Generator

QR Code Generator (0 Replies)
Discussion started by: Neo
0 Replies

7. Shell Programming and Scripting

time generator

Hi experts, I'd like to generate the table/file containing: number of milliseconds elapsed since midnight till midnight. It should contain 5 columns (hours minutes seconds milliseconds): Table will have theoretically 86 400 000 rows. My question is , is there somewhere the file or source... (7 Replies)
Discussion started by: hernand
7 Replies

8. Shell Programming and Scripting

Sequence generator

Thanks Guys This really helped (5 Replies)
Discussion started by: robert89
5 Replies

9. Shell Programming and Scripting

Generator script

Hello again unix.com people, I need your help again. I'm currently need a script that will generate ip ranges... lets say from to and the output should be like this: ............. ............. (line-by-line) ... (7 Replies)
Discussion started by: galford
7 Replies

Featured Tech Videos

All times are GMT -4. The time now is 09:27 PM.
Unix & Linux Forums Content Copyright 1993-2020. All Rights Reserved.
Privacy Policy