LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-11-2014, 11:12 AM   #1
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Rep: Reputation: Disabled
Need help with ssh options in a script


Hello, I am trying to implement the below in a script but the escape characters are not working for the regular expressions:

Code:
ssh -n oracle@lnx123 "cd /fmw/admin/scripts/instances/extapp_wt_inst[1-2]/config/OHS/extapp_ohs[1-2]/abcdocs ; touch outage.html " 2>/dev/null
done
I need to run this on sets of two servers, with the below paths -
/fmw/admin/scripts/instances/extapp_wt_inst1/config/OHS/extapp_ohs1/abcdocs
/fmw/admin/scripts/instances/extapp_wt_inst2/config/OHS/extapp_ohs2/abcdocs


I have tried the below using the escape characters but still no luck:

Code:
ssh -n oracle@lnx164 "cd /fmw/admin/scripts/instances/\extapp_wt_inst\\[1-2\\]\/config/OHS/extapp_ohs\\[1-2\\]/abcdocs "
Please let me know how I can correct this?
 
Old 08-11-2014, 11:42 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
It depends on WHERE you want the [1-2] to be interpreted...and WHAT you want to accomplish.

The regular expressions need to be evaluated on the remote system. But you are using them in a "cd" command which can only take one target - the expression [1-2] may be 0 or more.

It is an error if both directories exist on a target.

What are the errors you get from what you tried?
 
Old 08-11-2014, 11:42 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,267

Rep: Reputation: 298Reputation: 298Reputation: 298
Hi

It's complicated. The ssh command gets the parameters without quotes, and so does the shell on the other end. One way to do it, is to mix single and double quotes:

Code:
ssh -n oracle@lnx123 "cd '/fmw/admin/scripts/instances/extapp_wt_inst[1-2]/config/OHS/extapp_ohs[1-2]/abcdocs' ; touch outage.html " 2>/dev/null
Other way is to add quotes inside the parameter with a \ prefix:

Code:
ssh -n oracle@lnx123 "cd \"/fmw/admin/scripts/instances/extapp_wt_inst[1-2]/config/OHS/extapp_ohs[1-2]/abcdocs\" ; touch outage.html " 2>/dev/null
Edit:
Or maybe I misunderstood. You want to cd to any of those 2 if they exist? Then your code should work without any escaping. Does this work?

Code:
ssh -n oracle@lnx123 "touch /tmp/f1 ; touch /tmp/f2 ; ls /tmp/file[1-2]"

Last edited by Guttorm; 08-11-2014 at 11:49 AM.
 
Old 08-11-2014, 11:51 AM   #4
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
Hi jpollard, it will never be possible that both the directories exist on the same target..I want the script to login to those servers at the specified location and create an html file " outage.html "

When I try, it does not evaluates the regular expression and gives the error:

/fmw/admin/scripts/instances/extapp_wt_inst[1-2]/config/OHS/extapp_ohs[1-2]/abcdocs not found
 
Old 08-11-2014, 12:00 PM   #5
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
Hi Guttorm,

I tried the first 2 options you suggested, but both give the same error:

bash: line 0: cd: /fmw/admin/scripts/instances/extapp_wt_inst[1-2]/config/OHS/extapp_ohs[1-2]/abcdocs: No such file or directory

I have to make this work on 2 sets of servers which have different directory names but the same filename has to be created on both.

I don't know if there is any other way to implement this ?

Thanks for ur help!
 
Old 08-11-2014, 12:06 PM   #6
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,267

Rep: Reputation: 298Reputation: 298Reputation: 298
Well, as jpollard said above, the script is not very solid. You can get everything from 0 to 4 directories. It doesn't work without any escaping? And it does work if you ssh first and then run the command? Please post both.
 
Old 08-11-2014, 12:08 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by rraina View Post
Hi jpollard, it will never be possible that both the directories exist on the same target..I want the script to login to those servers at the specified location and create an html file " outage.html "

When I try, it does not evaluates the regular expression and gives the error:

/fmw/admin/scripts/instances/extapp_wt_inst[1-2]/config/OHS/extapp_ohs[1-2]/abcdocs not found
That looks like some combination of config1 extapp_ohs1, 1 2, 2 1, 2 2, do not exist.

I believe your first example should have worked - but only when the path actually exists on the host.

You might verify that /fmw/admin/scripts/instances/extapp_wt_inst1/onfig/OHS/extapp_ohs1/abcdocs (or some combination of the numbers) actually exists.
 
Old 08-11-2014, 01:05 PM   #8
rraina
LQ Newbie
 
Registered: Mar 2013
Posts: 16

Original Poster
Rep: Reputation: Disabled
Hi guys!

Indeed I was trying to go to wrong path ... I feel so silly now !!!

Thanks all for your prompt help.

I got it working without any escape characters.

ssh -n oracle@lnx164 "cd /fmw/admin/instances/APP_WT/extapp_wt_inst[1-2]/config/OHS/extapp_ohs[1-2]/abcdocs ;touch outage.html"

Thanks again!
 
  


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
options -X or -Y on SSH is not working for graphic mode Jorcelangelo Linux - General 4 11-05-2011 03:21 PM
ssh-executed script does not terminate when ssh session killed matthewg42 Linux - General 6 03-24-2011 01:15 PM
Script creation (how to include options in the script) pinga123 Linux - Newbie 7 07-15-2010 06:56 AM
SSH client Keepalive Options metallica1973 Linux - Networking 1 11-21-2008 12:27 PM
ssh logging options danimalz Linux - Security 2 02-14-2006 03:35 AM


All times are GMT -5. The time now is 02:40 AM.

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