#!/bin/ksh
# date_ps_ef.ksh
# Report on world.php or filename as argument 1
mimetype="Content-Type: text/html\\n"
emailfrom="rmetcalfe@rjmprogramming.com.au"
emailto="rmetcalfe15@gmail.com"
emailcc="rmetcalfe@rjmprogramming.com.au"
emailbcc=""
subjmiddle="Date ps-ef world.php Report"
lastdate="`date`"
subjis="First ${subjmiddle} at ${lastdate}"
lastcur=""
filen=""
flist=""
prefix="$0"
ppid=""
plain="plain"
hprefix=""
hsuffix=""
topiccmd="`echo \"ps -ef | grep '/world.php' | grep -v 'grep '\"`"
topiccmd1="`echo \"ps -ef \"`"
topiccmd2="`echo \"grep '/world.php'\"`"
topiccmd3="`echo \"grep -v 'grep '\"`"
# Local time the Korn Shell will be hosted at
preTZ="Australia/Perth"
#preTZ="Australia/Sydney"
thispid="`echo $$`"
postiftwoquit="`ps -ef | grep \" ${thispid} \" | grep -c ':00:00:00:00'`"
iftwoquit="1"
cmdsuffix=""
attachrest="\\n
First ${subjmiddle} at ${lastdate}
UID | PID | PPID | C | STIME | TTY | TIME | CMD |
`cat date_ps_ef_first.txt | sed '/^/s///g' | sed 's/ \{1,\}/<\/td> | /g' | awk '{ t=0; while (getline \$0) { if (t == 0) { print \" |
<\/tr>/g'`
"
if [ ! -z "$1" ]; then
if [ "`echo \"${1}\" | sed '/^topiccmd/s///g'`" != "`echo \"${1}\"`" ]; then
if [ "`echo \"${1}\" | sed '/^topiccmd1=/s///g'`" != "`echo \"${1}\"`" ]; then
topiccmd1="`echo \"${1:10}\" | tr '~' ' '`"
subjmiddle="Date ${topiccmd1} Report"
subjis="First ${subjmiddle} at ${lastdate}"
attachrest="\\nFirst ${subjmiddle} at ${lastdate}
UID | PID | PPID | C | STIME | TTY | TIME | CMD |
`cat date_ps_ef_first.txt | sed '/^/s///g' | sed 's/ \{1,\}/<\/td> | /g' | awk '{ t=0; while (getline \$0) { if (t == 0) { print \" |
<\/tr>/g'`
"
cmdsuffix="${cmdsuffix} topiccmd1=${1:10}"
elif [ "`echo \"${1}\" | sed '/^topiccmd2=/s///g'`" != "`echo \"${1}\"`" ]; then
topiccmd2="`echo \"${1:10}\" | tr '~' ' '`"
subjmiddle="`echo \"${subjmiddle}\" | sed \"/ Report/s// ${topiccmd2} Report/g\"`"
subjis="First ${subjmiddle} at ${lastdate}"
attachrest="\\nFirst ${subjmiddle} at ${lastdate}
UID | PID | PPID | C | STIME | TTY | TIME | CMD |
`cat date_ps_ef_first.txt | sed '/^/s///g' | sed 's/ \{1,\}/<\/td> | /g' | awk '{ t=0; while (getline \$0) { if (t == 0) { print \" |
<\/tr>/g'`
"
cmdsuffix="${cmdsuffix} topiccmd2=${1:10}"
elif [ "`echo \"${1}\" | sed '/^topiccmd3=/s///g'`" != "`echo \"${1}\"`" ]; then
topiccmd3="`echo \"${1:10}\" | tr '~' ' '`"
subjmiddle="`echo \"${subjmiddle}\" | sed \"/ Report/s// ${topiccmd3} Report/g\"`"
subjis="First ${subjmiddle} at ${lastdate}"
attachrest="\\nFirst ${subjmiddle} at ${lastdate}
UID | PID | PPID | C | STIME | TTY | TIME | CMD |
`cat date_ps_ef_first.txt | sed '/^/s///g' | sed 's/ \{1,\}/<\/td> | /g' | awk '{ t=0; while (getline \$0) { if (t == 0) { print \" |
<\/tr>/g'`
"
cmdsuffix="${cmdsuffix} topiccmd3=${1:10}"
fi
elif [ "`echo \"${1}\" | sed '/\?/s///g'`" != "`echo \"${1}\"`" ]; then
topiccmd="ps -ef | grep '/world.php' | grep -v 'grep '"
topiccmd1="ps -ef"
topiccmd2="grep '/world.php'"
topiccmd3="grep -v 'grep '"
echo "Enter your Korn Shell understood command: [ ${topiccmd1} | ${topiccmd2} | ${topiccmd3} ]"
read ptopic
if [ ! -z "`echo \"${ptopic}\" | tr -d \"\\n\"`" ]; then
topiccmd2=" grep ''"
topiccmd3=" grep ''"
ptopic="`echo \"${ptopic}\" | sed \"/|/s//\\|/g\"`"
#echo $ptopic
topiccmd1="`echo \"${ptopic}\" | cut -f 1 -d \"|\"`"
subjmiddle="Date ${topiccmd1} Report"
subjis="First ${subjmiddle} at ${lastdate}"
attachrest="\\nFirst ${subjmiddle} at ${lastdate}
UID | PID | PPID | C | STIME | TTY | TIME | CMD |
`cat date_ps_ef_first.txt | sed '/^/s///g' | sed 's/ \{1,\}/<\/td> | /g' | awk '{ t=0; while (getline \$0) { if (t == 0) { print \" |
<\/tr>/g'`
"
cmdsuffix="${cmdsuffix} topiccmd1=`echo ${topiccmd1} | tr ' ' '~'`"
ptopic="${ptopic} | grep ''"
#echo $ptopic
topiccmd2="`echo ${ptopic} | cut -f 2 -d \"|\"`"
subjmiddle="`echo \"${subjmiddle}\" | sed \"/ Report/s// ${topiccmd2} Report/g\"`"
subjis="First ${subjmiddle} at ${lastdate}"
attachrest="\\nFirst ${subjmiddle} at ${lastdate}
UID | PID | PPID | C | STIME | TTY | TIME | CMD |
`cat date_ps_ef_first.txt | sed '/^/s///g' | sed 's/ \{1,\}/<\/td> | /g' | awk '{ t=0; while (getline \$0) { if (t == 0) { print \" |
<\/tr>/g'`
"
cmdsuffix="${cmdsuffix} topiccmd2=`echo ${topiccmd2} | tr ' ' '~'`"
ptopic="${ptopic} | grep ''"
#echo $ptopic
topiccmd3="`echo ${ptopic} | cut -f 3 -d \"|\"`"
subjmiddle="`echo \"${subjmiddle}\" | sed \"/ Report/s// ${topiccmd3} Report/g\"`"
subjis="First ${subjmiddle} at ${lastdate}"
attachrest="\\nFirst ${subjmiddle} at ${lastdate}
UID | PID | PPID | C | STIME | TTY | TIME | CMD |
`cat date_ps_ef_first.txt | sed '/^/s///g' | sed 's/ \{1,\}/<\/td> | /g' | awk '{ t=0; while (getline \$0) { if (t == 0) { print \" |
<\/tr>/g'`
"
cmdsuffix="${cmdsuffix} topiccmd3=`echo ${topiccmd3} | tr ' ' '~'`"
fi
fi
while [ ! -z "$1" ]; do
if [ "`echo \"${1}\" | tr -d '?'`" == "" ]; then
cmdsuffix="${cmdsuffix}"
elif [ "`echo \"${1}\" | tr -d '@'`" != "`echo \"${1}\"" ]; then
if [ "`echo \"${emailto}\" | tr -d ' '`" == "`echo \"${emailto}\"" ]; then
emailto="`echo \"${1}\" | tr -d '?'` "
elif [ "`echo \"${emailcc}\" | tr -d ' '`" == "`echo \"${emailcc}\"" ]; then
emailcc="`echo \"${1}\" | tr -d '?'` "
else
emailbcc="BCC: `echo \"${1}\" | tr -d '?'`\\n"
fi
prefix="${prefix} `echo \"${1}\" | tr -d '?'`"
#echo 45
elif [ -f "`echo \"${1}\" | tr -d '?'`" ]; then
if [ ! -z "${mimetype}" ]; then
filen="`echo \"${1}\" | tr -d '?'`"
mimetype=""
shortf=""
basechars="`base64 ${filen} | tr -d \"\\n\"`"
i=0
flast="`echo \"${1}\" | tr -d '?' | tr '/' ' ' | sed '/\\\\/s// /g'`"
for filebits in ${flast}; do
shortf=${filebits}
((i=i+1))
done
subjmiddle="$shortf"
if [ "`echo \"${subjis}\" | sed '/^First /s///g'`" != "`echo \"${subjis}\"`" ]; then
subjis="First ${subjmiddle} at ${lastdate}"
fi
attachrest="Mime-Version: 1.0\\nContent-Type: multipart/mixed; boundary=\"19032019ABCDE\"\\n\\n--19032019ABCDE\\nContent-Type: text/${plain}; charset=\"iso-8859-1\"\\nContent-Transfer-Encoding: 8bit\\n\\n${hprefix}${subjis}${hsuffix}\\n\\n--19032019ABCDE\\nContent-Type: application/octet-stream; name=\"${shortf}\";\\nContent-Transfer-Encoding: base64\\nContent-Disposition: attachment;filename=\"${shortf}\"\\n\\n${basechars}\\n--19032019ABCDE--"
elif [ -z "${flist}" ]; then
ppid="$$"
prefix="${prefix} ${ppid}"
flist="`echo \"${1}\" | tr -d '?'`"
else
flist="${flist} `echo \"${1}\" | tr -d '?'`"
fi
elif [ "`echo \"${1}\" | tr -d '?' | tr '[A-Z]' '[a-z]' | sed '/^http/s///g'`" != "`echo \"${1}\" | tr -d '?' | tr '[A-Z]' '[a-z]'" ]; then
if [ ! -z "${mimetype}" ]; then
lastcur=" "
filen="`echo \"${1}\" | tr -d '?' | sed '/^https:/s//http:/g' | sed '/^HTTPS:/s//http:/g' | sed '/^Https:/s//http:/g'"
cfilen="`curl ${filen}`"
#cfilen="`php ./inout.php ${filen}`"
filen="${1}"
mimetype=""
shortf=""/
basechars="`echo -n \"${cfilen}\" | base64 | tr -d \"\\n\"`"
#basechars="${cfilen}"
i=0
flast="`echo \"${1}\" | tr -d '?' | tr '/' ' ' | sed '/\\\\/s// /g'`"
for filebits in ${flast}; do
shortf=${filebits}
((i=i+1))
done
subjmiddle="$shortf"
if [ "`echo \"${subjis}\" | sed '/^First /s///g'`" != "`echo \"${subjis}\"`" ]; then
subjis="First `echo \"${1}\" | tr -d '?'` at ${lastdate}"
fi
attachrest="Mime-Version: 1.0\\nContent-Type: multipart/mixed; boundary=\"19032019ABCDE\"\\n\\n--19032019ABCDE\\nContent-Type: text/${plain}; charset=\"iso-8859-1\"\\nContent-Transfer-Encoding: 8bit\\n\\n${hprefix}${subjis}${hsuffix}\\n\\n--19032019ABCDE\\nContent-Type: application/octet-stream; name=\"${shortf}\";\\nContent-Transfer-Encoding: base64\\nContent-Disposition: attachment;filename=\"${shortf}\"\\n\\n${basechars}\\n--19032019ABCDE--"
elif [ -z "${flist}" ]; then
ppid="$$"
prefix="${prefix} ${ppid}"
flist="`echo \"${1}\" | tr -d '?'`"
else
flist="${flist} `echo \"${1}\" | tr -d '?'`"
fi
elif [ "`echo \"${1}\" | tr -d '?' | tr -d ' ' | tr -d '^'`" != "`echo \"${1}\"" ]; then
prefix="${prefix} `echo \"${1}\" | tr -d '?' | tr ' ' '^'`"
subjis="`echo \"${1}\" | tr -d '?' | tr '^' ' ' | sed \"/ at date/s// at ${lastdate}/g\" | sed \"/\[date\]/s//${lastdate}/g\"`"
plain="html"
hprefix=""
hsuffix="
"
attachrest="Mime-Version: 1.0\\nContent-Type: multipart/mixed; boundary=\"19032019ABCDE\"\\n\\n--19032019ABCDE\\nContent-Type: text/${plain}; charset=\"iso-8859-1\"\\nContent-Transfer-Encoding: 8bit\\n\\n${hprefix}${subjis}${hsuffix}\\n\\n--19032019ABCDE\\nContent-Type: application/octet-stream; name=\"${shortf}\";\\nContent-Transfer-Encoding: base64\\nContent-Disposition: attachment;filename=\"${shortf}\"\\n\\n${basechars}\\n--19032019ABCDE--"
else
if [ "`echo \"${1}\" | sed '/^0/s///g' | sed '/^1/s///g' | sed '/^2/s///g' | sed '/^3/s///g' | sed '/^4/s///g' | sed '/^5/s///g' | sed '/^6/s///g' | sed '/^7/s///g' | sed '/^8/s///g' | sed '/^9/s///g'`" != "`echo \"${1}\"" ]; then
if [ "`echo \"${1}\" | sed '/0$/s///g' | sed '/1$/s///g' | sed '/2$/s///g' | sed '/3$/s///g' | sed '/4$/s///g' | sed '/5$/s///g' | sed '/6$/s///g' | sed '/7$/s///g' | sed '/8$/s///g' | sed '/9$/s///g'`" != "`echo \"${1}\"" ]; then
if [ "`echo \"${1}\" | sed '/\:/s///g'`" != "`echo \"${1}\"" ]; then
pfrom=""
pto=""
preadddh=""
adddh=""
addh="0"
addm="0"
adds="0"
twoy=""
factor="1"
thsx="3600"
secstowait="0"
nowis="`date '+%H:%M:%S'`"
one="`echo ${1} | tr -d '?'`"
oney="`echo ${1} | tr -d '?'`"
his="`echo ${nowis} | cut -f 1 -d ':'`"
hfrom="`echo ${one}:00 | cut -f 1 -d ':' | cut -f 1 -d '-' | cut -f 1 -d '+' | tr -d '-'`"
mis="`echo ${nowis} | cut -f 2 -d ':'`"
mfrom="`echo ${one}:00 | cut -f 2 -d ':' | tr -d '-' | tr -d '+'`"
sis="`echo ${nowis} | cut -f 3 -d ':'`"
sfrom="`echo ${one}:00 | cut -f 3 -d ':' | tr -d '-' | tr -d '+'`"
if [ "`echo ${1} | tr -d '?' | tr -d '-'`" != "`echo ${1} | tr -d '?'`" ]; then
twoy="`echo ${1} | tr -d '?' | sed '/\:00\:00\:00\:00/s///g'`:00:00:00:00"
if [ "`echo ${1} | tr -d '?' | sed '/\:\-/s///g'`" == "`echo ${1}`" ]; then
preadddh="-"
adddh="`echo \"${one}:00\" | cut -f 2 -d '-' | cut -f 1 -d ':'`"
xadddh="`echo \"${adddh}\" | cut -f 1 -d '.'`"
if [ "`expr ${xadddh} \>= 24`" == "1" ]; then
if [ "`expr ${xadddh} \< 60`" == "1" ]; then
thsx="60"
factor="1"
else
thsx="1"
factor="1"
fi
fi
if [ "${adddh}" != "${xadddh}" ]; then
zadddh="`echo \"${adddh}.\" | cut -f 2 -d '.'`"
zlen="`echo \"${zadddh}\" | tr -d ' ' | wc -c | tr -d ' '`"
if [ "${zlen}" == "0" -o "${thsx}" == "1" ]; then
factor="1"
elif [ "${zlen}" == "1" -o "${thsx}" == "1" ]; then
factor="1"
elif [ "${zlen}" == "2" -o "${thsx}" == "60" ]; then
factor="10"
xadddh="`echo ${xadddh}${zadddh:0:1}`"
elif [ "${zlen}" == "3" ]; then
factor="100"
xadddh="`echo ${xadddh}${zadddh:0:2}`"
else
factor="100"
xadddh="`echo ${xadddh}${zadddh:0:2}`"
fi
fi
if [ ! -z "${adddh}" ]; then
addh="`echo \"0${adddh}\" | cut -f 1 -d '.'`"
if [ "$thsx" == "1" ]; then
addh="`expr $xadddh \\/ 3600`"
elif [ "$thsx" == "60" ]; then
addh="`expr $xadddh \\/ 60`"
fi
adds="`expr ${xadddh} \\* ${thsx} \\/ ${factor}`"
adds="`echo \"${adds}\" | cut -f 1 -d '.'`"
adds="`expr ${adds} - ${addh} \\* 3600`"
addm="`expr ${adds} \\/ 60`"
addm="`echo \"${addm}\" | cut -f 1 -d '.'`"
adds="`expr ${adds} - ${addm} \\* 60`"
pfrom="${1}"
pto="${1}"
fi
fi
elif [ "`echo ${1} | tr -d '?' | tr -d '+'`" != "`echo ${1} | tr -d '?'`" ]; then
twoy="`echo ${1} | tr -d '?' | sed '/\:00\:00\:00\:00/s///g'`:00:00:00:00"
if [ "`echo ${1} | tr -d '?' | sed '/\:\+/s///g'`" == "`echo ${1} | tr -d '?'`" ]; then
preadddh="+"
adddh="`echo \"${one}:00\" | cut -f 2 -d '+' | cut -f 1 -d ':'`"
xadddh="`echo \"${adddh}\" | cut -f 1 -d '.'`"
if [ "`expr ${xadddh} \>= 24`" == "1" ]; then
if [ "`expr ${xadddh} \< 60`" == "1" ]; then
thsx="60"
factor="1"
else
thsx="1"
factor="1"
fi
fi
if [ "${adddh}" != "${xadddh}" ]; then
zadddh="`echo \"${adddh}.\" | cut -f 2 -d '.'`"
zlen="`echo \"${zadddh}\" | tr -d ' ' | wc -c | tr -d ' '`"
if [ "${zlen}" == "0" -o "${thsx}" == "1" ]; then
factor="1"
elif [ "${zlen}" == "1" -o "${thsx}" == "1" ]; then
factor="1"
elif [ "${zlen}" == "2" -o "${thsx}" == "60" ]; then
factor="10"
xadddh="`echo ${xadddh}${zadddh:0:1}`"
elif [ "${zlen}" == "3" ]; then
factor="100"
xadddh="`echo ${xadddh}${zadddh:0:2}`"
else
factor="100"
xadddh="`echo ${xadddh}${zadddh:0:2}`"
fi
fi
if [ ! -z "${adddh}" ]; then
addh="`echo \"0${adddh}\" | cut -f 1 -d '.'`"
if [ "$thsx" == "1" ]; then
addh="`expr $xadddh \\/ 3600`"
elif [ "$thsx" == "60" ]; then
addh="`expr $xadddh \\/ 60`"
fi
adds="`expr ${xadddh} \\* ${thsx} \\/ ${factor}`"
adds="`echo \"${adds}\" | cut -f 1 -d '.'`"
adds="`expr ${adds} - ${addh} \\* 3600`"
addm="`expr ${adds} \\/ 60`"
addm="`echo \"${addm}\" | cut -f 1 -d '.'`"
adds="`expr ${adds} - ${addm} \\* 60`"
pfrom="`echo ${1} | tr -d '?'`"
pto="`echo ${1} | tr -d '?'`"
fi
fi
fi
if [ ! -z "${preTZ}" -o ! -z "${adddh}" ]; then
bnowis="`date '+%H:%M'`"
if [ -z "${preTZ}" ]; then
ccnowis="`date '+%H:%M:%S'`"
cnowis="`date '+%H:%M'`"
else
ccnowis="`TZ=${preTZ} date '+%H:%M:%S'`"
cnowis="`TZ=${preTZ} date '+%H:%M'`"
fi
if [ "`echo ${nowis} | sed '/${cnowis}/s///g'`" == "`echo ${nowis}`" -o ! -z "${adddh}" ]; then
chis="`echo ${cnowis}:00 | cut -f 1 -d ':'`"
cmis="`echo ${cnowis}:00 | cut -f 2 -d ':'`"
csis="`echo ${ccnowis}:00 | cut -f 3 -d ':'`"
if [ ! -z "${adddh}" ]; then
news="`expr ${sfrom} + ${adds}`"
if [ "`expr ${news} \< 60`" == "1" ]; then
newm="`expr ${mfrom} + ${addm}`"
else
news="`expr ${news} - 60`"
newm="`expr ${mfrom} + ${addm} + 1`"
fi
if [ "`expr ${newm} \< 60`" == "1" ]; then
#echo $hfrom
#echo $addh
newh="`expr ${hfrom} + ${addh}`"
#echo $newh
else
newm="`expr ${newm} - 60`"
#echo $hfrom
#echo $addh
newh="`expr ${hfrom} + ${addh} + 1`"
#echo $newh
fi
if [ "`expr ${newh} \>= 24`" == "1" ]; then
newh="`expr ${newh} - 24`"
fi
pto="${newh}${preadddh}${adddh}:${newm}:${news}"
#echo $pto
#echo ${newh} ${preadddh} ${adddh} : ${newm} : ${news}
#echo $thsx
#exit
fi
#one="`expr ${chis} - ${his} + ${hfrom} + ${addh}`:`expr ${cmis} - ${mis} + ${mfrom} + ${addm}`:`expr ${csis} - ${sis} + ${sfrom} + ${adds}`"
one="`expr ${chis} - ${his} + ${hfrom}`:`expr ${cmis} - ${mis} + ${mfrom}`:`expr ${csis} - ${sis} + ${sfrom}`"
hfrom="`echo ${one}:00 | cut -f 1 -d ':' | cut -f 1 -d '-' | cut -f 1 -d '+' | tr -d '-'`"
mfrom="`echo ${one}:00 | cut -f 2 -d ':' | cut -f 1 -d '-' | cut -f 1 -d '+' | tr -d '-'`"
sfrom="`echo ${one}:00 | cut -f 3 -d ':' | cut -f 1 -d '-' | cut -f 1 -d '+' | tr -d '-'`"
his="`echo ${cnowis}:00 | cut -f 1 -d ':'`"
mis="`echo ${cnowis}:00 | cut -f 2 -d ':'`"
sis="`echo ${ccnowis}:00 | cut -f 3 -d ':'`"
nowis="${ccnowis}"
fi
else
bnowis="`date '+%H:%M'`"
cnowis="`date '+%H:%M'`"
fi
if [ "`expr ${hfrom} - ${his} \<= 0`" == "1" ]; then
#echo "Time found ${one} versus ${nowis} ... `expr ${hfrom} - ${his}`"
if [ "`expr ${hfrom} - ${his} \< 0`" == "1" ]; then
hfrom="`expr ${hfrom} + 24`"
else
if [ "`expr ${mfrom} - ${mis} \<= 0`" == "1" ]; then
if [ "`expr ${mfrom} - ${mis} \< 0`" == "1" ]; then
hfrom="`expr ${hfrom} + 24`"
else
if [ "`expr ${sfrom} - ${sis} \<= 0`" == "1" ]; then
if [ "`expr ${sfrom} - ${sis} \< 0`" == "1" ]; then
hfrom="`expr ${hfrom} + 24`"
fi
fi
fi
fi
fi
fi
curpid="$$"
precmdline="`ps -p ${curpid} -o args | sed '/^ARGS/s///g' | sed '/^ksh /s///g' | tr -d \"\n\"`"
if [ -z "${twoy}" ]; then
#echo "1:${cmdline}"
cmdline=`echo ${precmdline} | awk -v FS="${1}" '{ print $1 $2; }'`
#echo "-1:${cmdline}"
else
#echo "5:${precmdline}"
rtd="`echo ${1} | sed '/\:00\:00\:00\:00/s///g'`"
#echo "5rtd:${rtd}"
cmdline="`echo ${precmdline} | awk -v FS="${rtd}" '{ print $1 FS \":00:00:00:00\" $2; }'`"
cmdline="`echo ${cmdline} | sed \"/${1}:00:00:00:00${1}:00:00:00:00/s//${1}:00:00:00:00/g\" | sed \"/${1}${1}/s//${1}/g\"`"
#echo "6:${cmdline}"
fi
#echo "7:${cmdline}"
cmdline="`echo ${cmdline} | sed '/\:00\:00\:00\:00\:00\:00\:00\:00/s//\:00\:00\:00\:00/g'`"
#echo "8:${cmdline}"
if [ ! -z "${pfrom}" -a ! -z "${pto}" ]; then
#echo $pfrom
#echo $pto
#echo $cmdline
if [ ! -z "${pto}" -a "`echo \"${cmdline}\" | sed '/\:00\:00\:00\:00\:00\:00\:00\:00/s///g'`" == "`echo \"${cmdline}\"`" ]; then
cmdline="`echo ${cmdline} | sed \"/${pfrom}/s//${pto}:00:00:00:00/g\"`"
else
cmdline="`echo ${cmdline} | sed \"/${pfrom}/s//${pto}/g\"`"
fi
#echo $cmdline
#exit
fi
secstowait="`expr ${hfrom} - ${his}`"
secstowait="`expr ${secstowait} \\* 3600`"
stowait="`expr ${mfrom} - ${mis}`"
stowait="`expr ${stowait} \\* 60`"
secstowait="`expr ${stowait} + ${secstowait}`"
stowait="`expr ${sfrom} - ${sis}`"
secstowait="`expr ${stowait} + ${secstowait}`"
if [ ! -z "${twoy}" ]; then
secstowait="`expr 1 + ${secstowait}`"
fi
cmdline="`echo ${cmdline} | sed '/\:00\:00\:00\:00\:00\:00\:00\:00/s//\:00\:00\:00\:00/g' | tr -d '?'`"
#echo "TIME found ${1} versus ${nowis} ... `expr ${hfrom} - ${his}` ... ${secstowait} ... ${cmdline} ... ${nowis} ... ${cnowis} ... sleep ${secstowait}; `echo ${cmdline}` nohup ksh -c \"sleep ${secstowait} ; cd \\\"`pwd`\\\" ; `echo ${cmdline}${cmdsuffix}` ;\" > /dev/null 2> /dev/null"
nohup ksh -c "sleep ${secstowait} ; cd \"`pwd`\" ; ksh `echo ${cmdline}${cmdsuffix}` ;" > /dev/null 2>> /dev/null &
if [ "`echo ${1} | sed '/\:00\:00\:00\:00/s///g'`" == "`echo ${1}`" ]; then
exit
fi
else
ppid="`echo ${1} | tr -d '?'`"
#if [ "`ps -ef | grep ' ${1} ' | grep -v 'grep'`" ]; then
# exit
#fi
fi
fi
fi
fi
shift
done
emailfrom="`echo ${emailfrom} | tr -d ' '`"
emailto="`echo ${emailto} | tr -d ' '`"
emailcc="`echo ${emailcc} | tr -d ' '`"
fi
if [ ! -z "${flist}" ]; then
i=0
for xfilebits in ${flist}; do
ksh ${prefix} ${xfilebits} &
((i=i+1))
done
fi
while [ 0 -lt 1 ]; do
if [ "$postiftwoquit" == "2" ]; then
if [ "$iftwoquit" == "1" ]; then
iftwoquit="`ps -ef | grep \" ${thispid} \" | grep ':00:00:00:00' | grep -v ' sleep ' | grep -v ' grep ' | wc -l | tr -d ' '`"
if [ "$iftwoquit" != "0" ]; then
if [ "$iftwoquit" != "1" ]; then
exit
fi
fi
fi
elif [ "$postiftwoquit" == "1" ]; then
postiftwoquit="`ps -ef | grep \" ${thispid} \" | grep -c ':00:00:00:00'`"
fi
if [ -z "${flist}" ]; then
if [ ! -z "${ppid}" ]; then
if [ "`ps -ef | grep ' ${ppid} ' | grep -v 'grep'`" ]; then
exit
fi
fi
fi
if [ ! -z "${mimetype}" ]; then
#echo 34
#echo $topiccmd1
#echo $topiccmd2
#echo $topiccmd3
#cur="``${topiccmd1}` | `${topiccmd2}` | `${topiccmd3}` | wc -l | tr -d ' '`"
cur="`${topiccmd1} | ${topiccmd2} | ${topiccmd3} | wc -l | tr -d ' '`"
#cur="`${topiccmd1} | wc -l | tr -d ' '`"
#echo $cur
else
cur="`ls -l ${filen}`"
fi
echo "`date` $cur"
if [ "$lastcur" != "$cur" ]; then
if [ -z "`echo \"${lastcur}\" | tr -d ' '`" ]; then
lastdate="`date`"
if [ ! -z "${mimetype}" ]; then
echo "${topiccmd1} | ${topiccmd2} | ${topiccmd3}" > date_ps_ef_first_bit.ksh
ksh ./date_ps_ef_first_bit.ksh > date_ps_ef_first.txt
rm -f ./date_ps_ef_first_bit.ksh
attachrest="\\nFirst ${subjmiddle} at ${lastdate}
UID | PID | PPID | C | STIME | TTY | TIME | CMD |
`cat date_ps_ef_first.txt | sed '/^/s///g' | sed 's/ \{1,\}/<\/td> | /g' | awk '{ t=0; while (getline \$0) { if (t == 0) { print \" |
<\/tr>/g'`
"
fi
subjis="`echo \"${subjis}\" | sed \"/ with file/s// with ${subjmiddle}/g\" | sed \"/\[file\]/s//${subjmiddle}/g\"`"
attachrest="`echo \"${attachrest}\" | sed \"/ with file/s// with ${subjmiddle}/g\" | sed \"/\[file\]/s//${subjmiddle}/g\"`"
#echo 12
echo -e "${mimetype}From: ${emailfrom}\nTo: ${emailto}\nCC: ${emailcc}\n${emailbcc}Subject: ${subjis}\n${attachrest}" | sendmail -t -f ${emailto}
if [ ! -z "${mimetype}" ]; then
if [ ! -f "date_ps_ef_next.txt" ]; then
echo "" > date_ps_ef_next.txt
fi
attachrest="\\nChanged ${subjmiddle} at ${lastdate}
"
fi
if [ -z "${cur}" ]; then
exit
fi
else
thisdate="`date`"
if [ ! -z "${mimetype}" ]; then
subjis="Changed ${subjmiddle} at ${thisdate}"
echo "`${topiccmd1} | ${topiccmd2} | ${topiccmd3}`" > date_ps_ef_next.txt
else
basechars="`base64 ${filen} | tr -d \"\\n\"`"
if [ "`echo \"${subjis}\" | sed '/^First /s//Changed /g'`" != "`echo \"${subjis}\"`" ]; then
subjis="Changed ${subjmiddle} at ${thisdate}"
attachrest="Mime-Version: 1.0\\nContent-Type: multipart/mixed; boundary=\"19032019ABCDE\"\\n\\n--19032019ABCDE\\nContent-Type: text/${plain}; charset=\"iso-8859-1\"\\nContent-Transfer-Encoding: 8bit\\n\\n${hprefix}${subjis}${hsuffix}\\n\\n--19032019ABCDE\\nContent-Type: application/octet-stream; name=\"${shortf}\";\\nContent-Transfer-Encoding: base64\\nContent-Disposition: attachment;filename=\"${shortf}\"\\n\\n${basechars}\\n--19032019ABCDE--"
else
subjis="`echo \"${subjis}\" | sed \"/${lastdate}/s//${thisdate}/g\"`"
attachrest="Mime-Version: 1.0\\nContent-Type: multipart/mixed; boundary=\"19032019ABCDE\"\\n\\n--19032019ABCDE\\nContent-Type: text/${plain}; charset=\"iso-8859-1\"\\nContent-Transfer-Encoding: 8bit\\n\\n${hprefix}${subjis}${hsuffix}\\n\\n--19032019ABCDE\\nContent-Type: application/octet-stream; name=\"${shortf}\";\\nContent-Transfer-Encoding: base64\\nContent-Disposition: attachment;filename=\"${shortf}\"\\n\\n${basechars}\\n--19032019ABCDE--"
fi
fi
lastdate="${thisdate}"
subjis="`echo \"${subjis}\" | sed \"/ with file/s// with ${subjmiddle}/g\" | sed \"/\[file\]/s//${subjmiddle}/g\"`"
#echo 16
echo -e "${mimetype}From: ${emailfrom}\nTo: ${emailto}\nCC: ${emailcc}\n${emailbcc}Subject: ${subjis}\n${attachrest}" | sendmail -t -f ${emailto}
if [ ! -z "${mimetype}" ]; then
cat date_ps_ef_next.txt > date_ps_ef_first.txt
fi
fi
lastcur="$cur"
fi
if [ ! -z "${mimetype}" ]; then
if [ -z "${mimetype}" ]; then
"`${topiccmd1} | ${topiccmd2} | ${topiccmd3}`"
fi
fi
sleep 30
done
exit