LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   How to change a line in a file and send to a remote machine with rsync (https://www.linuxquestions.org/questions/linux-server-73/how-to-change-a-line-in-a-file-and-send-to-a-remote-machine-with-rsync-845498/)

danndp 11-20-2010 07:53 AM

How to change a line in a file and send to a remote machine with rsync
 
Hello my friends,

I'm configuring an rsync between 2 machines, A_Server --> B_Server, using the following script:

Quote:

#!/bin/bash
#
# Script de backup a través de Rsync desde RMP-1 hasta RMP-2.
#
# Si se produce algún error en cualquier momento abortar.
#set -e

DATOS="/tmp/prueba.txt"
EXCLUDES=
OPTS="-vv --relative --delete --force --ignore-errors --delete-excluded --exclude-from=$EXCLUDES -a"
RSERVER="rsync://A_Server@192.168.1.4/A_Server/"
export RSYNC_PASSWORD=1234

#Este script sincroniza los datos de Asterisk de RMP-1 a RMP-2 a través
#del servicio rsyncd. Los datos se guardan en RMP-2 en la carpeta
#/home/RMP-1/.
"
echo
echo "Copiando datos ..."
echo "rsync $OPTS $DATOS $RSERVER"
rsync $OPTS $DATOS $RSERVER
echo "OK"

echo
echo "Hora Fin: $(date)"
echo "=)"
The Rsyn is working OK. What i need is to change one of the lines of the /tmp/prueba.txt before sending it to the remote machine (obviously not changing the file in the local machine), i mean, send prueba.txt to the remote machine deleting one line and adding another one...how can i do this????

sed is a good choice, but no clue how to put all together in the same script...i would appreciate your help

BEST REGARDS!!!

quanta 11-20-2010 08:16 AM

You can change it in the remote server after rsyncing:
Code:

ssh user@B sed -i '23c\'"new line" /path/to/prueba.txt
-i to inline edit
23 is line number
c stand for change

danndp 11-20-2010 11:28 AM

Quote:

Originally Posted by quanta (Post 4165314)
You can change it in the remote server after rsyncing:
Code:

ssh user@B sed -i '23c\'"new line" /path/to/prueba.txt
-i to inline edit
23 is line number
c stand for change

Thanks my friend....but i'm trying and is not working :(

Quote:

<RMP-Sangoma> root@srv-RMP3:~# ssh ddias@192.168.10.3 sed -i '2c\'"new line" /tmp/prueba.txt
ddias@192.168.10.3's password:
sed: no se puede leer line: No existe el fichero o el directorio
sed: cannot rename /tmp//sedCBV2jO: Operación no permitida
Am i missing something?

danndp 11-20-2010 11:33 AM

Seems to be a problem of permissology, right? :)

danndp 11-20-2010 11:34 AM

Quote:

Originally Posted by danndp (Post 4165483)
Seems to be a problem of permissology, right? :)

Sorry...not permissology...."Permitting".... :)


All times are GMT -5. The time now is 06:19 AM.