0

I want to write a daemon-script for my Raspberry Pi 2 that runs on startup and permanently watches for changes in a specific directory. If there is a change, it should copy the changed files to a directory on a Windows computer (maybe via SSH).

I found out that the Gamin library for Python that monitors files can help (https://people.gnome.org/~veillard/gamin/python.html), but I am not sure if a bash script would be better suited for the job, especially the file transfer. Unfortunately I just started digging into Unix and Python and could use some any helpful advice on what would be the best way to solve this problem.

Peter H.
  • 109
  • 2
  • 10
  • 1
    Python can run any system command via `subprocess`, albeit it's more verbose than bash. And you can find a ton of resources on the Web about writing a daemon in Python. So if you're more comfortable with Python, just use it. – 4ae1e1 May 22 '15 at 00:54
  • The concept you are interested in is "inotify." There are Perl packages and other libraries. – RTLinuxSW May 22 '15 at 01:30

1 Answers1

1

You could checkout this watch script and set the sleep time to what ever interval you want to check

https://gist.github.com/mikesmullin/6401258

Add it to systemd or init.d and use it to copy via scp.

https://unix.stackexchange.com/questions/47695/how-to-write-startup-script-for-systemd

https://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian

Instead of scp you could make the directory a git repository and let the script commit and push the changes every time.

git add -u
git commit -m "<your standard commit message>"
git push

Follow this link for more information about how to set up a git server on windows

https://github.com/msysgit/msysgit/wiki/Setting-up-a-Git-server-on-Windows-using-Git-for-Windows-and-CopSSH

Community
  • 1
  • 1
ikstream
  • 448
  • 12
  • 20
  • 1
    The watch.sh script did it for me! I ended up adding the script to "/etc/xdg/lxsession/LXDE-pi/autostart" for autostart. SSH/scp did for some reasons not work on my Windows 7 because of "Permission denied (keyboard-interactive)", but Samba worked just fine so it was not a big deal. – Peter H. May 24 '15 at 13:08