LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-02-2013, 07:10 PM   #1
soupmagnet
LQ Newbie
 
Registered: Sep 2012
Posts: 27

Rep: Reputation: Disabled
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.

Last edited by soupmagnet; 01-02-2013 at 07:12 PM.
 
Old 01-03-2013, 09:09 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,185

Rep: Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586Reputation: 1586
Try:
Code:
ssh root@your_ip "if [ -d '/directory_name' ]; then echo 'yep, that directory is there'; fi;"
 
1 members found this post helpful.
Old 01-03-2013, 10:31 AM   #3
soupmagnet
LQ Newbie
 
Registered: Sep 2012
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by szboardstretcher View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Use SOCKS proxy running on a remote machine shadyabhi Linux - Networking 3 01-16-2014 02:12 AM
[SOLVED] SSH remote command: Pipe remote output to local machine? kenneho Linux - Server 6 12-06-2012 01:37 AM
can I check HP CP-1215 toner levels from a remote machine? garydale Linux - Hardware 3 12-03-2010 09:52 AM
How to check the Listening url in the remote machine winxandlinx Linux - Security 5 07-11-2010 08:56 PM
running shell command on remote machine with ssh qrshat Solaris / OpenSolaris 3 08-17-2006 07:32 AM


All times are GMT -5. The time now is 12:47 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration