Remote script over ssh execution issues.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remote script over ssh execution issues.
# 8  
Old 06-08-2015
Your code is now escaping special characters and printing server name. But it is also printing below line after each server's output.

Code:
 /<Oracle_home>/ohs/bin/odl_rotatelogs -h:/<app_Home>/config/OHS/ohs1/component_events.xml_ohs1
/<Oracle_home>/ohs/bin/odl_rotatelogs -h:/<app_Home>/config/OHS/ohs1/component_events.xml_ohs2
 serverA1 awk server=serverA1

How do I suppress that?



Last edited by kchinnam; 06-08-2015 at 03:15 PM.. Reason: more info
# 9  
Old 06-09-2015
Or, if you quote EOF all expansion is disabled, this does leave you to resolve server on the remote side perhaps you could use hostname like this:

Code:
ssh $server "bash -s" << "EOF"
ps -ef | awk -v server=$(hostname -s) '/[r]otate/ && /config/ {print server, $8" "$10}'
EOF

# 10  
Old 06-09-2015
Code:
server=$(hostname -s)

is resolving hostname to local hostname.

Below code is working.. but I am not sure how its working, can you explain?
Code:
 
 ps -ef | awk -v "server=$server" '/[r]otate/ && /config/ {print server, \$8" "\$10}'

it is filtering out
Code:
serverA1 awk server=serverA1

# 11  
Old 06-09-2015
That's the awk process itself. It should not be matched due to the [r] brackets. Are you sure you used above command pipe?

Add a 1 between closing brace and closing quote and post the result.
This User Gave Thanks to RudiC For This Post:
# 12  
Old 06-09-2015
The quotes around "EOF" are important, they stop this local-side expansion of the $() command substitution eg:

Code:
$ hostname -s
MyPC

$ ssh MyServer <<EOF
   echo $(hostname -s)
EOF
MyPC

$ ssh MyServer <<"EOF"
  echo $(hostname -s)
EOF
MyServer

This User Gave Thanks to Chubler_XL For This Post:
# 13  
Old 06-26-2015
This is really useful, I am having fun with this capability..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exiting the Remote server after script execution

Hi All , I'm running a script abc.sh in server "host1" shown as below : #! /bin/bash sh stop.sh ssh user@$host2 "/home/user/prod_work/xyz.sh; sh start.sh The problem I am facing is , the control is not passed to host1 after executing the script "xyz.sh" in host2 . ... (12 Replies)
Discussion started by: Pradeep_1990
12 Replies

2. Shell Programming and Scripting

Shell Script execution issues

Hi, There's a shell script by name "download", which has been created as user "mgr" and that script needs to executed as user "dev". I tried giving privileges 701 on the script download. But it's throwing the error message bin]$ ./download /bin/bash: ./download: Permission denied ... (6 Replies)
Discussion started by: venkatesh17
6 Replies

3. Shell Programming and Scripting

output from remote server during execution of a script

How to see the output from remote server during execution of a script ? I am executing a script (ls) from machine 1 but the o/p should be displayed in machine 2. Can I achieve this ? Example:- Machine 1:- # ls Machine 2:- (console) file1 file2 file 3 dir1 dir2 (0 Replies)
Discussion started by: frintocf
0 Replies

4. HP-UX

Remote ssh execution and .profile issues

Greetings, i'm currently having issues in successfully executing a script from one server to other, and i'm cracking my nut in understanding why. Let's get started with the default info: Server A: briozzo@A:/home/briozzo $ uname -a HP-UX A B.11.31 U ia64 2787251109 unlimited-user license ... (3 Replies)
Discussion started by: nbriozzo
3 Replies

5. Programming

Perl script remote execution as another user

Hi gurus, I have a requirement where I need to remotely run a perl script as another user. Running the script locally as the required user is fine, however I need to su with the script due to filesystem permission issues. I do not want to update permissions on the remote server due to security... (5 Replies)
Discussion started by: melias
5 Replies

6. Cybersecurity

Log remote execution over SSH

If a user execute commands remotely over ssh : $ ssh USERNAME@SERVER COMMANDSHow the SERVER administrator can log those COMMANDS executed in a "not a tty" session ? I searched for my question and get the following suggestions:Anybody give help how to do this ? what the content of "/bin/bash "... (1 Reply)
Discussion started by: new0h
1 Replies

7. Shell Programming and Scripting

help with remote execution of a script

does anyone know how can i execute a script which i locally run as " . /etc/local/host/src.srvr -D ." need to execute above command in rexec command. if i put the command as it is it does not run. Sorry but i am naive in scripting. Thanks rexec sgplqim -l vau -n ' ' (0 Replies)
Discussion started by: NK4U
0 Replies

8. Shell Programming and Scripting

ssh can't back from remote host during script execution

Hi all I wrote a script to execute a script on several remote hosts, but somehow during the execution of the local script, ssh can't come back from the remote host, so that causes my local script hanging... I use the below command to do the job in the local script, any idea? ssh... (12 Replies)
Discussion started by: bzylg
12 Replies

9. Shell Programming and Scripting

problem with remote execution of script using telnet

Hi all, i am trying to remotely execute a script from a different server. this is the code that i use : #!bin/sh pwd (sleep 1 echo "username" sleep 2 echo "pwd" sleep 2 echo "cd /path/to/file" if then echo "script1.sh" echo "mailx -s "Task Executed"... (1 Reply)
Discussion started by: sais
1 Replies

10. Shell Programming and Scripting

Issues using ssh from crontab to run remote script from

I have a solaris9 x86 server using ssh as follows: SSH Version Sun_SSH_1.0, protocol versions 1.5/2.0. The remote server solaris9 sparc has exactly the same version ssh installed. I am running a script on my server which includes the following command to run a script on the remote server:... (4 Replies)
Discussion started by: frustrated1
4 Replies
Login or Register to Ask a Question