Sponsored Content
Full Discussion: Grouping hostnames for pdsh
Top Forums Shell Programming and Scripting Grouping hostnames for pdsh Post 302976788 by joeg1484 on Wednesday 6th of July 2016 09:24:03 AM
Old 07-06-2016
Grouping hostnames for pdsh

Hi All,

I have a list of hostnames in a text file and I would like to craft a bash script that would group them for use with pdsh.

For example... I would like to group the following from a file:

Code:
hostname1000
hostname1001
hostname1002
hostname1003
hostname1004
hostname2000
hostname2001
hostname2002

into hostname[1000-1004,2000-2002]

I tried some prelimenary scripts like:

Code:
num=1;for a in $(cat range_hostname.txt |cut -c 1-12 |sort) ; do echo ${a}${num}; num=$[num+1 ];done

to get hostname10, for example, and put a count after, but this just counts all the lines and puts the count at the end. Not like a group of like names like I need.

Any ideas for this?

Thanks!
Joe



Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 07-06-2016 at 11:27 AM.. Reason: Added (i)code tags.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

newbie question about hostnames

When I log into bash it will say my username @localhost I wondering how do I change localhost to another such as draco.I've the using the hostname command as root but it changes back to localhost after I reboot.I was wondering how would I hide my ISP hostname in linux.Because when I log into an IRC... (1 Reply)
Discussion started by: angelfly
1 Replies

2. IP Networking

DHCP and Hostnames

I have a linksys DSL router. I run a mixed environment of Windows, Linux and Solaris. The routers dhcp tables show the windows machines hostnames and associated IP's ok but the unix bases mahines don't have associated hostnames in the DHCP tables. I can ping by IP but not my the machines... (5 Replies)
Discussion started by: mr16ga
5 Replies

3. Shell Programming and Scripting

Scripting nslookup to resolve multiple hostnames

Hi Friends, I have a list of servers with their production names in a file. I want to know the best way eiter a command or a script that can do the following :- Append "-bkp" to each hostnames at the end And run nslookup and make sure I have valid backup IP add assigned to it. Any... (1 Reply)
Discussion started by: new2prog
1 Replies

4. Shell Programming and Scripting

regex help to get unique hostnames

Hi I have a file containing hostnames like this (host=myhost.domain.com) or (host=myhost) i need to extarct the unique hostnames without the domain names from that file. so my output should be myhost (without domain names) But my regex skills are rusty i tried grep "host"... (4 Replies)
Discussion started by: xiamin
4 Replies

5. Shell Programming and Scripting

Compare file of hostnames with table in MySQL DB

Hi all, i have a list of files that contains some PC hostname, then i need to enumerate every hostname and check if there's a table with same name of the hosts in MySQL database XYZ. I need this because have to decide automatically if i have to make a create table or a insert into an existent... (2 Replies)
Discussion started by: maxlamax
2 Replies

6. UNIX for Dummies Questions & Answers

Is there a unix command to find ALL hostnames for an ip address?

I am trying to determine if there are several url/host names for an IP address. Is there a UNIX command to find ALL host names for an IP address? Thank you in advance. (3 Replies)
Discussion started by: rukasu
3 Replies

7. Programming

Getting All VM Hostnames Using Pysphere

I need to obtain a list of all the hostname of all the VM's that reside on two ESXI servers using pysphere. I have attempted using the basic methods but an unable to get a hostname in my testing using: from pysphere import VIServer server = VIServer() ... (0 Replies)
Discussion started by: metallica1973
0 Replies

8. UNIX for Dummies Questions & Answers

Cyrillic Hostnames?

As the title suggests, I'm wondering if its possible to set a hostname to a name or word with Cyrillic letters (e.g. - Like the Russian alphabet). I tried installing the cyrillic-console package in Debian. I switched my desktop to Russian as well. However, when I try to set the hostname I get that... (2 Replies)
Discussion started by: Azrael
2 Replies

9. Shell Programming and Scripting

Ip address for multiple hostnames

i have a file which has 100 servers,i want a script which can output me ip address and hostname for that server. Thanks in advance!! input file abc.com output file should be abc.com 192.168.1..1 (1 Reply)
Discussion started by: Moon1234
1 Replies

10. Shell Programming and Scripting

Check for valid hostnames

Hello, I am trying to develop a script to check for valid hostnames. Below are the prerequisites for a valid hostname which I got from wiki : Hostnames are composed of series of labels concatenated with dots, as are all domain names. For example, "en.wikipedia.org" is a hostname. Each label... (8 Replies)
Discussion started by: rahul2662
8 Replies
LIBBASH(7)							  libbash Manual							LIBBASH(7)

NAME
libbash -- A bash shared libraries package. DESCRIPTION
libbash is a package that enables bash dynamic-like shared libraries. Actually its a tool for managing bash scripts whose functions you may want to load and use in scripts of your own. It contains a 'dynamic loader' for the shared libraries ( ldbash(1)), a configuration tool (ldbashconfig(8)), and some libraries. Using ldbash(1) you are able to load loadable bash libraries, such as getopts(1) and hashstash(1). A bash shared library that can be loaded using ldbash(1) must answer 4 requirments: 1. It must be installed in $LIBBASH_PREFIX/lib/bash (default is /usr/lib/bash). 2. It must contain a line that begins with '#EXPORT='. That line will contain (after the '=') a list of functions that the library exports. I.e. all the function that will be usable after loading that library will be listed in that line. 3. It must contain a line that begins with '#REQUIRE='. That line will contain (after the '=') a list of bash libraries that are required for our library. I.e. every bash library that is in use in our bash library must be listed there. 4. The library must be listed (For more information, see ldbashconfig(8)). Basic guidelines for writing library of your own: 1. Be aware, that your library will be actually sourced. So, basically, it should contain (i.e define) only functions. 2. Try to declare all variables intended for internal use as local. 3. Global variables and functions that are intended for internal use (i.e are not defined in '#EXPORT=') should begin with: __<library_name>_ For example, internal function myfoosort of hashstash library should be named as __hashstash_myfoosort This helps to avoid conflicts in global name space when using libraries that come from different vendors. 4. See html manual for full version of this guide. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <ril@ran4.net> SEE ALSO
ldbash(1), ldbashconfig(8), getopts(1), hashstash(1) colors(1) messages(1) urlcoding(1) locks(1) Linux Epoch Linux
All times are GMT -4. The time now is 09:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy