LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 06-12-2018, 07:02 AM   #1
sumitsahay
LQ Newbie
 
Registered: Jun 2018
Posts: 13

Rep: Reputation: Disabled
Post Space in parameter while running command using ssh


Hi All,

I am running ansible playbook using ssh command but in that command I am not able to pass the parameter as it is not taking the space between the string, it accepting the first character and skipping the next as there is one space between that.

ssh user_name@host_ip -C /usr/bin/ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface Gi1/0/16"' --limit $query_baselocation-$query_sublocation-$query_building >& /tmp/test.log

As you can see above it is taking only the "Interface" as parameter and not the "Gi1/0/16"

I checked with ansible forum as well but it is not the ansible issue as because when I am running this command without using ssh it is working fine.

Looking forward for your reply.

Thanks & Regards
Sumit Sahay
 
Old 06-12-2018, 07:20 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
you might need to escape that space using one or two backslashes.
 
Old 06-12-2018, 07:23 AM   #3
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Sometimes when you're doing a command within a command within a command one layer strips off the quoting for its use so it doesn't get passed to the next layer.

It may be doing something as simple as putting another level of quotes around it will help:
Code:
""interface Gi1/0/16""
Sometimes you have to get more creative by escaping quotes to make them get passed literally:
Code:
\"interface Gi1/0/16\"
It may be you have to quote even more of what you're passing.
 
Old 06-12-2018, 07:41 AM   #4
sumitsahay
LQ Newbie
 
Registered: Jun 2018
Posts: 13

Original Poster
Rep: Reputation: Disabled
Post

Quote:
Originally Posted by MensaWater View Post
Sometimes when you're doing a command within a command within a command one layer strips off the quoting for its use so it doesn't get passed to the next layer.

It may be doing something as simple as putting another level of quotes around it will help:
Code:
""interface Gi1/0/16""
Sometimes you have to get more creative by escaping quotes to make them get passed literally:
Code:
\"interface Gi1/0/16\"
It may be you have to quote even more of what you're passing.
Hi,

Thanks for your reply.

ssh user_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc=""interface Gi1/0/16/""' --limit BNG-TMEC-ITC5

while running this I am getting this as below

ERROR! the playbook: Gi1/0/16/ could not be found as it is taking "Interface" only no the character after space.

ssh user_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface Gi1/0/16/"' --limit BNG-TMEC-ITC5

I am getting this error,

ERROR! the playbook: Gi1/0/16/" could not be found

As in parameter I am unable to pass the space between string.

Please suggest me for this issue.

Looking forward for your reply.

Thanks & Regards
Sumit Sahay
 
Old 06-12-2018, 07:45 AM   #5
sumitsahay
LQ Newbie
 
Registered: Jun 2018
Posts: 13

Original Poster
Rep: Reputation: Disabled
Post

Quote:
Originally Posted by pan64 View Post
you might need to escape that space using one or two backslashes.
Hi,

Thanks for your reply.

I used as suggested by you as below,

ssh user_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface\\Gi1/0/16/"' --limit host_name

TASK [debug] *******************************************************************
ok: [host_ip] => {
"changed": false,
"msg": "interface\\Gi1/0/16/"

}

ssh user_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface\Gi1/0/16/"' --limit host_name

TASK [debug] *******************************************************************
ok: [host_ip] => {
"changed": false,
"msg": "interface\\Gi1/0/16/"
}

Looking forward for your reply.

Thanks & Regards
Sumit Sahay
 
Old 06-12-2018, 08:07 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
I can't see the space in your last post.
 
Old 06-12-2018, 08:54 AM   #7
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,372

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Looks like a quoting problem.
Perhaps put the entire command in double quotes (so that $query can still be interpreted) and escape the space character in the extra variable setting.
Code:
ssh user_name@host_ip -C "/usr/bin/ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e switch_desc=interface\ Gi1/0/16 --limit $query_baselocation-$query_sublocation-$query_building >& /tmp/test.log"
 
Old 06-13-2018, 02:05 AM   #8
sumitsahay
LQ Newbie
 
Registered: Jun 2018
Posts: 13

Original Poster
Rep: Reputation: Disabled
Post

Quote:
Originally Posted by pan64 View Post
I can't see the space in your last post.
Hi,

I am using following command like below,

ssh user_name@host_ip -C
ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface Gi1/0/16/"' --limit host_name

As you can see there is one space between interface and Gi1/0/16/

When I am running the command it is taking only interface as parameter and not the full string.

Looking forward for your suggestion.

Thanks & Regards
Sumit Sahay
 
Old 06-13-2018, 02:07 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Quote:
Originally Posted by sumitsahay View Post
Looking forward for your suggestion.
see post #2
 
Old 06-13-2018, 02:17 AM   #10
sumitsahay
LQ Newbie
 
Registered: Jun 2018
Posts: 13

Original Poster
Rep: Reputation: Disabled
Post

Quote:
Originally Posted by pan64 View Post
see post #2
ssh user_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface\\Gi1/0/16/"'
--limit host_name

Output:
TASK [debug] *******************************************************************
ok: [host_ip] => {
"changed": false,
"msg": "interface\\Gi1/0/16/"
}

ssh user_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface\Gi1/0/16/"' --limit host_name

TASK [debug] *******************************************************************
ok: [host_ip] => {
"changed": false,
"msg": "interface\\Gi1/0/16/"
}

this is what I am getting while adding one or more backslash.

Looking forward for your suggestion.

Regards
Sumit Sahay
 
Old 06-13-2018, 02:21 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,863

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
see post #6
Where is the space now (between interface and Gi1/0/16/)?
 
Old 06-13-2018, 02:28 AM   #12
sumitsahay
LQ Newbie
 
Registered: Jun 2018
Posts: 13

Original Poster
Rep: Reputation: Disabled
Post

Quote:
Originally Posted by pan64 View Post
see post #6
Where is the space now (between interface and Gi1/0/16/)?

ssh usr_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface Gi1/0/16/"' --limit host_name



TASK [debug] *******************************************************************
ok: [host_ip] => {
"changed": false,
"msg": "interface"
}

If we pass the space between interface and Gi1/0/16 it is taking interface and skipping Gi1/0/16.


Looking forward for your suggestion.


Regards
Sumit Sahay
 
Old 06-13-2018, 08:22 AM   #13
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Don't replace the space with \\. Put \\ to the left of the space, but keep the space like this: \\<space>
 
Old 06-13-2018, 11:11 AM   #14
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
OP. You're getting good advice here, but you need to put your commands and outputs in [code] tags to preserve the spacings.
 
Old 06-14-2018, 03:58 AM   #15
sumitsahay
LQ Newbie
 
Registered: Jun 2018
Posts: 13

Original Poster
Rep: Reputation: Disabled
Post

Quote:
Originally Posted by AwesomeMachine View Post
Don't replace the space with \\. Put \\ to the left of the space, but keep the space like this: \\<space>
Thanks for your reply.

I did as you suggested in this post, like this I did

ssh user_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface\\<space> Gi1/0/16/"' --limit host_name

Output
TASK [debug] *******************************************************************
ok: [host_ip] => {
"changed": false,
"msg": "interface\"
}

ssh user_name@host_ip -C ansible-playbook -i ./hosts /ansibleplaybooks/switch_conf_desc.yml -e'switch_desc="interface\\ Gi1/0/16/"' --limit host_name

Output
TASK [debug] *******************************************************************
ok: [host_ip] => {
"changed": false,
"msg": "interface\"
}


Looking for your suggestions.

Regards
Sumit Sahay
 
  


Reply



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
Help with error running command over SSH pearemb Linux - Newbie 21 12-05-2015 01:41 PM
[SOLVED] How-to set a parameter in the command line to be used later by a user-space script? Didier Spaier Linux - Kernel 5 03-02-2013 05:40 AM
How to find out free disk space by running command deepak_message Linux - Server 5 09-26-2012 07:28 AM
Keep running a command when disconnect from SSH stuartornum Linux - General 3 02-17-2006 10:19 PM
problem in running ssh command skvasistha Linux - General 1 11-29-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:48 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