Sponsored Content
Top Forums Shell Programming and Scripting SSH full shell script in 1 line. Post 302582625 by mrwatkin on Friday 16th of December 2011 02:52:02 PM
Old 12-16-2011
SSH full shell script in 1 line.

I'd like to ssh a piece of shell script code into a single ssh command.

As you all know, you could ssh something like this:

Code:
ssh user@host "ls -la"

and receive the output of that command being run on that machine. So, let's say I scripted something on the fly via command line like this:

Code:
%prompt%>for i in 1 2 3 4 5
> do
> echo "i = $i\n"
> done
i = 1

i = 2

i = 3

i = 4

i = 5

%prompt%>

Is there a way to get this bundled into 1 command via an ssh? If I bring up this quick script via the command history, I get:

Code:
for i in 1 2 3 4 5^Jdo^Jecho "i = $i\n"^Jdone

The "^J" won't work. I tried. Is there some character I can use in it's place? I tried \n and \r, but no dice. Just so we're clear, I'm trying to do something like:

Code:
ssh user@host "for i in 1 2 3 4 5^Jdo^Jecho "i = $i\n"^Jdone"

Thanks in advance for your responses.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ssh using shell script

I need to ssh a server using shell script and run certain commands there. Please let me know how to do it . Thanks! (4 Replies)
Discussion started by: asth
4 Replies

2. Shell Programming and Scripting

ssh in shell script

Hi all, I am trying to write a script in shell which can connect me to a remote server and run some commands my problem is i cant pass the password barrier.I read a lot of articles where bloggers have suggested not to use telnet and to use something more secure like ssh.I tried ssh but as soon... (8 Replies)
Discussion started by: pistachio
8 Replies

3. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

4. Shell Programming and Scripting

Executing remote application using ssh without full reference to its location

Hello again :) , My script has an ssh command to run a script on a remote machine. The script has commands such as sqlplus and unzip. However, the return I get in my own terminal says it can't find sqlplus and unzip. the ssh command is: ssh user@host "cd ScriptDir; ./Script.sh" and the... (6 Replies)
Discussion started by: jangozo
6 Replies

5. UNIX for Advanced & Expert Users

SSH key works from CMD line not script

OK , .. This is an odd one. I have a new server and I need to have a tunnel open to it. I have this exact process running on a few others but this new one I just got is not allowing the script to connect. I set up my users account and ssh keys from the server that will host the tunneling i... (6 Replies)
Discussion started by: jeffsandman0035
6 Replies

6. UNIX for Advanced & Expert Users

SSH using shell script terminates the script execution

Hello, I am writing a shell script in which i do ssh to remote server and count the number of files there and then exit. After the exit the shell script terminates which i believe is expected behavior. Can some one suggest me a way where even after the exit the script execution resumes. ... (2 Replies)
Discussion started by: manaankit
2 Replies

7. Shell Programming and Scripting

How to get full sql table data using shell script

i have a Oracle table like col1 col2 ---- ----- a 1 b 2 c 3 when i write a script for it , it gives me all the data in one column. Please give me the solution which gives the exact result like we see in sql editors. for a in `echo " set feedback off; set pagesize 40;... (1 Reply)
Discussion started by: ss135r
1 Replies

8. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

9. UNIX for Dummies Questions & Answers

SSH on a Shell Script

Hello, I'm sure you'd have received a lot of questions like this, but I couldn't find anything relevant to my problem in the first search. Sorry in advance if this is a repeated question. I'm trying to do an SSH inside a shell script and expect the shell script to connect to a remote server... (6 Replies)
Discussion started by: mathbalaji
6 Replies

10. Shell Programming and Scripting

Help with shell script - filter txt file full of ips

Hello again gentlemen. I would like to make a shell script to 'optimize' a plain text full of IPs. Let's suppose to have this text file: 1.192.63.253-1.192.63.253 1.0.234.46/32 1.1.128.0/17 1.116.0.0/14 1.177.1.157-1.177.1.157 1.23.22.19 1.192.61.0-1.192.61.99 8.6.6.6 I want to... (2 Replies)
Discussion started by: accolito
2 Replies
SSH-COPY-ID(1)						      General Commands Manual						    SSH-COPY-ID(1)

NAME
ssh-copy-id - install your public key in a remote machine's authorized_keys SYNOPSIS
ssh-copy-id [-i [identity_file]] [user@]machine DESCRIPTION
ssh-copy-id is a script that uses ssh to log into a remote machine and append the indicated identity file to that machine's ~/.ssh/autho- rized_keys file. If the -i option is given then the identity file (defaults to ~/.ssh/id_rsa.pub) is used, regardless of whether there are any keys in your ssh-agent. Otherwise, if this: ssh-add -L provides any output, it uses that in preference to the identity file. If the -i option is used, or the ssh-add produced no output, then it uses the contents of the identity file. Once it has one or more fin- gerprints (by whatever means) it uses ssh to append them to ~/.ssh/authorized_keys on the remote machine (creating the file, and directory, if necessary.) NOTES
This program does not modify the permissions of any pre-existing files or directories. Therefore, if the remote sshd has StrictModes set in its configuration, then the user's home, ~/.ssh folder, and ~/.ssh/authorized_keys file may need to have group writability disabled manu- ally, e.g. via chmod go-w ~ ~/.ssh ~/.ssh/authorized_keys on the remote machine. SEE ALSO
ssh(1), ssh-agent(1), sshd(8) OpenSSH 14 November 1999 SSH-COPY-ID(1)
All times are GMT -4. The time now is 11:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy