Sponsored Content
Top Forums Shell Programming and Scripting Run shell script on another server using ssh Post 302396436 by Corona688 on Thursday 18th of February 2010 12:00:48 PM
Old 02-18-2010
You can accomplish this with simple redirection.
Code:
ssh user@host 'exec bash' < shell-script.sh

This will execute the bash shell on the remote host, and feed bash your shell script. You can substitute any shell of choice for bash of course.

You can even leave out the 'exec bash' argument entirely and it will probably still work, but you will get that login's default shell and not necessarily the one you want.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script for how to connect to a remote server by using ssh

i want to connect to a remote server through ssh. i have to also provide password within that script. after connecting to the remote server i want to do some operations like grep,cd etc can u pls help me to wite a script. Thanks (1 Reply)
Discussion started by: millan
1 Replies

2. Programming

Expect script to run a Shell script on remote server

Hi All, I am using a expect script to run a shell script on remote server, the code is as follows. But the problem is that it executes only first command, and hangs it doesn't run the next commands. spawn ssh $uid@$host expect "password:" send "$password\r" expect "*\r" send... (2 Replies)
Discussion started by: yashwanthsn
2 Replies

3. Shell Programming and Scripting

ssh - run shell script - Error

Hi Team, I am trying to run shell script from one server to another server with below command. ssh abc@pqr.america.com /tmp/test.ksh But, it gives below error. Can someone help me what is the issue? exec(): 0509-036 Cannot load program ssh because of the following errors: ... (3 Replies)
Discussion started by: ace_friends22
3 Replies

4. Shell Programming and Scripting

shell script to run after ssh logout from another machine

Scenario: I currently manager a cluster at work which is on a private network and i constantly need to ssh to other clients for diags e.t.c. I created a debain client which i use as my gateway to get to all the clients on the private network and I then created a Shell menu script which will make... (4 Replies)
Discussion started by: defamer
4 Replies

5. Shell Programming and Scripting

run query in shell script after ssh

Hi, I need to run sql query in shell script after getting connected to ssh. For that I connected to ssh through shell script using RSA keys done]. Now when I am running sql query, it's not working... but several other commands like 'ls'. 'mkdir', etc are working properly. Here is my code: ... (2 Replies)
Discussion started by: shekhar2010us
2 Replies

6. UNIX for Dummies Questions & Answers

ssh command to execute shell script in another server

ssh -q <hostname> /opt/tcs/satish/tst.ksh ssh -q <anotherserver> /opt/tcs/satish/tst.ksh tst.ksh has "nohup <command> & " when i execute below script , its throwing error as nohup can not be found ssh -q <anotherserver> /opt/tcs/satish/tst.ksh > log & can someone let me... (5 Replies)
Discussion started by: only4satish
5 Replies

7. UNIX for Dummies Questions & Answers

how to use ssh to run shell script on a remote machine?

how to use ssh to run shell script on a remote machine? ssh user@remote sh ./script.unx i ran the above command ./script.unx HAS NOHUP COMMAND IN ITS BODY, I AM GETTING ERROR AS NOHUP NOT FOUND... i tried to run that script from remote server, its working fine do ineed to set... (6 Replies)
Discussion started by: only4satish
6 Replies

8. Shell Programming and Scripting

Switching server in UNIX via shell script (SSH )

Requirement: I am writing a shell script which take some file from say Server1 and I have to execute some command on Server2 then I have to manipulate the data and based on that I have to produce report. Problem:I can schedule the shell script on only one server (Server1 or Server2) So, In the... (3 Replies)
Discussion started by: raks2301
3 Replies

9. Ubuntu

Run a script at remote server without ssh password

Hello, What I want to do is to run a file on remote server by running a script at localhost but script should not ask ssh password of my remote server when script is executed. Scenario1: To copy files from server2 to data server:$ scp -r root@server2_ip:/var/www/html/*.* /var/ When I enter... (6 Replies)
Discussion started by: baris35
6 Replies

10. Shell Programming and Scripting

Except script to run a local shell script on remote server using root access

local script: cat > first.sh cd /tmp echo $PWD echo `whoami` cd /tmp/123 tar -cvf 789.tar 456 sleep 10 except script: cat > first #!/usr/bin/expect set ip 10.5.15.20 set user "xyz123" set password "123456" set script first.sh spawn sh -c "ssh $user@$ip bash < $script" (1 Reply)
Discussion started by: Aditya Avanth
1 Replies
SSH2_PUBLICKEY_ADD(3)							 1						     SSH2_PUBLICKEY_ADD(3)

ssh2_publickey_add - Add an authorized publickey

SYNOPSIS
bool ssh2_publickey_add (resource $pkey, string $algoname, string $blob, [bool $overwrite = false], [array $attributes]) DESCRIPTION
Note The public key subsystem is used for managing public keys on a server to which the client is already authenticated. To authenticate to a remote system using public key authentication, use the ssh2_auth_pubkey_file(3) function instead. PARAMETERS
o $pkey - Publickey Subsystem resource created by ssh2_publickey_init(3). o $algoname - Publickey algorithm (e.g.): ssh-dss, ssh-rsa o $blob - Publickey blob as raw binary data o $overwrite - If the specified key already exists, should it be overwritten? o $attributes - Associative array of attributes to assign to this public key. Refer to ietf-secsh-publickey-subsystem for a list of supported attributes. To mark an attribute as mandatory, precede its name with an asterisk. If the server is unable to support an attribute marked mandatory, it will abort the add process. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Adding a publickey with ssh2_publickey_add(3) <?php $ssh2 = ssh2_connect('shell.example.com', 22); ssh2_auth_password($ssh2, 'jdoe', 'password'); $pkey = ssh2_publickey_init($ssh2); $keyblob = base64_decode(' AAAAB3NzaC1yc2EAAAABIwAAAIEA5HVt6VqSGd5PTrLRdjNONxXH1tVFGn0 Bd26BF0aCP9qyJRlvdJ3j4WBeX4ZmrveGrjMgkseSYc4xZ26sDHwfL351xj zaLpipuBGRrw17mWVBhuCExo476ri5tQFzbTc54VEHYckxQ16CjSTibI5X 69GmnYC9PNqEYq/1TP+HF10='); ssh2_publickey_add($pkey, 'ssh-rsa', $keyblob, false, array('comment'=>"John's Key")); ?> SEE ALSO
ssh2_publickey_init(3), ssh2_publickey_remove(3), ssh2_publickey_list(3). PHP Documentation Group SSH2_PUBLICKEY_ADD(3)
All times are GMT -4. The time now is 03:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy