Skip to content

Instantly share code, notes, and snippets.

@sadbox
Last active August 29, 2015 14:02
Show Gist options
  • Save sadbox/f89b1e98c8c7f75ba865 to your computer and use it in GitHub Desktop.
Save sadbox/f89b1e98c8c7f75ba865 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
for user in $(ls /home/znc/users/); do
if [ ! -d "/home/${user}" ] ; then
continue
fi
echo "Syncing logs for ${user}"
from="/home/znc/moddata/log/${user}_"
to="/home/${user}/znclogs"
group="$(id -gn "${user}")"
if ! stat -t "${from}"* &>/dev/null; then
echo "User ${user} has no logs, skipping!"
continue
fi
if [ ! -d "${to}" ] ; then
mkdir "${to}"
chown "${user}":"${group}" "${to}"
fi
if rsync -a --chown "${user}":"${group}" "${from}"* "${to}"; then
echo "Logs successfully synced"
else
echo "Error syncing logs for ${user}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment