Sponsored Content
Full Discussion: Hostsfile generator
Top Forums Shell Programming and Scripting Hostsfile generator Post 303040870 by Marti95 on Friday 8th of November 2019 04:43:30 AM
Old 11-08-2019
Hostsfile generator

Hello

I use a bash script to creating the hosts file /etc/hosts
Quote:
#!/bin/bash
System is Centos7
But there is a bug inside my output and I want to fix this.

My Array looks like this:
Code:
205,IP         111.122.133.20 
205,HOST2      unas           
205,HOST1      unas15533      
205,COMMENT    # UNAS         
775,IP         111.122.133.77 
775,HOST2      wlan           
775,HOST1      15533-wlan     
775,COMMENT    # WLAN Access Point
1015,IP        111.122.133.101
1015,HOST2     rdp1           
1015,HOST1     15533-rdp1     
1015,COMMENT   # RDP-Terminal 1
1025,IP        111.122.133.102
1025,HOST2     rdp2           
1025,HOST1     15533-rdp2     
 1025,COMMENT   # RDP-Terminal 2

The created hosts file looks something like this:
Quote:
# x.x.x.001 - x.x.x.020 ----- Gateway, Switch, Picco und Sicherung
192.168.123.1 123wan wan # Opensystem Gateway
192.168.123.2 123switch1 switch1 # Switch 1
192.168.123.3 123switch2 switch2 # Switch 2
192.168.123.5 123imm1 imm1 # IMM 1
192.168.123.20 unas123 unas # UNAS Sicherung

# x.x.x.41 - x.x.x.50 Server
192.168.123.41 123virtsrv1 virtsrv1 # CentOS

# x.x.x.161 - x.x.x.190 ----- Netzwerkdrucker
192.168.123.161 123mps1 mps1 # Netzwerkdrucker 1
192.168.123.162 123mps2 mps2 # Netzwerkdrucker 2
192.168.123.163 123mps3 mps3 # Netzwerkdrucker 3
192.168.123.164 123mps4 mps4 # Netzwerkdrucker 4

# #x.x.x.191 - x.x.x.199 ----- WPS Drucker und PreisChecker
192.168.123.191 123toschiba1 toschiba1 # Toshiba WPS 1
192.168.123.192 123toschiba2 toschiba2 # Toshiba WPS 2

# 10.168.123.xxx ----- DMZ
10.168.123.2 123rowa rowa # Rowa (DMZ)
I creat the hosts file with this command:
Code:
echo "===================================================="
d=`date +%Y%m%d`
touch "/tmp/hosts.${d}"
IFS=$'\n'
echo "${!ENTRIES[*]}" | sort -t, -k1,1n -k2,2.2r -k2.3 | while read IX; do printf "%-10s\n" ${ENTRIES[$IX]}; done | paste -sd"\t\t\t\n" >> "/tmp/hosts.${d}"
echo "Script finished"
echo "===================================================="

I would like to format the file so that the distances are even (sometimes there is a bigger gap between IP and hosts1, between hosts 1 and hosts 2, ...).
Also, I do not want to use tabs because this causes problems.

Thank you for the help Smilie
 

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 64.1.1.1 to 74.255.255.255 and the output should be like this: 64.1.1.2 64.1.1.3 ............. ............. 74.255.255.254 74.255.255.255 (line-by-line) ... (7 Replies)
Discussion started by: galford
7 Replies
IpfilterDlfConverter(3pm)				  LogReport's Lire Documentation				 IpfilterDlfConverter(3pm)

NAME
Lire::Firewall::IpfilterDlfConverter - convert ipf (ipmon) logs to firewall DLF DESCRIPTION
Lire::Firewall::IpfilterDlfConverter converts Ipfilter logs into firewall DLF format. Input for this converter is the standard ipf syslog log file as produced by ipmon. IP Filter is shipped with FreeBSD, OpenBSD (up to 2.9) and some other OS's. EXAMPLE
A ipfilter logfile which looks like Oct 30 07:42:29 rolle ipmon[16747]: 07:42:28.585962 ie0 @0:9 b 192.168.48.1,45085 -> 192.168.48.2,22 PR tcp len 20 64 -S OUT Oct 30 07:40:24 rolle ipmon[16747]: 07:40:23.631307 ep1 @0:6 b 192.168.26.5,113 -> 192.168.26.1,3717 PR tcp len 20 40 -AR OUT Oct 30 07:42:29 rolle ipmon[16747]: 07:42:28.585962 ie0 @0:9 b 192.168.48.1,45085 -> 192.168.48.2,22 PR tcp len 20 64 -S OUT Oct 30 07:44:11 rolle ipmon[16747]: 07:44:10.605416 2x ep1 @0:15 b 192.168.26.1,138 -> 192.168.26.255,138 PR udp len 20 257 IN Oct 30 07:44:34 rolle ipmon[16747]: 07:44:33.891869 ie0 @0:10 b 192.168.48.1,23406 -> 192.168.48.2,22 PR tcp len 20 64 -S OUT Oct 30 07:49:13 rolle ipmon[16747]: 07:49:12.554420 ep1 @0:15 b 210.132.100.117 -> 192.168.26.5 PR icmp len 20 56 icmp 3/3 for 192.168.26.5,61915 - 210.132.100.117,53 PR udp len 20 23040 IN Oct 30 07:50:23 rolle ipmon[16747]: 07:50:22.908107 ep1 @0:15 b 210.132.100.117 -> 192.168.26.5 PR icmp len 20 56 icmp 3/3 for 192.168.26.5,4480 - 210.132.100.117,53 PR udp len 20 19712 IN Oct 30 07:56:11 rolle ipmon[16747]: 07:56:11.113029 2x ep1 @0:15 b 192.168.26.1,138 -> 192.168.26.255,138 PR udp len 20 257 IN (that's: .... 'PR' protocol 'len' length_of_ip_headers_saved packetlength direction) will get converted to something like 994398737 denied igmp 100.187.115.1 - ep1 LIRE_NOTAVAIL 224.0.0.2 - 56 994398861 denied igmp 100.187.115.1 - ep1 LIRE_NOTAVAIL 224.0.0.1 - 56 994398862 denied igmp 100.187.115.1 - ep1 LIRE_NOTAVAIL 224.0.0.2 - 56 994406849 denied udp 192.168.26.4 137 ie0 LIRE_NOTAVAIL 192.168.26.255 137 116 994406850 denied udp 192.168.26.4 137 ie0 LIRE_NOTAVAIL 192.168.26.255 137 116 994406866 denied udp 192.168.26.4 137 ie0 LIRE_NOTAVAIL 192.168.26.255 137 98 SEE ALSO
ipl(4) for description of log structure. The ipmon.c source (e.g. on http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/ src/usr.sbin/ipmon/Attic/ipmon.c?rev=1.27& content-type=text/plain&hideattic=0 ) for the specification of the log syntax. The IP Filter webpage on http://coombs.anu.edu.au/~avalon/ip-filter.html AUTHOR
Joost van Baal <joostvb@logreport.org>, Wessel Dankers <wsl@logreport.org> VERSION
$Id: IpfilterDlfConverter.pm,v 1.7 2009/03/15 08:10:55 vanbaal Exp $ COPYRIGHT
Copyright (C) 2001-2003 Stichting LogReport Foundation LogReport@LogReport.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. Lire 2.1.1 2009-03-15 IpfilterDlfConverter(3pm)
All times are GMT -4. The time now is 06:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy