*ix script to check port of client server and return output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting *ix script to check port of client server and return output
# 1  
Old 11-03-2012
*ix script to check port of client server and return output

Hello EveryOne,

I am new to *ix. some could help to write a script.
Problem :- Have to ssh to so many client and check port or filesystem usage, so thinking to automate using script.

What i Need:- when i run script on my Launchpad server, it should

Should ask and SSH to user provided Server -> Authenticate User password-> Run port check commands (netstat) or Filesystem usage (df -k) -> return output to Launchpad server server screen(where i ran that script)

if fails to do- Return a valid reason( file not found) or (server not available)

please let me know if i miss something..

Kindly help:-

Br,
# 2  
Old 11-03-2012
You shouldn't use a password to log on to your servers from the launch pad system. Use exchanged keys instead.

You might want to design your script so that it reads from a list all the host names it has to work on. This way you can design a "template script" which provides the base logic of cycling through all the servers in the list, contacting them, writing the results in a log, etc..

You will need some logic to handle servers which are unreachable for some reason (not pingable, key not exchanged, network not reachable, ...). If the list of servers is really long you probably have always one or the other which is unreachable in the moment your run your script, so it should better be able to deal with such a condition until you don't want to do an awful lot of handiwork during its run. "Deal with it" meaning something as simple as writing the hostname in an output file "hosts.failed" for instance.

Run your tasks separately, so that you can handle all the logic on the launch pad server. It is easier to handle this locally:

Code:
if [ $(ssh -qo BatchMode user@host "/some/command") != "success" ] ; then
     ssh -qo BatchMode user@host "do_this"
fi

then to handle it remote:

Code:
ssh -qo BatchMode user@host "if [ \"$(/some/command)\" != \"success\" ] ; then ; do_this ; fi"

or, even more troublesome, first "roll out" all sorts of scripts to the remote servers and only then execute these from the central script. Chances are you introduce a lot of inconsistencies though this error-prone way, where older versions of your scripts interfere with newer versions, etc..

Ideally you can parallelize the work on remote servers by creating a special script which handles exactly one remote host and call that from a control script looping through the list of hosts. Put the calls to this script in the background and use "wait" and some counter to limit the number of background processes running in parallel. (You might want to avoid hitting the limit on processes on your launch pad box.)

I hope this helps.

bakunin
# 3  
Old 11-03-2012
Thanks for suggestion, But

In our work environment i have hell lot of servers. In a day i get 20 to 30 tickets or requests saying a port check have been failed on so and so(6445 or 6996) node. so everytime its new server(even i dont know there names)
script should prompt.
enter username
enter node name;
enter password
enter port number to check
check port (listening or established or nothing) and show me the result.
if the port is not up or server is unreachable show fixed error(try manually human :-)))

please help... i am fed up of doing same lengthy steps to check the tickets.


Br,
# 4  
Old 11-03-2012
I guess you can do something like below:-

Code:
echo -e "Enter host: \c"
read host

echo -e "Enter user: \c"
read user

echo -e "Enter port: \c"
read port

ssh ${user}@${host} "netstat -a | grep ${port}; some_other_cmd"

Since you do not have the ssh-keys setup, the script will ask for password and execute the command. I hope this helps.
This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check telnet port multiple server

Dear Team, I want to check multiple linux server to check port open. eg. 192.168.1.12 80,192.168.1.12 443 Please provide script for that? (8 Replies)
Discussion started by: pradeep1807
8 Replies

2. Shell Programming and Scripting

Need output of script on screen and file with correct return status of the called script.

Hi, I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed. Below is my sample... (14 Replies)
Discussion started by: Prathmesh
14 Replies

3. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

4. Shell Programming and Scripting

Return output from shell script

Hi All, There are 2 scripts A and B. A --> It will invoke script B B --> It will generate below output. 100 - connected 105 - Not Connected 210 - Connected I want to return this value to script A. Please advice. (4 Replies)
Discussion started by: Girish19
4 Replies

5. Shell Programming and Scripting

Sftp script for dev server to client server

hi, i am new to unix, cuold u send some sftp acripts to send files to dev server to clint server, (1 Reply)
Discussion started by: Koti.annam
1 Replies

6. HP-UX

how to check remote server port listening from application.

Hi, I have an application running on HP-UX, from this application I need to findout if the port number. lets say 7890,7891, 7892 are listening on the remote server running on HP-UX. Is there any way of doing it using "system()" function or any other? I noticed that nmap, netcat are not... (0 Replies)
Discussion started by: einsteinBrain
0 Replies

7. Shell Programming and Scripting

Script to check if Port is Active

is there a better way to check if a port is active on linux and sunos systems? this is currently what I'm using in my script: netstat -an | egrep -i "$PORT" i know this isn't the best way as there could be numbers in that output that has my port number in it but isn't necessarily a... (0 Replies)
Discussion started by: SkySmart
0 Replies

8. Programming

Client/Server Socket Application - Preventing Client from quitting on server crash

Problem - Linux Client/Server Socket Application: Preventing Client from quitting on server crash Hi, I am writing a Linux socket Server and Client using TCP protocol on Ubuntu 9.04 x64. I am having problem trying to implement a scenario where the client should keep running even when the... (2 Replies)
Discussion started by: varun.nagpaal
2 Replies

9. Shell Programming and Scripting

Client-server script

Hi all, I am referring to this website . What I'm trying to do is to have a server script which will receive data from GPS in one line and store it in some file. Now from what I can see in this server file, server is sending the data to client but I don't need that .. I need only server script... (3 Replies)
Discussion started by: c0mrade
3 Replies

10. Shell Programming and Scripting

copy file from server to client script

i want to run automated backup copy , using crontab and how to do that? the backup file should be taken from the sun server and put it in the client machine daily.pls help.. (5 Replies)
Discussion started by: gini
5 Replies
Login or Register to Ask a Question