diff --git a/block-II/01-raw/dates b/block-II/01-raw/dates new file mode 100644 index 0000000000000000000000000000000000000000..81c4acfba8d3d07d40863e59bba9bb4b21d8959f --- /dev/null +++ b/block-II/01-raw/dates @@ -0,0 +1,14 @@ +2020-10-04 13:22:07 data-eco-unit-7-node-73-start-2020-07-08-file.txt +2020-10-12 17:39:20 data-eco-unit-13-node-133-start-2020-07-08-file.txt + +2020-10-15 17:30:50 data-eco-unit-2-node-23-start-2020-07-08-file.txt +2020-10-15 21:54:05 data-eco-unit-12-node-123-start-2020-07-08-file.txt + +2020-10-27 14:30:19 data-eco-unit-10-node-103-start-2020-07-08-file.txt +2020-10-27 20:20:16 data-eco-unit-5-node-53-start-2020-07-08-file.txt +2020-10-27 22:01:38 data-eco-unit-3-node-33-start-2020-07-08-file.txt +2020-10-27 22:39:46 data-eco-unit-9-node-93-start-2020-07-08-file.txt +2020-10-28 04:43:10 data-eco-unit-11-node-113-start-2020-07-08-file.txt +2020-10-28 05:11:59 data-eco-unit-6-node-63-start-2020-07-08-file.txt +2020-10-28 05:15:18 data-eco-unit-4-node-43-start-2020-07-08-file.txt +2020-10-28 05:35:37 data-eco-unit-8-node-83-start-2020-07-08-file.txt diff --git a/getLastDates.sh b/getLastDates.sh new file mode 100755 index 0000000000000000000000000000000000000000..ba22226073b5074b1d2b65c3f6a97aa88c95a642 --- /dev/null +++ b/getLastDates.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +echo "Usage:" +echo "source <this>" +echo "#then you can use any function/alias from here." + +function isNumber(){ + re='^[0-9]+$' + if [[ "$1" =~ $re ]]; then + return 1 + else + return 0 + fi +} + +function getLastDateUnit(){ + for i in "$@"; do + echo "unit $i" + getLastDate `ls *unit-$i-*` + done +} + +function getLastDate() { + # gets last line timestamp and transforms it to date + # for more files, will get latest date of all files + + latest_date=0 + for file in "$@"; do + timestamp=`t1 $file | cut -d';' -f1` + isNumber "$timestamp" + if [ "$?" == 0 ]; then + continue + fi + + # echo "${timestamp}; `date -d @"$timestamp" +%F-%T`; $file" + if [ ${timestamp} -gt ${latest_date} ]; then + latest_date="$timestamp" + latest_file="$file" + fi + done + + last_date=`date -d @"$timestamp" +"%Y-%m-%d %T"` # 2>/dev/null #2>&1 + echo "${last_date} ${file}" + echo "" +} + +alias getLastDateAllUnits="getLastDateUnit {2..13}" +alias getMostRecentBup="scp time:\`ssh time ls -rt /media/data/*gz | tail -1\` ." \ No newline at end of file