[SOLVED] Need help to get the available hosts among many hosts
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need help to get the available hosts among many hosts
I have many hosts as following. But those hosts are dual operating system (Linux and Windows). I always run program background. If someone is using Linux, it is fine. But if someone is using windows or the host is offline. Then, I cannot use ssh. The way I do preiviously is first ssh one by one. And then find the hosts which are offline or windows. And write them down one by one. And then ssh to hosts except them. Let us assume the number of programs is less than the total available hosts. Can someone write a shell script to output the all available hosts to a file like "host_available"?
Here is the host file. https://www.dropbox.com/s/vbz6w864y3...tlist.txt?dl=0
I am using ssh to connect the computers on campus. If the computer I am trying to connect is offline or using windows, the ssh will take long time, and finally it will failed. I write a shell script to generate the hostlist
Code:
#!/bin/bash
for i in `seq -w 1 28`
do
echo "c15-0330-$i.ad.mtu.edu"
# I would like to add a command here to see whether ssh c15-0330-$i.ad.mtu.edu it succeeds or not. And then output a #file which contains the all available host.
done
for i in `seq -w 1 20`
do
echo "c28-0112-$i.ad.mtu.edu"
done
for i in `seq -w 1 20`
do
echo "c28-112a-$i.ad.mtu.edu"
done
I do not how to set a certain time to see whether connection is successful or not (see the comment in the shell script).
I have many hosts as following. But those hosts are dual operating system (Linux and Windows). I always run program background. If someone is using Linux, it is fine. But if someone is using windows or the host is offline. Then, I cannot use ssh. The way I do preiviously is first ssh one by one. And then find the hosts which are offline or windows. And write them down one by one. And then ssh to hosts except them. Let us assume the number of programs is less than the total available hosts. Can someone write a shell script to output the all available hosts to a file like "host_available"?
Here is the host file. https://www.dropbox.com/s/vbz6w864y3...tlist.txt?dl=0
Please read the LQ Question Guidelines link in my posting signature.
We will help you, but we are NOT going to write your scripts for you. Shown effort of your own, post what you tried, and tell us where you're stuck. Otherwise, try any of the easily found tutorials to help you get started
I have many hosts as following. But those hosts are dual operating system (Linux and Windows). I always run program background. If someone is using Linux, it is fine. But if someone is using windows or the host is offline. Then, I cannot use ssh. The way I do preiviously is first ssh one by one. And then find the hosts which are offline or windows. And write them down one by one. And then ssh to hosts except them. Let us assume the number of programs is less than the total available hosts. Can someone write a shell script to output the all available hosts to a file like "host_available"?
Here is the host file. https://www.dropbox.com/s/vbz6w864y3...tlist.txt?dl=0
I'll bite because this is not rocket science...
Code:
nmap -sP -PA22 192.168.1.1/24 > hosts_available
Last edited by /dev/random; 05-12-2015 at 02:23 PM.
Reason: code tags
Please read the LQ Question Guidelines link in my posting signature.
We will help you, but we are NOT going to write your scripts for you. Shown effort of your own, post what you tried, and tell us where you're stuck. Otherwise, try any of the easily found tutorials to help you get started
OK. I am using ssh to connect the computers on campus. If the computer I am trying to connect is offline or using windows, the ssh will take long time, and finally it will failed. I write a shell script to generate the hostlist
Code:
#!/bin/bash
for i in `seq -w 1 28`
do
echo "c15-0330-$i.ad.mtu.edu"
# I would like to add a command here to see whether ssh c15-0330-$i.ad.mtu.edu it succeeds or not. And then output a #file which contains the all available host.
done
for i in `seq -w 1 20`
do
echo "c28-0112-$i.ad.mtu.edu"
done
for i in `seq -w 1 20`
do
echo "c28-112a-$i.ad.mtu.edu"
done
I do not how to set a certain time to see whether connection is successful or not (see the comment in the shell script).
It is very help. I check the output of hosts_available as following
Code:
Starting Nmap 6.40 ( http://nmap.org ) at 2015-05-12 16:32 EDT
Nmap scan report for c15-0330-01.ad.mtu.edu (141.219.152.233)
Host is up (0.042s latency).
Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
But I need hosts_available to be list of host. How can I remove other words except "c15-0330-01.ad.mtu.edu"? Since it is easier for me to check why the computer is offline by its name. And also I only know the host name but I do not know the ip address, how can I use ip address or get the ip addresses of hosts (ifconfig, I only can login and type ifconfig, and write down the ip adresses)? IP address is not sequential. I only need to scan the host in the range of host_lists since they are more likely free and they are new computers with processor i7.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.