Skip to main content
need to remove the tarball after successful extraction
Source Link
Adam Katz
  • 4.2k
  • 1
  • 28
  • 35

On your local system, create a skeleton of what you want. For example, if you want to copy file foo to remote location /etc/foo, then you need to create an etc directory and then put foo into it. Then tar the skeleton. Now you can do this via cron as suggested by @Anthon in the comments to the question above.

Step by step:

On the remote host, create script like this:

#!/bin/sh
DROP="/home/YOURUSERNAME/drop.tgz"
if [ ! -s /home/YOURUSERNAME/drop.tgz"$DROP" ]; then exit 0; fi
cd /
tar -pzxf /home/YOURUSERNAME/drop.tgz"$DROP" && rm "$DROP"

On the remote host, add that script to a cron job that runs as root.

On your local host, create the skeleton and populate the files you want copied:

mkdir -p etc
mkdir -p var/www
cp -a foo etc/
cp -a bar var/www/
tar -pzcf drop.tgz etc var
scp drop.tgz REMOTEHOST:
rm -rf drop.tgz etc var

The drop.tgz will be extracted when the root's cron next runs. Note, this will overwrite all kinds of things that you might not like.

A safer option, assuming there are only a few files you need to modify, would be to make your user account have write access to them (chown or both chgrp and chmod g+w), then you can scp them directly.

On your local system, create a skeleton of what you want. For example, if you want to copy file foo to remote location /etc/foo, then you need to create an etc directory and then put foo into it. Then tar the skeleton. Now you can do this via cron as suggested by @Anthon in the comments to the question above.

Step by step:

On the remote host, create script like this:

#!/bin/sh
if [ ! -s /home/YOURUSERNAME/drop.tgz ]; then exit 0; fi
cd /
tar -pzxf /home/YOURUSERNAME/drop.tgz

On the remote host, add that script to a cron job that runs as root.

On your local host, create the skeleton and populate the files you want copied:

mkdir -p etc
mkdir -p var/www
cp -a foo etc/
cp -a bar var/www/
tar -pzcf drop.tgz etc var
scp drop.tgz REMOTEHOST:
rm -rf drop.tgz etc var

The drop.tgz will be extracted when the root's cron next runs. Note, this will overwrite all kinds of things that you might not like.

A safer option, assuming there are only a few files you need to modify, would be to make your user account have write access to them (chown or both chgrp and chmod g+w), then you can scp them directly.

On your local system, create a skeleton of what you want. For example, if you want to copy file foo to remote location /etc/foo, then you need to create an etc directory and then put foo into it. Then tar the skeleton. Now you can do this via cron as suggested by @Anthon in the comments to the question above.

Step by step:

On the remote host, create script like this:

#!/bin/sh
DROP="/home/YOURUSERNAME/drop.tgz"
if [ ! -s "$DROP" ]; then exit 0; fi
cd /
tar -pzxf "$DROP" && rm "$DROP"

On the remote host, add that script to a cron job that runs as root.

On your local host, create the skeleton and populate the files you want copied:

mkdir -p etc
mkdir -p var/www
cp -a foo etc/
cp -a bar var/www/
tar -pzcf drop.tgz etc var
scp drop.tgz REMOTEHOST:
rm -rf drop.tgz etc var

The drop.tgz will be extracted when the root's cron next runs. Note, this will overwrite all kinds of things that you might not like.

A safer option, assuming there are only a few files you need to modify, would be to make your user account have write access to them (chown or both chgrp and chmod g+w), then you can scp them directly.

Source Link
Adam Katz
  • 4.2k
  • 1
  • 28
  • 35

On your local system, create a skeleton of what you want. For example, if you want to copy file foo to remote location /etc/foo, then you need to create an etc directory and then put foo into it. Then tar the skeleton. Now you can do this via cron as suggested by @Anthon in the comments to the question above.

Step by step:

On the remote host, create script like this:

#!/bin/sh
if [ ! -s /home/YOURUSERNAME/drop.tgz ]; then exit 0; fi
cd /
tar -pzxf /home/YOURUSERNAME/drop.tgz

On the remote host, add that script to a cron job that runs as root.

On your local host, create the skeleton and populate the files you want copied:

mkdir -p etc
mkdir -p var/www
cp -a foo etc/
cp -a bar var/www/
tar -pzcf drop.tgz etc var
scp drop.tgz REMOTEHOST:
rm -rf drop.tgz etc var

The drop.tgz will be extracted when the root's cron next runs. Note, this will overwrite all kinds of things that you might not like.

A safer option, assuming there are only a few files you need to modify, would be to make your user account have write access to them (chown or both chgrp and chmod g+w), then you can scp them directly.