Check if remote process is running (linux)

CdSdw

I have the following code that will check if a script (named my_script.sh) is running:

ps cax | grep my_script.sh > /dev/null
if [ $? -eq 0 ]
then
    echo "Process is running."
else
    echo "Process is not running."
fi

However, I'd like to modify this to check if the process is running on another machine, without ssh'ing directly, since this breaks me out of the current script if I'm running it in a loop.

In essence, I'd like to do this:

ssh otherMachine
ps cax | grep my_script.sh > /dev/null
if [ $? -eq 0 ]
then
    echo "Process is running."
else
    echo "Process is not running."
fi
ssh originalMachine

Any help would be appreciated. Thanks!

matteo martelli

I am not sure this is what you are looking for but you can execute the check command in the remote machine direcly inside a ssh call. The return value should correspond to the return value of the command invoked in the remote machine.

Of course you need a passwordless authentication method enabled (e.g. ssh keys).

ssh otherMachine "ps cax | grep my_script.sh > /dev/null"
if [ $? -eq 0 ]
then
    echo "Process is running."
else
    echo "Process is not running."
fi

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Check if remote process is running (linux)

From Dev

Check if a process is running on a remote machine

From Dev

How can I check if a process is running in Linux?

From Dev

Linux Script to check if process is running and act on the result

From Dev

How to check is a certain process is running - java on linux

From Dev

How to check is a certain process is running - java on linux

From Dev

Check if process is running on multiple remote computers and copy a file if process is NOT running, keep list of those which succeeded

From Dev

Running process on a remote browser

From Dev

Check if a process is running or not?

From Dev

Check if a process is running on Bosun

From Dev

Check if process is running and kill it

From Dev

Check if process is running - Windows

From Dev

Running Commands on a Remote Linux

From Dev

running a process in background in linux

From Dev

How to check if a process is running on Windows?

From Dev

How to check the process is already running or not

From Dev

How to check the process is already running or not

From Dev

Shell script to check if process is running

From Dev

Check if a process is running with shell script

From Dev

running Xvfb in background on remote linux

From Dev

Remote debugging running process inside docker container

From Dev

Getting PID for a process running on a remote node

From Dev

Echo whether a process is running on a range of remote computers

From Dev

Test if process is running on remote units and output to log

From Dev

Running one process in parallel linux

From Dev

Running one process in parallel linux

From Dev

Keeping a process running in a linux machine

From Dev

Check on variable Remote Process, if done continue

From Dev

How to check if the remote rsyslog client is running

Related Related

  1. 1

    Check if remote process is running (linux)

  2. 2

    Check if a process is running on a remote machine

  3. 3

    How can I check if a process is running in Linux?

  4. 4

    Linux Script to check if process is running and act on the result

  5. 5

    How to check is a certain process is running - java on linux

  6. 6

    How to check is a certain process is running - java on linux

  7. 7

    Check if process is running on multiple remote computers and copy a file if process is NOT running, keep list of those which succeeded

  8. 8

    Running process on a remote browser

  9. 9

    Check if a process is running or not?

  10. 10

    Check if a process is running on Bosun

  11. 11

    Check if process is running and kill it

  12. 12

    Check if process is running - Windows

  13. 13

    Running Commands on a Remote Linux

  14. 14

    running a process in background in linux

  15. 15

    How to check if a process is running on Windows?

  16. 16

    How to check the process is already running or not

  17. 17

    How to check the process is already running or not

  18. 18

    Shell script to check if process is running

  19. 19

    Check if a process is running with shell script

  20. 20

    running Xvfb in background on remote linux

  21. 21

    Remote debugging running process inside docker container

  22. 22

    Getting PID for a process running on a remote node

  23. 23

    Echo whether a process is running on a range of remote computers

  24. 24

    Test if process is running on remote units and output to log

  25. 25

    Running one process in parallel linux

  26. 26

    Running one process in parallel linux

  27. 27

    Keeping a process running in a linux machine

  28. 28

    Check on variable Remote Process, if done continue

  29. 29

    How to check if the remote rsyslog client is running

HotTag

Archive