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
ZSSH(1) 							       ZSSH								   ZSSH(1)

NAME
zssh - interactive file transfer wrapper for ssh SYNOPSIS
zssh [zssh options] [--] [ssh options] ztelnet [zssh options] [--] [telnet options] DESCRIPTION
zssh (Zmodem SSH) is a program for interactively transferring files to a remote machine while using the secure shell ( ssh ). It is intended to be a convenient alternative to scp , allowing to transfer files without having to open another session and re-authenticate one- self. zssh is an interactive wrapper for ssh used to switch the ssh connection between the remote shell and file transfers. This is achieved by using another tty/pty pair between the user and the local ssh process to plug either the user's tty (remote shell mode) or another process (file transfer mode) on the ssh connection. ztelnet behaves similarly to zssh, except telnet is used instead of ssh. It is equivalent to 'zssh -s "telnet -8 -E"' Files are transferred through the zmodem protocol, using the rz and sz commands. zssh behaves as an usual ssh session until the escape sequence is depressed ( default is ^@ which can be produced by pressing C-space, or C-2, or C-` ), which enables file transfer mode. A new prompt is then displayed, and commands can be executed locally to initiate file transfers (among other things). It roughly behaves as a local shell featuring line edition, history and completion (thanks to libreadline), globbing, and escape characters ( " ' and ). The following builtins are handled by zssh itself: ? , cd , disconnect , escape , exit , help , hook , quit , repeat , rz , suspend , sz , version cd <dir> change current directory disconnect disconnect and exit escape [^X] Change escape key to ^X. Without argument, print current escape key exit exit file transfer mode. ^D may also be used for this purpose. help print help and tips ? hook prg [args] Hook program 'prg' on the the pty. Its standard input and output will go through the ssh channel. typing 'sz'/'rz' is in fact equivalent to 'hook sz'/'hook rz' A weird imagination is most useful to gain full advantage of this feature. quit same as exit. repeat repeats cmd forever (^C to interrupt). Useful for example if you use a remote script invoking "sz" and you don't want to be typing "rz" each time... Remember however that several files can be transferred by a single sz/rz pair so this is not usually necessary to use repeat. rz Receive files from the remote machine. runs rz and plugs the process on the ssh connection. running sz on the REMOTE machine is required : 1) run `sz <remote_file> ...' from the remote machine shell 2) press the escape sequence (C-space) to enter file transfer mode 3) run the `rz' builtin suspend suspend zssh (back to the local machine shell) sz <file> ... Send files to the remote machine. runs sz and plugs the process on the ssh connection. There is no need to manually run rz on the remote side. version print version information builtins rz , sz , hook and exit return to shell mode after completion. OPTIONS
-f --force Do not ask user any question -h --help show basic help -s cmd --shell cmd run cmd as remote shell instead of the default "ssh -e none" (zssh) or "telnet -8 -E" (ztelnet) ex: zssh -s "rsh -x" -V --version show version -z ^X --zssh-escape ^X set escape sequence to ^X -- may be used to separate zssh options from ssh ones Other arguments are passed verbatim to ssh/telnet/whatever. ENVIRONMENT
ZSSHESCAPE Setting the ZSSHESCAPE environment variable allows to override the default escape sequence. ZSSHESCAPE should contain only two characters of the form `^X', meaning that ^X is to be the new escape sequence. REQUIREMENTS
the following binaries need to be properly installed for zssh to work : ssh/telnet/... the remote shell to be executed (local machine) sz rz zmodem send and receive programs. Should be both on local and remote machine, and (hopefully) of compatible versions. TIPS
If file transfer is initiated but never completes ( ie a line like : Bytes Sent: 38144/4610624 BPS:3424 ETA 22:15 or Bytes Sent: 0/ 513 BPS:0 ETA 00:00 Retry 0: Got ZCAN can be seen, but transfer never completes ) Chances are the pty/tty on one of the systems are not 8-bit clean. (Linux is 8-bit clean, NetBSD is not). Using the -e (escape) option of rz should solve this problem. Transfers can be interrupted with ^C (somewhat experimental =) If you get stuck in rz/sz (for example you've just ran rz, but you then decided not to transmit anything), hit a dozen ^X (Ctrl-X, not the zssh escape!) to stop it Use `sz -y <files>' to overwrite files on the other side BUGS
/ LIMITATIONS You may sometimes have to hit return 2 or 3 times after file transfer completion in order get back to the shell. Some digits are usually displayed; don't worry it won't harm (you or your term) ... the tty may (sometimes) be somewhat upset after an interrupted transfer ( using ^C ). typing `reset' in this case should help. no pipe, redirection (and other stuff) support in shell ... but after all there are already wonderful shells around =) CREDITS
ttssh's author - Robert O'Callahan - for the original idea The sourceforge team. AUTHOR
Matthieu Lucotte <gounter@users.sourceforge.net> zssh homepage: http://zssh.sourceforge.net SEE ALSO
ssh(1), telnet(1), scp(1), sz(1), rz(1), readline(3), ZSSH
June 26, 2000 ZSSH(1)
All times are GMT -4. The time now is 09:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy