Service checking through shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Service checking through shell script
# 1  
Old 09-19-2014
Service checking through shell script

I want to check the postgres service for client PC which is remotely placed through shell script , whether the Postgres service is working or not.I don't have an idea to develop this script.Please give me a code.
Code:
Client PC IP Address:

10.66.1.133

# 2  
Old 09-19-2014
You could use nc to test postgress is listening on it's port:


Code:
 if nc -w 3 -z 10.66.1.133 5432 < /dev/null > /dev/null 2>&1
then
   echo "Postgress is running"
else
   echo "Postgress NOT running"
fi

or if your using bash shell you could do:

Code:
if 2>/dev/null >/dev/tcp/10.66.1.133/5432
then
   echo "Postgress is running"
else
   echo "Postgress NOT running"
fi


Last edited by Chubler_XL; 09-19-2014 at 01:08 AM..
This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 09-19-2014
Excellent, It Superbly works ,
Please explain the above steps in ifcondition.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script newbie- how to generate service log from shell script

Hi, I am totally a newbie to any programming languages and I just started an entry level job in an IT company. One of my recent tasks is to create a script that is able to show the log file of linux service (i.e. ntpd service) lets say, if I run my script ./test.sh, the output should be... (3 Replies)
Discussion started by: xiaogeji
3 Replies

2. Shell Programming and Scripting

Checking to see if windows service is running

Hi I have created a PowerShell script which successfully checks whether windows service pgsql-9.2 is running. I have tried to call that PowerShell script with a shell/bash script within a LINUX machine but have been unsuccessful. Is there a way of a shell/Perl script to check whether a... (5 Replies)
Discussion started by: simpsa27
5 Replies

3. Solaris

Checking if service is running

Hi, For audit reasons, I need to stop the web server service in some Solaris servers. The port that is listening for this service is port 10000. This is the output that shows the port 10000 is open in the server : # netstat -an | grep 10000 10.70.21.144.10000 10.70.21.133.58130 49640... (6 Replies)
Discussion started by: anaigini45
6 Replies

4. Shell Programming and Scripting

Help me with C-shell Script: Disk checking

Hi, i am new in shell script. i have given a task to make a C-shell script. I have list of ip address and device name respectively. For example; cal 1 : 100.21.25.10 cal 2 : 100.21.25.11 cal 3 : 100.21.25.12 cal 4 : 100.21.25.14 and so on... Right now, i have this. #! /bin/csh -f ... (0 Replies)
Discussion started by: lattey
0 Replies

5. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

6. Shell Programming and Scripting

Shell script for service

Hi, I want to add an application as a service in Linux(Fedora 12). It should be run always for monitoring my system. It never terminate unless kill it. I wrote this script, put it on /etc/init.d/myapp and added it to run level 2345: #!/bin/bash # # chkconfig: 2345 20 80 # description:... (3 Replies)
Discussion started by: pronetin
3 Replies

7. Shell Programming and Scripting

checking to see if a service is running in a shell script

How can I tell, in a shell script, if a certain service is running? I know how to do this on the command line, but not in a script. Is an error thrown somehow that I can check? Thanks. (6 Replies)
Discussion started by: daflore
6 Replies

8. Shell Programming and Scripting

Checking availability of service

HI CAN ANY ONE HELP ME FOR BELOW QUESTION CHECKING AVAILABILITY OF SERVICE IN LINUX (2 Replies)
Discussion started by: satheeshkr_cse
2 Replies

9. Shell Programming and Scripting

Regularly checking with shell script

Hi, I am new in scripting and also in Linux. I wrote my first script recently. I have an external hdd connected to my debian machine. I am spinning it down using a spindown code (code.google.com/p/spindown/)when I am not using it ( automatically after 1 hour). The problem was I wanted to know when... (2 Replies)
Discussion started by: aspedisca
2 Replies

10. Shell Programming and Scripting

Checking Files with a Shell Script

Hey everyone, I'm writing a shell script that needs to loop thru a directory and check a defined type of files(.df). I use "checkfile.x" which is a compiled program to check those files. Sintaxis : checkfile.x DatefileName.df The program displays something like this: File: kanswer.df -... (1 Reply)
Discussion started by: Testing_Yorsh
1 Replies
Login or Register to Ask a Question