Sponsored Content
Top Forums Shell Programming and Scripting Need solution for my bash script executed localy for ssh remote machine Post 303046051 by Azura1003 on Wednesday 22nd of April 2020 11:24:49 AM
Old 04-22-2020
Thanks a lot for your reply see bellow normally the script doesn't looks like this I don't know why when I posted on this page the spaces disappeared.


I'm sorry I'm not that good in scripting still learning.


Can you explain me why you have added the variable with "\" ( \$) , is it the way to explain to the terminal that those variables needs to be executed on the remote shell ?



Quote:
Be aware of the escaped $ - chars for the variable expansion - without those, expansion would be done by the local shell, not the one on the remote node.
Can you clarify this part plz ?



Many thanks Smilie

Last edited by Azura1003; 04-22-2020 at 12:40 PM..
 

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
RDUP-BACKUPS(7) 						       rdup							   RDUP-BACKUPS(7)

NAME
rdup-backups - introduction into making backups with rdup INTRODUCTION
rdup is a simple program that prints out a list of files and directories that are changed changed on a filesystem. It is more sophisticated than for instance find, because rdup will find files that are removed or directories that are renamed. A long time ago rdup included a bunch of shell and Perl scripts that implemented a backup policy. These could be used in a pipeline to per- form a backup. Currently rdup consists out of three basic utilities: rdup With rdup you create the file list on which later programs in the pipeline can work. The default output format also includes the files' content. rdup can be seen as a tar replacement in this respect, but rdup also allows for all kinds of transformations of the content (encryption, compression, reversal), see the -P switch in rdup(1) for more information. rdup-tr With rdup-tr you can transform the files rdup delivers to you. You can create tar, cpio or pax files. You can encrypt pathnames. rdup-tr is filter that reads from standard input and writes to standard output. See rdup-tr(1) for more information. With rdup and rdup-tr you can create an encrypted archive which is put in a directory structure that is also encrypted. rdup-up With rdup-up you can update an existing directory structure with the updates as described by rdup. rdup-up reads rdup input and will create the files, symbolic links, hard links and directories (and sockets, pipes and devices) in the file system. See rdup-up(1) for more information. So the general backup pipeline for rdup will look something like this: create filelist | transform | update filesystem ( rdup | rdup-tr | rdup-up ) Note 1: The same sequence is used for restoring. In both cases you want to move files from location A to B. The only difference is that the transformation is reversed when you restore. Note 2: The use of rdup-tr is optional. BACKUPS AND RESTORES
For rdup there is no difference between backups and restores. If you think about this for a minute you understand why. Making a backup means copying a list of files somewhere else. Restoring files is copying a list of files back to the place they came from. Same difference. So rdup can be used for both, if you did any transformation with rdup during the backup you just need to reverse those operations during the restore. BACKUPS
It is always best to backup to another medium, be it a different local harddisk or a NFS/CIFS mounted filesystem. You can also use ssh to store file on a remote server, ala rsync (although not as network efficient). If you backup to a local disk you can just as well use rsync or plain old tar, but if you store your files at somebody else's disk you will need encryption. This is where you go beyond rsync and rdup comes in. Rsync cannot do per-file encryption, sure you can encrypt the network traffic with ssh, but at the remote side your files are kept in plain view. If you implement remote backups, the easy route is to allow root access on the backup medium. If the backup runs without root access the created files will not have their original ownership. For NFS this can be achieved by using no_root_squash, for ssh you could enable PermitRootLogin. Note that this may be a security risk. SNAPSHOT BACKUPS
We need a little help here in the form of the rdup-simple script. Keep in mind that the following scripts can also be run remotely with the help of ssh. The following script implements the algorithm of rdup-simple. #!/bin/bash # some tmp files are saved in ~/.rdup. This directory must exist DIR=/home # what to backup BACKUP=/vol/backup TODAY=$(date +%Y%m/%d) LIST=~/.rdup/list-$HOSTNAME STAMP=~/.rdup/timestamp-$HOSTNAME # for remote backup, this has to run on the remote host! BUGBUG RET=$? case $RET in 2|*) echo Error >&2 exit 1 ;; 1) # full dump, remove file-list and time-stamp file rm $LIST $STAMP ;; 0) # inc dump # do nothing here ;; esac # this is the place where you want to modify the command line # right now, nothing is translated we just use 'cat' rdup -N $STAMP -Pcat $LIST $DIR | rdup-up $BACKUP/$HOSTNAME/$TODAY # or do a remote backup #rdup -N $STAMP -Pcat $LIST $DIR | ssh root@remotehost # rdup-up $BACKUP/$HOSTNAME/$TODAY LOCAL BACKUPS
With rdup-simple you can easily create backups. Backing up my home directory to a backup directory: rdup-simple ~ /vol/backup/$HOSTNAME This will create a backup in /vol/backup/$HOSTNAME/200705/15. So each day will have its own directory. Multiple sources are allowed, so: rdup-simple ~ /etc/ /var/lib /vol/backup/$HOSTNAME Will backup your home directory, /etc and /var/lib to the backup location. Also if you need to compress your backup, simple add a '-z' switch: rdup-simple -z ~ /etc/ /var/lib /vol/backup/$HOSTNAME REMOTE BACKUPS
For a remote backup to work, both the sending machine and the receiving machine must have rdup installed. The currently implemented proto- col is ssh. Dumping my homedir to the remote server: rdup-simple ~ ssh://miekg@remote/vol/backup/$HOSTNAME The syntax is almost identical, only the destination starts with the magic string 'ssh://'. Compression and encryption are just as easily enabled as with a local backup, just add '-z' and/or a '-k keyfile' argument: rdup-simple -z -k 'secret-file' ~ ssh://miekg@remote/vol/backup/$HOSTNAME Remember though, that because of these advanced features (compression, encryption, etc, ...) the network transfer can never be as efficient as rsync. ALSO SEE
rdup(1), rdup-tr(1), rdup-up(1) and http://www.miek.nl/projects/rdup/ 1.1.x 15 Dec 2008 RDUP-BACKUPS(7)
All times are GMT -4. The time now is 07:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy