LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Check for condition on remote machine before running command? (https://www.linuxquestions.org/questions/linux-newbie-8/check-for-condition-on-remote-machine-before-running-command-4175443886/)

soupmagnet 01-02-2013 07:10 PM

Check for condition on remote machine before running command?
 
Is it possible to, via use of a shell script, to check for a condition (if;then) on a remote machine before executing a command or series of commands on the local machine?

I have 3 different Linux systems that connect to a Mac for backups and other various tasks. I would like to, for example, be able to check the remote machine (Mac) for a certain directory with the current date. If that directory doesn't exist, then the local machine (Linux) will create that directory and perform various tasks on the remote machine.

I want to run said script from, a daily cronjob possibly, on whichever of the three Linux systems is booted first. But I don't want it to run the various tasks for any particular day, again, when/if the other systems are booted afterwards. There is no way to predict which of the three Linux systems will be booted first on any particular day, or whether or not any of the others will be booted at all.

And I do I have a working password-less ssh connection from each of the Linux machines to the remote machine...if that helps.

szboardstretcher 01-03-2013 09:09 AM

Try:
Code:

ssh root@your_ip "if [ -d '/directory_name' ]; then echo 'yep, that directory is there'; fi;"

soupmagnet 01-03-2013 10:31 AM

Quote:

Originally Posted by szboardstretcher (Post 4862095)
Try:
Code:

ssh root@your_ip "if [ -d '/directory_name' ]; then echo 'yep, that directory is there'; fi;"

Thank you. I tried that several times before, but without the quotes. Works perfectly now.


All times are GMT -5. The time now is 07:09 PM.