Trying to script rsync using pam_exec

Posted by Ricky-Rose on Server Fault See other posts from Server Fault or by Ricky-Rose
Published on 2013-06-28T21:21:21Z Indexed on 2013/06/28 22:22 UTC
Read the original article Hit count: 306

Filed under:
|
|

I'm trying to write a bash script that will execute rsync when called by pam_exec. I've tried a couple different ways, and I'm not sure what I'm doing wrong. When I try to run the script at login by adding

session optional pam_exec.so /usr/bin/local/sync.sh

to my sshd file, it gives me an exit code of 12.

if I log in and then manually run my script, it allows me to connect to the remote server, and it lists my files, but it doesn't actually sync anything.

I have tried the code below using buth $USER and $PAM_USER. $PAM_USER doesn't work at all.

#!/bin/sh 
rsync -azv -e ssh $USER@remote_server:/home/html/$USER/ /home/html/$USER

© Server Fault or respective owner

Related posts about bash

Related posts about rsync