feat: adjust file-dload-curl-cert-while.sh

This commit is contained in:
dancingCycle 2023-12-16 12:46:47 +01:00
parent 8f144aa868
commit 0e1da8910c
3 changed files with 83 additions and 8 deletions

View File

@ -3,17 +3,16 @@
echo "started..."
#
# special variable $# is the number of arguments
if [ $# -lt 6 ] ; then
echo 'Call ./<script> <size: absolute file name> <size: minimum file size in bytes> <size: csv email recipient list> <dload: url> <dload: cert secret> <dload: cert file path & name>'
if [ $# -lt 5 ] ; then
echo 'Call ./<script> <size: absolute file name> <size: minimum file size in bytes> <dload: url> <dload: cert secret> <dload: cert file path & name>'
exit 1
fi
#
file="$1"
minimumSize="$2"
emailRecipientList="$3"
dloadUrl="$4"
dloadCertKey="$5"
dloadCertFile="$6"
dloadUrl="$3"
dloadCertKey="$4"
dloadCertFile="$5"
#
retVal=1;
#echo "retVal initial state: ${retVal}"
@ -22,9 +21,9 @@ while [ $retVal -ne 0 ]
do
echo "call script: file-dload-curl-cert.sh"
sh ./file-dload-curl-cert.sh $dloadUrl $dloadCertKey $dloadCertFile $file
echo "call script: file-size.sh"
echo "call script: file-size-without-email.sh"
#TODO This looks like an asynchronous we are not waiting for, isn't it?
sh ./file-size.sh $file $minimumSize $emailRecipientList
sh ./file-size-without-email.sh $file $minimumSize
retVal=$?
#echo "retVal: ${retVal}"
done

40
file-size-with-email.sh Normal file
View File

@ -0,0 +1,40 @@
#!/bin/sh
#
echo "started..."
#
# special variable $# is the number of arguments
if [ $# -lt 3 ] ; then
echo 'Call ./<script> <absolute file name> <minimum file size in bytes> <csv email recipient list>'
exit 1
fi
#
file="$1"
echo "file: ${file}"
#
if [ ! -f $file ]; then
echo "ERROR: File not found!"
exit 1
fi
#
minimumSize="$2"
echo "minimumSize: ${minimumSize}"
emailRecipientList="$3"
#echo "emailRicipientList: ${emailRecipientList}"
now=$(date +%Y%m%d%H%M%S)
echo "now: ${now}"
actualSize=$(wc -c <"$file")
echo "actualSize: ${actualSize}"
output=""
#
if [ $actualSize -ge $minimumSize ]; then
output="$now: File ${file} size is greater than or equal minimum size of $minimumSize Bytes. Actual size: $actualSize Bytes"
echo $output
echo $output | mail -s "File size valid: ${file}" ${emailRecipientList}
else
output="$now: File ${file} size is less than minimum size of $minimumSize Bytes. Actual size: $actualSize Bytes"
echo $output
echo $output | mail -s "File size NOT valid: ${file}" ${emailRecipientList}
exit 1
fi
#
echo "done."

View File

@ -0,0 +1,36 @@
#!/bin/sh
#
echo "started..."
#
# special variable $# is the number of arguments
if [ $# -lt 2 ] ; then
echo 'Call ./<script> <absolute file name> <minimum file size in bytes>'
exit 1
fi
#
file="$1"
echo "file: ${file}"
#
if [ ! -f $file ]; then
echo "ERROR: File not found!"
exit 1
fi
#
minimumSize="$2"
echo "minimumSize: ${minimumSize}"
now=$(date +%Y%m%d%H%M%S)
echo "now: ${now}"
actualSize=$(wc -c <"$file")
echo "actualSize: ${actualSize}"
output=""
#
if [ $actualSize -ge $minimumSize ]; then
output="$now: File ${file} size is greater than or equal minimum size of $minimumSize Bytes. Actual size: $actualSize Bytes"
echo $output
else
output="$now: File ${file} size is less than minimum size of $minimumSize Bytes. Actual size: $actualSize Bytes"
echo $output
exit 1
fi
#
echo "done."