]> git.nbdom.net Git - nb.git/commitdiff
etc/cron.weekly/clean-dirs
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 25 May 2018 22:51:59 +0000 (23:51 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 25 May 2018 22:51:59 +0000 (23:51 +0100)
etc/cron.weekly/clean-dirs [new file with mode: 0755]
etc/cron/nb
etc/profile.d/nb.sh
www/dbq/dbq.php

diff --git a/etc/cron.weekly/clean-dirs b/etc/cron.weekly/clean-dirs
new file mode 100755 (executable)
index 0000000..0b9e7a3
--- /dev/null
@@ -0,0 +1,77 @@
+#!/usr/bin/env bash
+#################################################################################
+#
+# NB 06.07.13
+# Delete unused files
+#
+# To test: touch -t '190001010000' /tmp/todel && ls -lh /tmp/todel
+#
+#################################################################################
+DAYS="+120"
+DIRS="\
+/tmp/ \
+/var/tmp/ \
+~root/tmp/
+/{home,Users}/*/tmp/ \
+/{home,Users}/*/{ownCloud,Dropbox,Google\ Drive}/tmp/ \
+/Users/*/.Trash/ \
+"
+
+LOCATE="
+/Thumbs.db
+/ZbThumbnail.info
+/.xvpics
+/.DS_Store
+/home/*/._ico_*
+/home/share/Music/*desktop.ini
+/kodi_crashlog-*
+"
+
+#################################################################################
+DEBUG=0
+LOG="/var/log/clean-dirs.log"
+while [ $# -gt 0 ]; do
+
+       case "$1" in
+
+               -*help|-h) cat <<EOF
+Usage: clean-dirs [OPTIONS]
+-h     --help  This help
+-d     --debug Dont delete anything
+-l     --log           [FILE] Write to log file
+-c     --conf  [FILE] Load shell config file
+EOF
+                       exit
+               ;;
+               --debug|-d) DEBUG=$(($DEBUG+1)) ;;
+               --log|-l) shift; LOG=$1 ;;
+               --conf|-c) shift; . "$1" || exit ;;
+
+               *) exec $0 -h ;;
+
+       esac
+       shift
+
+done
+
+if [ -z "$DIRS" -a -z "$LOCATE" ]; then
+       echo "Envs DIRS and LOCATE undefined. See $0 --help" 1>&2
+       exit 1
+fi
+
+[ -n "$LOG" -a "$DEBUG" = "0" ] && exec > "$LOG"
+
+       (
+               [ -n "$LOCATE" ] && which locate 1>/dev/null 2>&1 && locate $LOCATE &
+               if [ -n "$DIRS" -a -n "$DAYS" ]; then
+                       eval find $DIRS -mindepth 1 -type f -mtime $DAYS
+                       eval find $DIRS -mindepth 1 -type d -mtime $DAYS -empty -prune
+               fi
+       ) 2>/dev/null | while IFS= read -r path; do
+
+       echo "Found: $path"
+       [ "$DEBUG" -gt 0 ] && continue
+
+       rm -vr "$path" 2>/dev/null | sed 's/^/  /'
+
+done
index d203d871aff712bd37c7c32306921f66bcd90ed2..013fd8baaa027993b3a612b8a9c62fe8af9690f7 100644 (file)
@@ -3,7 +3,9 @@
 #
 #LANG=C
 SHELL=/bin/bash
-PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/nb/bin
+PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
+# NB 25.05.18 :/opt/nb/bin
+#NB_INIT='[ -z "$NB_ROOT" ] || . /etc/profile'
 
 #####################################################################
 # m h dom mon dow user command
index dbc2ea2844bbdd18ee4863ebce336c9d1c035f17..519c7e928ca5791a2e977e11af90f41204a2eb84 100644 (file)
@@ -101,6 +101,7 @@ nb_api_post() {
                curl="$curl -d \"$1\""
                shift
        done
+       #echo "$curl"; return
        (
                eval "$(eval "$curl")" #&& echo "$table: $rowCount: $args"
        )
@@ -108,6 +109,7 @@ nb_api_post() {
 
 nb_api_post_host_info() {
        local host=$(hostname)
+       [ -z "$*" ] && echo "Usage: nb_api_post_host_info key=? val=?" && return 1
        [ -z "$host" ] && host=$(hostname -f)
        nb_api_post host_info "host=$host" "$@"
 }
@@ -115,6 +117,6 @@ nb_api_post_host_info() {
 nb_post_sys_infos() {
        # To be compatible with other sed that does not support \t
        sys_infos | tr '\t' '!' | sed -e 's/"/\\"/g' -e 's/^/key="sys./' -e 's/!/" val="/' -e 's/$/"/' | while read -r i; do
-               eval nb_api_post_host_info $i
+               echo eval nb_api_post_host_info $i
        done
 }
index 8b5373fbd8dee537e6992458a096fe1f208505e4..f0814e96d8525c714c36ed4c2b15477f1d362498 100644 (file)
@@ -506,14 +506,19 @@ class DbQ extends nb {
                $row_parse_post($r,$this->table);
        }
 
-       public function table_rows($fct=null) {
+       private function table_rows($fct=null) {
                $this->db->limit = $this->limit();
+               $ropt = [
+                       'html_menu' => empty($this->_nopage),
+               ];
 
+               #if (!empty($this->_nopage)) $this->db->
                $this->row_parse_pre();
                $this->row_parse_post();
 
                $opt = ($this->page->is('html')
                        and $this->table_rw()
+                       and empty($this->_nopage)
                ) ? [
                        'row_parse_pre' => function(&$r){
                                $this->row_parse_pre($r);
@@ -550,7 +555,7 @@ class DbQ extends nb {
                ] : [];
 
                $this->db()->__construct($opt);
-               $this->table->rows();
+               $this->table->rows($ropt);
        }
 
        private function ar_unshift( array & $array, $key, $val) {