ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
hi guys,
I have several servers and i want to make use of 1 of them to do some simple monitoring. It should be able check the process of other servers. What i did is
for SERVER in ${SERVERS}; do
echo "testing 2"
LINECOUNT= ssh ${SERVER} "ps -ef | grep -v grep |grep -v ${SERVER} | grep ${SERVICE} | wc -l"
echo "linecount is ${LINECOUNT}"
if [ ${LINECOUNT}=0 ]; then
echo " ${SERVICE} is not running."
else
echo " ${SERVICE} is running."
fi
I can run the ps command locally and able to get the result.
But the thing is when i use ssh to execute the remote command, it does return me the output like 1 or 0. What can i do? Thanks in advance
hi nat, i have some other issues over here. I have this script over here but when i run it has this error
./remotechecking.sh: line 15: syntax error near unexpected token `fi'
./remotechecking.sh: line 15: ` fi'
#!/bin/bash -x
LOGFILE=/root/remotechecking.log
exec > ${LOGFILE}
exec 2>&1
SERVERS="testserver testserver2 testserver3"
for SERVER in ${SERVERS}; do
echo "in for loop ${SERVER}"
if [ SERVER="testserver" ]; then
#CHECK_APACHE
echo "in the 2nd loop "
CHECK_WONDERFUL()
fi
done
CHECK_APACHE() {
LINECOUNT=`ssh ${SERVER} "ps -ef | grep -v grep |grep -v ${SERVER} | grep apache" | wc -l`
if [ ${LINECOUNT}=1 ]; then
echo " apache on ${SERVER} is running."
else
echo " apache on ${SERVER} is not running."
fi
}
CHECK_WONDERFUL()
{
LINECOUNT=`ssh ${SERVER} "ps -ef | grep -v grep |grep -v ${SERVER} | grep wonderful" | wc -l`
if [ ${LINECOUNT}=1 ]; then
echo " wonderful on ${SERVER} is running."
else
echo " wonderful on ${SERVER} is not running."
sorry guys, i managed to figure this out. i need to put in a function infront of CHECK_WONDERFUL() and it will be then a method.
I have another question though. Although it can do the check but the log show which i create will show the banner when it ssh into other server, any ways to eliminate the banner?
hi guys..another question....when i run this script,
./remotechecking.sh: line 25: syntax error near unexpected token `done'
./remotechecking.sh: line 25: `done'
anywhere wrong with the else if condition?
9 for SERVER in ${SERVERS}; do
10 echo "in for loop ${SERVER}"
11 if [ ${SERVER}="sinp2ps11" ]; then
12 CHECK_P2PS
13 else if [ ${SERVER}="sinp2ps12" ]; then
14 CHECK_P2PS
15 else if [ ${SERVER}="sinp2ps13" ]; then
16 CHECK_P2PS
17 else if [ ${SERVER}="sinp2ps14" ]; then
18 CHECK_P2PS
19 else if [ ${SERVER}="sindacs" ]; then
20 CHECK_DACS
21 else if [ ${SERVER}="sindts" ]; then
22 CHECK_DTS
23 endif
24
25 done
If we abstract this requirement to its fullest possible extent, what we are left with is the need to explore the status of a particular set of hardware and/or the status of particular running processes on that hardware. This might well prove to be an existing-solution that you might be able to productively leverage or use...
Dictum Ne Agas -- "Do Not Do A Thing Already Done."
hi..i'm not really sure whether nagios covers solaris OS as well so at the meantime, i will be the script to capture what i want and at the same time hosts the finding on a apache server. How do i make use of the information captured to display on a website? shall i run the check on a cron job basis....and the website will extract the information from the log file? or shall i run the check and generate the website after that?
I have another question though. Although it can do the check but the log show which i create will show the banner when it ssh into other server, any ways to eliminate the banner?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.