Bala12
Bala12

Reputation: 129

rsync to move file from local to remote machine and execute command on remote machine

I have one file in my local Linux machine and I want to move that one to remote machine and then execute one command on remote machine to restart the service. The issue is after moving the file the remote connection get closed. I have used the following command:

rsync --remove-source-files -av -e ssh -t /home/testdata.txt root@vdstvmaster:/home/; service restart

If I execute the above command file is successfully moved to remote machine. But the second command (service restart) is not executed on remote machine.

Upvotes: 1

Views: 1163

Answers (1)

András Aszódi
András Aszódi

Reputation: 9660

rsync can use a remote shell to perform the copy operation. But it is not meant as a "general-purpose" remote shell application. Just invoke the second command over SSH locally after the rsync command like this:

rsync --remove-source-files -av -e ssh -t /home/testdata.txt root@vdstvmaster:/home/


ssh root@vdstvmaster service restart

BTW some people may consider remotely logging into another machine as root bad security.

Upvotes: 1

Related Questions