#!/bin/ksh # lookforhyperlinks.ksh # RJM Programming # February, 2023 # Look for hyperlinks in downloaded Spreadsheets # crontab usage supply an additional argument (onto a first emailee argument, perhaps) ... or to do as a one off execution usage # Thanks to ... # https://www.unix.com/unix-for-dummies-questions-and-answers/123644-converting-binary-file-readable-format-ksh.html # https://stackoverflow.com/questions/26968159/list-of-files-modified-1-hour-before # https://www.unix.com/shell-programming-and-scripting/247464-awk-combined-if.html # https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command modeopencurl="open"; one="1"; two="2"; qt="\""; emailto=""; if [ ! -z "$1" ]; then if [ "`echo $1`" == "curl" ]; then modeopencurl="curl"; shift; fi fi if [ ! -z "$1" ]; then if [ "`echo $1 | tr '@' 'x'`" != "`echo $1`" ]; then emailto="$1"; shift; fi fi while test "$one" -ne "$two" ; do axls=`find $HOME/Downloads -name "*.xls*" -type f -mmin 1`; if [ ! -z "$axls" ]; then res=`hexdump -C "${axls}" | sed '/[.][|][.]/s//.!@!./g' | cut -f2 -d '|' | sed '/[.][!][@][!][.]/s//.|./g' | tr -d '\n' | sed -e 's/=.s.a.y./=.S.a.Y./g' | tr -d "'" | cut -d':' -f 2- | grep '.h.t.t.p.' | sed '/[.][.][.][.]/s//~/g' | sed '/[%][.]2[.]0/s//"/g' | awk -F'.h.t.t.p.' '{for(i=2;i<=NF;i++){if($i){split($i,a,"~");print "http" a[1] "@";}}}' | sed '/[.][.]/s//.~/g' | sed '/[.]/s///g' | sed '/[~]/s//./g' | sed '/\_record\.php\?docronwork\=\@/s//SaY/g' | sed '/[@]/s//";\n/g'` if [ ! -z "$res" ]; then if [ -z "$1" -a -z "$emailto" ]; then if [ "$modeopencurl" = "curl" ]; then echo $res | sed -e 's/ http/"; \ncurl "http/g' | awk 'NR==1,/http/{sub(/http/, "curl \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh else echo $res | sed -e 's/ http/"; \nopen "http/g' | awk 'NR==1,/http/{sub(/http/, "open \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh fi ksh /tmp/ideatwo.ksh & else if [ ! -z "$emailto" ]; then # no -e 's/=/%3d/g' below echo $res | sed -e 's/";";\n/\n/g' | sed -e 's/";\n/\n/g' | sed -e 's/ /tmp/ideatwo.ksh bxls=`echo "$axls" | sed -e 's/ /tmp/ideatwo.ksh else echo $res | sed -e 's/ http/"; \nopen "http/g' | awk 'NR==1,/http/{sub(/http/, "open \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh fi else if [ "$modeopencurl" = "curl" ]; then echo $res | sed -e 's/ http/"; \ncurl "http/g' | awk 'NR==1,/http/{sub(/http/, "curl \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh else echo $res | sed -e 's/ http/"; \nopen "http/g' | awk 'NR==1,/http/{sub(/http/, "open \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh fi ksh /tmp/ideatwo.ksh & fi fi fi fi if [ -z "$1" ]; then sleep 60 else two=$one fi done exit