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 /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 " |
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? |
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 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 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]" |
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 |
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! |
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.
|
Quote:
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. |
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! |
All times are GMT -5. The time now is 04:23 AM. |