0

I'm using Incrond to check a folder for file changes which triggers a Rsync job to our storage server. This configuration is deployed through Puppet, and therefore would like to use the $HOSTNAME variable in the destination path so it writes to it's own directory.

/path/to/backup/ IN_CLOSE_WRITE,IN_CREATE,IN_MODIFY,IN_MOVED_TO,IN_CLOSE_NOWRITE /usr/bin/rsync -t --password-file=/etc/rsyncd.secrets /path/to/backup/$# rsync://rsync@STORAGESERVER/storage/$HOSTNAME/backup/$#

However, this hostname variable is not available in Incrond; and just passes "hostname" into the rsync path.

How can I get the $HOSTNAME variable to work in Incrond?

  • 1
    Are you trying to use the system's hostname in your command? You seem stuck on using the content of the HOSTNAME environment variable. Would you consider using the system hostname instead? – Michael Hampton Dec 10 '18 at 14:06
  • Yes I'm indeed trying to pass the system's hostname so it will backup to the corresponding folder. – user10075632 Dec 10 '18 at 14:11

1 Answers1

0

I would suggest this workaround :

Instead of triggering the actual rsync command, I would make incrond trigger a bash script execution containing the rsync command, and you will have the HOSTNAME command available in the script environment during its execution.

Obviously, you first have to deploy this script before, but as you're using puppet, it should not be the difficult part.

Chaoxiang N
  • 1,218
  • 4
  • 10