LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-08-2011, 07:10 AM   #1
flashback
LQ Newbie
 
Registered: Nov 2009
Location: Milan, Italy
Distribution: Fedora of course !
Posts: 11

Rep: Reputation: 0
ssh remote command


Hi all, the problem:
i need to remote execute a script that check for the content of a remote dir, but with the following script:

Code:
if [[ `ssh mipbmh "if [ `dir /etc/dir/$app | wc -w` -gt "1" ]; then echo ok; else echo ko; fi"` == ok ]];

then ssh mipbmh "dir /etc/dir/$app"; echo

else echo -e "\033[01;38mWARNING /etc/dir/$app is EMPTY\033[00m "
fi
the directory checked is the local directory, the one from where i invoke the script, not the remote one as i supposed...Where am i wrong ?
Thanks.

P.S. of course the host mipbmh is defined in my hosts file and there are no probs when connecting to it.

Thanks ! Roberto.
 
Old 11-08-2011, 07:29 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The command substitution
Code:
`dir /etc/dir/$app | wc -w`
is performed on the local machine, before the ssh command is launched. To avoid this you have to protect the backticks from the local shell, so that they are sent to the remote machine literally
Code:
\`dir /etc/dir/$app | wc -w\`
 
Old 11-08-2011, 07:30 AM   #3
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Why not just do :

Code:
if [ $(ssh mipbmh "dir /etc/dir/$app" | wc -w) -gt "1" ]; then
    ssh mipbmh "dir /etc/dir/$app"; echo
else
    echo -e "\033[01;38mWARNING /etc/dir/$app is EMPTY\033[00m "
fi

Last edited by Cedrik; 11-08-2011 at 07:31 AM.
 
Old 11-08-2011, 07:47 AM   #4
flashback
LQ Newbie
 
Registered: Nov 2009
Location: Milan, Italy
Distribution: Fedora of course !
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
The command substitution
Code:
`dir /etc/dir/$app | wc -w`
is performed on the local machine, before the ssh command is launched. To avoid this you have to protect the backticks from the local shell, so that they are sent to the remote machine literally
Code:
\`dir /etc/dir/$app | wc -w\`
It sounds reasonable, but it's not working...any other hint ?
 
Old 11-08-2011, 07:53 AM   #5
flashback
LQ Newbie
 
Registered: Nov 2009
Location: Milan, Italy
Distribution: Fedora of course !
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Cedrik View Post
Why not just do :

Code:
if [ $(ssh mipbmh "dir /etc/dir/$app" | wc -w) -gt "1" ]; then
    ssh mipbmh "dir /etc/dir/$app"; echo
else
    echo -e "\033[01;38mWARNING /etc/dir/$app is EMPTY\033[00m "
fi
I'll use it, surely better than mine, but i still have to solve the main problem...thanks
 
Old 11-08-2011, 08:14 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by flashback View Post
It sounds reasonable, but it's not working...any other hint ?
Yes, sorry. You need also to escape the escape character. A first command substitution is attempted when the local shell reads the whole if/then command line, a second one is attempted when the local shell performs the ssh command inside the first command substitution:
Code:
\\\`dir /etc/dir/$app | wc -w\\\`
However I agree to keep it simple as Cedrik pointed out.
 
1 members found this post helpful.
Old 11-10-2011, 07:14 AM   #7
flashback
LQ Newbie
 
Registered: Nov 2009
Location: Milan, Italy
Distribution: Fedora of course !
Posts: 11

Original Poster
Rep: Reputation: 0
SOLVED ssh remote command

Thanks a lot, the triple escap solved the problem !
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Remote command execution via SSH and newgrp command SuperMegaMau Linux - General 4 05-13-2011 07:31 AM
Escape command for remote ssh execution brianmcgee Linux - Software 2 06-14-2010 06:34 AM
SSH remote command withouth output Ricio Linux - Newbie 5 10-20-2008 11:44 AM
SSH remote command not timing out tajsss Other *NIX 5 04-28-2005 06:57 AM
remote command over ssh, password prompt linowes Linux - General 2 10-27-2002 08:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:26 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
Open Source Consulting | Domain Registration