From dcd5695020caba5fb9e1eb62a28f2eb1ff372d95 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 8 Mar 2019 15:10:09 +0000 Subject: [PATCH] bin/nb-repos-run-parts --- bin/nb-repos-run-parts | 28 ++++++++++++++++++++++++++++ bin/nb-run-parts | 1 - bin/nb-update | 2 +- etc/cron/nb | 5 +++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100755 bin/nb-repos-run-parts diff --git a/bin/nb-repos-run-parts b/bin/nb-repos-run-parts new file mode 100755 index 00000000..abac9722 --- /dev/null +++ b/bin/nb-repos-run-parts @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +##################################################################### +# +# bin/nb-repos-run-parts +# +##################################################################### +DIR=${1:?Missing DIR} + +nb_repos | while read repo; do + [ -d "$repo/$DIR" ] || continue + echo "$repo/$DIR" + user=`ls -dl "$repo/$DIR" | awk '{print $3}'` + cmd="cd \"$repo\"" + cmd="$cmd && ls -lhd \"$repo/$DIR\" && whoami" + #cmd="$cmd && run-parts --report \"$repo/$DIR\"" + + if [ "$USER" = "$user" ]; then + sh -c "$cmd" + elif [ "$USER" = "root" ]; then + su $user -c "$cmd" + else + echo "Wrong user current user=$USER repo user=$user ($repo)" + false + fi + ret=$? + + #echo "$cmd" +done diff --git a/bin/nb-run-parts b/bin/nb-run-parts index 8d635495..ef10127d 100755 --- a/bin/nb-run-parts +++ b/bin/nb-run-parts @@ -4,7 +4,6 @@ # bin/nb-run-parts # ##################################################################### - USAGE="nb-run-parts PATH" DIR=${1:?$USAGE} LOG_DIR="/var/log/nb" diff --git a/bin/nb-update b/bin/nb-update index 40aa744e..4967d5fa 100755 --- a/bin/nb-update +++ b/bin/nb-update @@ -61,7 +61,7 @@ for repo in $(nb_repos); do # # Get user # - user=`ls -dl "$repo/.git" |awk '{print $3}'` + user=`ls -dl "$repo/.git" | awk '{print $3}'` cmd="" diff --git a/etc/cron/nb b/etc/cron/nb index a8bf6996..647926b5 100644 --- a/etc/cron/nb +++ b/etc/cron/nb @@ -12,6 +12,11 @@ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 0 00 * * * root . /etc/profile && nb-update -cleanup >/var/log/nb.log 2>&1 | true 0 01-08 * * * root . /etc/profile && nb-update >/var/log/nb.log 2>&1 | true +# NB 08.03.19 25 5 * * * root which run-parts &> /dev/null && . /etc/profile && cd / && nb_repos_ls etc/cron.daily | while read i; do run-parts --report "$i"; done +# NB 08.03.19 47 4 * * 7 root which run-parts &> /dev/null && . /etc/profile && cd / && nb_repos_ls etc/cron.weekly | while read i; do run-parts --report "$i"; done +# NB 08.03.19 52 3 1 * * root which run-parts &> /dev/null && . /etc/profile && cd / && nb_repos_ls etc/cron.monthly | while read i; do run-parts --report "$i"; done +# NB 08.03.19 52 1 1 * * root which run-parts &> /dev/null && . /etc/profile && cd / && nb_repos_ls etc/cron.yearly | while read i; do run-parts --report "$i"; done +# NB 08.03.19 25 5 * * * root which run-parts &> /dev/null && . /etc/profile && [ -d "$NB_ROOT" -a -d "$NB_ROOT/etc/cron.daily" ] && cd / && run-parts --report $NB_ROOT/etc/cron.daily 47 4 * * 7 root which run-parts &> /dev/null && . /etc/profile && [ -d "$NB_ROOT" -a -d "$NB_ROOT/etc/cron.weekly" ] && cd / && run-parts --report $NB_ROOT/etc/cron.weekly 52 3 1 * * root which run-parts &> /dev/null && . /etc/profile && [ -d "$NB_ROOT" -a -d "$NB_ROOT/etc/cron.monthly" ] && cd / && run-parts --report $NB_ROOT/etc/cron.monthly -- 2.47.3