LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 05-11-2015, 06:49 PM   #1
Ben Wang
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Rep: Reputation: Disabled
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).

Last edited by Ben Wang; 05-12-2015 at 03:01 PM.
 
Old 05-12-2015, 01:28 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,886

Rep: Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258Reputation: 4258
Quote:
Originally Posted by Ben Wang View Post
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
 
1 members found this post helpful.
Old 05-12-2015, 02:23 PM   #3
/dev/random
Member
 
Registered: Aug 2012
Location: Ontario, Canada
Distribution: Slackware 14.1, LFS-current, NetBSD 6.1.3
Posts: 263

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by Ben Wang View Post
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
 
3 members found this post helpful.
Old 05-12-2015, 02:56 PM   #4
Ben Wang
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
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).

Last edited by Ben Wang; 05-12-2015 at 02:58 PM.
 
Old 05-12-2015, 03:41 PM   #5
Ben Wang
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by /dev/random View Post
I'll bite because this is not rocket science...

Code:
nmap -sP -PA22 192.168.1.1/24 > hosts_available
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.

Last edited by Ben Wang; 05-12-2015 at 03:55 PM.
 
Old 05-12-2015, 04:55 PM   #6
Ben Wang
LQ Newbie
 
Registered: Apr 2015
Posts: 16

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by /dev/random View Post
I'll bite because this is not rocket science...

Code:
nmap -sP -PA22 192.168.1.1/24 > hosts_available
Problem solved. Thank you.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
hosts.deny vs arno ip tables blocked hosts D0zer Linux - Security 2 12-07-2014 02:07 AM
Script for hosts, numbers of hosts and users connected to squid server arunabh_biswas Programming 5 08-28-2010 04:11 AM
can't restrict sshd access through hosts.allow and hosts.deny but was working earlier farhan Linux - Security 4 04-18-2008 07:41 AM
/etc/hosts.deny/hosts.allow have no effect on sshd access bganesh Linux - Security 4 05-04-2006 08:06 PM
Adding shell commands to hosts.deny and hosts.allow ridertech Linux - Security 3 12-29-2003 03:52 PM


All times are GMT -5. The time now is 02:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration