#!/bin/ksh # lookforhyperlinks.ksh # RJM Programming # February, 2023 # Look for hyperlinks in downloaded Spreadsheets *.xls, PDF *.pdf, Rich Text Format *.rtf, Unified Office Format text *.uot, Web page *.htm *.html *.php *.asp *.aspx, Word *.doc (only) # 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 "*.[xXpPrRuUhHdDaA][lLdDtToOhHsS][sSfFtTmMcCpP]*" -type f -mmin 1`; if [ ! -z "$axls" ]; then if [ "`echo $axls | sed -e 's/ot$//g' | sed -e 's/OT$//g' | sed -e 's/ml$//g' | sed -e 's/ML$//g' | sed -e 's/tm$//g' | sed -e 's/TM$//g' | sed -e 's/hp$//g' | sed -e 's/HP$//g' | sed -e 's/sp$//g' | sed -e 's/SP$//g' | sed -e 's/px$//g' | sed -e 's/PX$//g'`" != "`echo $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 'http' | sed '/[}][}][}][}]/s//>/g' | sed '/[<]/s//>/g' | sed '/["]/s//>/g' | sed '/[%][.]2[.]0/s//"/g' | awk -F'http' '{for(i=2;i<=NF;i++){if($i){split($i,a,">");print "http" a[1] "@";}}}' | sed '/[.][.]/s//.>/g' | sed '/[>]/s//./g' | sed '/\_record\.php\?docronwork\=\@/s//SaY/g' | sed '/[@]/s//";\n/g'` elif [ "`echo $axls | sed -e 's/tf$//g' | sed -e 's/TF$//g'`" != "`echo $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 'http' | sed '/[}][}][}][}]/s//>/g' | sed '/["]/s//>/g' | sed '/[%][.]2[.]0/s//"/g' | awk -F'http' '{for(i=2;i<=NF;i++){if($i){split($i,a,">");print "http" a[1] "@";}}}' | sed '/[.][.]/s//.>/g' | sed '/[>]/s//./g' | sed '/\_record\.php\?docronwork\=\@/s//SaY/g' | sed '/[@]/s//";\n/g'` elif [ "`echo $axls | sed -e 's/oc$//g' | sed -e 's/OC$//g'`" != "`echo $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'` elif [ "`echo $axls | sed -e 's/f$//g' | sed -e 's/F$//g'`" = "`echo $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'` else 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 '.http' | sed '/[.][.][.][.]/s//>/g' | sed '/[%][.]2[.]0/s//"/g' | awk -F'.http' '{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'` fi 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' | sed -e 's/";";"/";/g' | sed -e 's/"";/";/g' | 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' | sed -e 's/";";"/";/g' | sed -e 's/"";/";/g' | 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' | sed -e 's/";";"/";/g' | sed -e 's/"";/";/g' | 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