Sponsored Content
Top Forums Shell Programming and Scripting Need solution for my bash script executed localy for ssh remote machine Post 303046062 by RudiC on Wednesday 22nd of April 2020 04:01:57 PM
Old 04-22-2020
man bash is your friend:
Quote:
Here Documents
This type of redirection instructs the shell to read input from the current source until a line containing only delimiter (with no trailing blanks)
is seen. All of the lines read up to that point are then used as the standard input (or file descriptor n if n is specified) for a command.

The format of here-documents is:

[n]<<[-]word
here-document
delimiter

No parameter and variable expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion, the character sequence \<newline> is ignored, and \ must be used to quote the characters \, $, and `.


You are in a dilemma here: you want the IP variable expanded locally, but the other variables expanded remotely. For the first, you can't have the "word" quoted, but it must be unquoted, so, for the second, you need to apply the escapes for the $ signs.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

executng program on remote machine using ssh

I am trying to search and remove files from a list of servers. I want to find every occurence of this file on each machine and then remove it. If I execute the find command on the remote machine I would like to be able to pipe the output to xargs and remove the file. Does anyone know hat would be... (1 Reply)
Discussion started by: sewood
1 Replies

2. Shell Programming and Scripting

executing command in a remote machine through ssh - shell script

Hi All, i have two machines like x and y . my requirement is i should connect to machine Y from x through ssh connection . and do some operation such as copy and move and delete files in Y machine . i tried with this code but it is doing in machine x only . and i need to exit from Y when... (1 Reply)
Discussion started by: rateeshkumar
1 Replies

3. Shell Programming and Scripting

Cannot create variables via ssh on remote machine

Hello to all Background info: Local machine : Linux, /bin/bash Remote machine (for the user used for ssh) : SunOs, /bin/ksh (so we have different OS, different Shells) My problem : From the local host i execute $ var=bla $ result=$(ssh -q user@remote-machine " > echo \"this is... (12 Replies)
Discussion started by: black_fender
12 Replies

4. 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

5. Shell Programming and Scripting

bash script to execute a command remote servers using ssh

Hello, I am running into few issues, please suggest me what I am missing. I am running this script on a linux host. Main idea of this script is to, login to each host via ssh and get uid of user, service user that I trying to run this script, has already deployed ssh keys and provide sudo... (8 Replies)
Discussion started by: bobby320
8 Replies

6. Shell Programming and Scripting

Mount fails (because remote machine is off) bash script stops

Hi, I'm trying to automate a couple of mounts. (I would do this in fstab, but the auto feature causes the virtual machine I'm running in to freeze when it boots up) If the machine I'm trying to connect to is OFF, I get the host unreachable error and then the bash script stops. The problem is... (3 Replies)
Discussion started by: jdilts
3 Replies

7. Red Hat

iptables applied in local machine, can't ssh remote machine after chain changed to DROP

I want to SSH to 192.168.1.15 Server from my machine, my ip was 192.168.1.99 Source Destination was UP, with IP 192.168.1.15. This is LAN Network there are 30 Machine's Connected to the network and working fine, I'm Playing around the local machine's because I need to apply the same rules in... (2 Replies)
Discussion started by: babinlonston
2 Replies

8. Linux

Executing a script in remote machine through ssh

How to execute a script in remote machine through ssh I have a script test.sh which does some backup activity in remote machine. Wanted to keep backup also in remote machine. ssh -l username <remote machine> "commands to be exceuted as ; separted" but how to put the script in the place of... (5 Replies)
Discussion started by: sanvel
5 Replies

9. Shell Programming and Scripting

Check/get the exit status of a remote command executed on remote host through script

Geeks, Could you please help me out in my script and identify the missing piece. I need to check/get the exit status of a remote command executed on remote host through script and send out an email when process/processes is/are not running on any/all server(s). Here's the complete... (5 Replies)
Discussion started by: lovesaikrishna
5 Replies

10. Shell Programming and Scripting

Ssh bash script exits without remote command completion

Hi, My goal is to connect from unix server A to windows server B and call a bat file on windows. I am able to succeed in remoting to windows and executing a command, the issue i am facing is the shell scrip is exiting without making sure of bat file success. Can you please help me in... (4 Replies)
Discussion started by: pxp018
4 Replies
MUSSH(1)							   MUltihost SSH							  MUSSH(1)

NAME
mussh - MUltihost SSH SYNOPSIS
mussh [ OPTIONS ] <-h host... | -H hostfile > [-c cmd ] [-C scriptfile ] DESCRIPTION
mussh is a shell script that allows you to execute a command or script over ssh(1) on multiple hosts with one command. When possible mussh will use ssh-agent(1) and RSA/DSA keys to minimize the need to enter your password more than once. OPTIONS
--help Prints full help text. -d Same as -d 1 -d 0 Turns debug mode off. -d 1 On STDERR prints out basic actions and ssh-agent activity and which host is being connected to. -d 2 Includes all of the output from -d1, the list of hosts, the command/script as it will be executed on each host, and a lot more. -v Same as -v 1 -v 1 Sets ssh in debug1 mode by passing "-v" to ssh. -v 2 Sets ssh in debug2 mode by passing "-v -v" to ssh. -v 3 Sets ssh in debug3 mode by passing "-v -v -v" to ssh. -m [n] Run concurrently on 'n' hosts at a time (asynchronous). Use '0' (zero) for infinite. (default) -q No output unless necessary. This will cancel -d and -v if after them on the command line. It also suppresses the output of each host. This will NOT suppress the password/passphrase prompts required to log into each host. -i <identity> [identity ..] Load an identity file. When -i is used, the specified identity file(s) is loaded instead of the default identity. You can load as many RSA/DSA identities as you'd like. -o <ssh-args> Args to pass to ssh with -o option. See the ssh(1) man page for more info on the -o option. -a Force loading ssh-agent. Without this flag, mussh will not load another agent when one is already loaded. -A Do NOT load ssh-agent. If no agent is loaded you will be prompted for a password or passphrase by ssh for each host. If you do not have RSA/DSA keys for the destination hosts, this will save you some hassle. -b Print each hosts' output in a block without mingling with other hosts' output. -B Allow hosts' output to mingle. (default) -u Unique. Eliminate duplicate hosts. (default) If you a host or user@host occurs more than once across files specified with -H or hosts specified with -h, the host or user@host is used only once. -U Do NOT make host list unique. This simply overrides the -u flag. This will cause scripts to be executed on duplicate hosts once per listing. -P Do NOT fall back to passwords on any host. This will skip hosts where keys fail. If you use this with '-d' you'll still see which hosts failed. -l <login> Use 'login' when no other is specified with hostname. -L <login> Force use of 'login' name on all hosts. These can be handy for adding 'root@' to hostnames kept in a file for -H option. With -h it means you get to type less. -s <shell> Path to shell on remote host. (Default: bash) -t <secs> Timeout setting for each session. (requires openssh 3.8 or newer) -V Print version info and exit. PROXY ARGS
-p [user@]<host> Host to use as proxy. (Must have mussh installed) -po <ssh-args> Args to pass to ssh on proxy with -o option. HOST ARGS
-h [user@]<host> [[user@]<host> ..] Add a host to list of hosts. May be used more than once. -H <file> [file ..] Add contents of file(s) to list of hosts. Files should have one host per line. Use "#" for comments. COMMAND ARGS
If neither is specified, commands will be read from standard input. -c <command> Add a command or quoted list of commands and args to list of commands to be executed on each host. May be used more than once. -C <file> [file ..] Add file contents to list of commands to be executed on each host. May be used more than once. PROXY MODE
When proxying, mussh can use a single remote server to as a bastion host. All hosts will be connected to from the central host rather than from the computer where you are initially running mussh. This can be handy when you only have access to one machine behind a firewall. The proxy host must have OpenSSH 2.3 or greater, or an sshd that works with ForwardAgent under ssh2. Proxy server must also have mussh installed in your PATH. To verify that it is in your path use "ssh user@proxy 'which mussh'". Use "ssh user@proxy 'echo $PATH'" to deter- mine what your path is. SSH-AGENT INTERACTION Assuming that you're not turning off the agent with '-A' mussh will attempt to use ssh-agent(1). Normally mussh will get rid of the agent when it exits. See EXAMPLES for examples. EXAMPLES
There is an EXAMPLES file with detailed examples. The basic command: $ mussh -h foo bar baz A simple command: $ mussh -h foo bar baz -c 'rpm -e emacs' A simple command asynchronously: $ mussh -h foo bar baz -c 'rpm -e emacs' -m Using a specific key: $ mussh -h foo bar baz -c 'rpm -e emacs' -i ~/.ssh/my_other.key Loading a list of hosts from a file: $ mussh -H /tmp/hostlist.txt -c 'rpm -e emacs' Loading a script from a file: $ mussh -h foo bar baz -C /tmp/scriptfile.sh BUGS
Please report any bugs at http://sourceforge.net/projects/mussh/ AUTHOR
Dave Fogarty <doughnut at doughnut dot net> SEE ALSO
ssh(1), ssh-agent(1) Doughnut August 2005 MUSSH(1)
All times are GMT -4. The time now is 03:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy