Check/get the exit status of a remote command executed on remote host through script
Geeks,
Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s).
Here's the complete requirement.
From one server I need to ssh to all servers, check if desired processes are running and send out a consolidated email of all servers that are not running desired processes.
In some cases the server needs to be checked on 3-5 processes, they all need to be on the same script if possible else a different script.
This one works well as expected, when I run on single host from command line.
I need this
Thanks,
Saikrishna
Last edited by Don Cragun; 08-26-2015 at 10:42 PM..
Reason: Add CODE tags.
Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s).
Here's the complete requirement.
From one server I need to ssh to all servers, check if desired processes are running and send out a consolidated email of all servers that are not running desired processes.
In some cases the server needs to be checked on 3-5 processes, they all need to be on the same script if possible else a different script.
This one works well as expected, when I run on single host from command line.
I need this
Thanks,
Saikrishna
First, note that this script adds notes about failures to the end of existing text in /var/tmp/failed.txt. So, once an error is detected, future invocations of this script will add new failures to the end of the existing list instead of starting with a clean slate each time you run the script. Why output anything at all if the server is running the command you're looking for? Why print a blank line?
Second, you should ssh to a single server (presumably $i) instead of to your entire list of servers ($Server_List) in your loop. Assuming $Server_List expands to more than one word, your current command will always fail with a syntax error.
Third, you aways send mail even if no errors were detected.
Fourth, if you are trying to count the number of lines in ps output that match a certain string, why are you throwing away the output before counting the number of lines found?
Fifth, the output from wc -l contains some leading spaces (unless the number of lines counted is 10 million or larger); so a string comparison between the output from wc -l and "1" can never match.
And, finally, if the command:
works to check the status of a single server, why are you using a different command to check the status of each server in your loop? What is it about the command above that tells you whether or not the command you're looking for is running on that server? Why can't you script determine whether or not the command you're looking for is running on any server when you run it inside your for loop?
We only need to report in case of failures, if the process is running as expected then no need to report.
For all failures in servers list it should append to the file /var/tmp/failed.txt so that we can send out all in 1 email.
List of servers are different, so processes running on them differ. I can append wc -l at the end of script for string comparison if that can address the issue.
Due to large volume of servers its hard to manage/insert script on all servers, we need one host to check for errors and report through email on exact failure, so if new servers are added to list along with new processes then we can just edit/update script in 1 place rather than 1000+.
I will update the script to send email only incase of failures or /var/tmp/failed.txt is found.
Hi all, posting my first time, hope not breaking posting rules with it, if yes, let me know.
I'm trying to build a script to check a file in an sftp server through a remote server.
The intention is to check the file in a sftp host, and if the file is found or not, it should send an email.... (4 Replies)
I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code
TARFILE=${NAME}.tar
TARGZFILE=${NAME}.tar.gz
ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Hi,
Given addresses of 2 remote machines, using a shell script is it possible to
get the state of running processes in "src"
stop all the processes in "src"
exit out of "src"
ssh into "dest"
resume the state of executing processes captured in step 1 in "dest"
Assumption:
"src" is... (3 Replies)
Hello,
Is there any way to check which user and from which IP executed a command to the server.I need something like the history but with information also from which IP the command executed.
Thanks in advance (8 Replies)
Hi all,
I'm trying to run the sipp simulator in crontab but after some attempt I came to the conclusion that for some reason this isn't possible (maybe due to sipp interactive nature).
This is confirmed by these posts.
Now I'm trying to launch sipp from an expect script that runs in crontab.
... (0 Replies)
Hi there
I am in the process of writing a script to check whether a port on a remote system is up or not.
Here's what I have so far:
#!/bin/bash
telnet xx.xx.xx.xx 80 | (echo "^]")
if ]; then
echo "Please check Web services " | mailx -s "Please check webservices... (1 Reply)
Hi,
My script needs to check whether the remote host is up or not.
If it is up i need to start few servers in that host or else just a notification should be sent that the remote host is down?
Could someone help me out in this?
Regards
Arun (4 Replies)
Hi to everyone.
How can I get the exit status from a remote command executed with rexec? :eek:
machine A has RedHat Linux 9 and the remote machine B has SCO UNIX.
Code:
rexec -l user -p password host sh /u/files/scripts/seq_cal.sh 2006 08
I want the exit status returned by... (1 Reply)
I am executing a find command in my script i.e
find $2 -type f -name '*.gif' -mtime +$1 -exec rm {} \;
how do i check that this command is executed properly.. i would lke t trap the errror and display my error message
kinly help.. this is an urgent issue. (1 Reply)