Skip to content

Commit

Permalink
better ctimer_fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
petskratt committed Nov 27, 2020
1 parent 29eb4ca commit 307378e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ctimer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* v.1.5.1
* - error message if json_decode fails
* - tweaks to ctimer_remote (use builtin, /usr/bin/env and do not trust path)
* - output time with seconds
* v.1.5
* - Bootstrap 4.5.2
* - host in json
Expand Down Expand Up @@ -319,7 +320,7 @@ function generate_ctimes_html( $file_ctimes_grouped ) {

foreach ( $files as $file ) {

$file_date = date( "Y-m-d H:i", $file['ctime'] );
$file_date = date( "Y-m-d H:i:s", $file['ctime'] );
$fragment .= $file_date . ' - <span class="path">' . ltrim( $file['name'], './' ) . '</span>' . PHP_EOL;

if ( empty( $fragment_date ) || $file_date < $fragment_date ) {
Expand Down
22 changes: 14 additions & 8 deletions ctimer_fetch
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
#!/bin/bash
# Fetch files specified by path from remote site
# set -x
#set -x

if [ ! -f "$1" ] || [ ! -f "$1" ]; then
echo "Please provide host-named file with list of paths (or directory with such fiels) to rsync as command line argument."
exit 1
fi

host=$(basename $1)
dir="./${host}_files_$(date +%Y-%m-%d)"
dir="./${host}_files_$(date +%Y-%m-%d_%H-%M)"

mkdir -p "${dir}/tree/"
rm -f "${dir}/_paths.txt"
mkdir -p "${dir}/_meta/"
rm -f "${dir}/_meta/paths.txt"

rsync -azh --files-from="$1" "${host}":/ "${dir}/tree/"

function safecp() {
idx=2 # set the copy index to 0
dfn=${file##*/} # destination file name (dfn) w/path stripped
while [ -f "${dir}/${dfn}" ]; do # test if $dfn exist in output_dir
dfn=${file##*/}_$((idx++)) # if so, add copy index "_#" (increment until unique)
idx=1 # set the copy index to 1
fn="${file##*/}" # destination file name (dfn) w/path stripped
dfn="$fn"

while [ -f "${dir}/${dfn}" ]; do # test if $dfn exist in output_dir
dfn="${fn%.*}_$((idx++)).${fn##*.}" # if so, add copy index "_#" before extenison (increment until unique)
done

cp "$file" "${dir}/${dfn}"
echo "${dfn} - ${file}" >> "${dir}/_paths.txt"
echo "${dfn} - ${file}" >> "${dir}/_meta/paths.txt"
}

while read -d '' file; do
safecp </dev/null
done < <(find "${dir}/tree/" -type f -print0)

rm -rf "${dir}/tree/"

mv "$1" "${dir}"/_meta/"$host"

0 comments on commit 307378e

Please sign in to comment.