I wrote a shell script which calculates the execution time of itself but the problem I'm facing is its not able to send the time difference via email. Please Help.
Here is the Script
#!/bin/bash
start=$(date +%s.%N)
ls /etc > /tmp/x
rm /tmp/x
executiontime(){
end=$(date +%s.%N)
diff=$(echo "$end-$start" | bc)
echo "Inside function $diff"
}
#Email Function
Sender="Sendmail"
Recpt="[email protected]"
Sub="Test"
Message="sendmail function $diff"
#Sendmail Function
sendmailfun() {
sendmail -F $Sender -it <<END_MESSAGE
To: $Recpt
Subject: $Sub
$Message
END_MESSAGE
}
executiontime
echo "outside function $diff"
sendmailfun
When I run this script the output on the cmd line is like follows
root@itpl-lptp-008:/home/incaendo/Downloads# sh executiontest.sh
Inside function .008025182
outside function .008025182
But the email I get after executing the above script just have the line as follows
sendmail function
i.e. without the $diff value. why so? Is there anyway I can send the time difference via email.