LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   sftp: run command after user exits? (https://www.linuxquestions.org/questions/linux-server-73/sftp-run-command-after-user-exits-768481/)

schwing 11-11-2009 01:34 PM

sftp: run command after user exits?
 
I have a server where my users sftp and drop files. I also set up a backup server where the sftp server rsyncs to. My problem is that the are around 100GB of files that I would like to keep in sync between the servers. The first sync took a few days to complete, but now each time it runs it takes almost 30 minutes creating the file list.

My thought to speed this up would be to have sftp run a specific rsync command on the user's directory to transfer only the files they sftp'd to the backup server. Then once a night I could run the "full" rsync to make sure nothing is missed.

Could someone tell me how I could run a script after the user has logged out? My users are mainly Windows users using a GUI client so asking them to do anything on their end is not really an option.

-ken

choogendyk 11-12-2009 08:00 PM

hmm. still no answers. What about writing a script in shell or perl that runs as a daemon and watches the log files? When an entry shows that a user has transferred files, run rsync on their home directory. There are some tricks to this. You have to make sure the logging level is such as to give you what you need, and you need to know how to read the added tail on a log file (keep your place when another program has written to the file).

Another shot in the dark might be to figure out how openssh connects with its sftp module (not the same as /usr/bin/sftp, possibly /usr/libexec/sftp-server?). If that is a binary that is called when someone does an sftp, you could move it to, say, sftp-server-real, and put a script in its place that calls it and then does the rsync. I've done that with some other sorts of things, like the lp binary, but I don't know if the ssh/sftp connection is amenable to that approach. One difficulty here is figuring out how to get the user who was running it. You might try doing a sizable scp and then looking at processes on the server side to see what it is doing. There is likely to be a root process and a process under the name of the user doing the scp.

Anyway, if nobody comes in with any more concrete ideas, those are a couple of things you could poke at and think about.

chrism01 11-12-2009 10:11 PM

How about inotify or dnotify?


All times are GMT -5. The time now is 05:42 PM.