I have written about 10 scripts that create individual log files of tasks on my Raspberry Pi4 (OS is Ubuntu Server). These scripts are activated via crontab, ssh query my 12 Raspberry Pi MotionEye security cameras, and report back what they have done in created log files and email messages. The scripts activate at different cron times (however, 3 of them run on the hour with 2 of those only running at midnight), but will sometimes overlap when running. Currently, the scripts are pretty much self sustaining. What I would like to do is create a sub-script that does the emailing so I don't have to keep up with that task in each main script should I make any changes. To test this, I created 7 test script files, TestFileA - TestFileG that write varying lines of text to their own individual log files (6, 9, 12, 4, 10, 12, & 4 lines):
#!/bin/sh export TLOG=/home/.myaccountname./TestDir/TestFileD.tmp ALOG=/home/.myaccountname./TestDir/TestFileD.log ##### echo "This TestFileD log contains 2 additional lines" >| $TLOG echo "TestFileD, Line 1" >> $TLOG echo "$(date "+%m-%d-%Y %T"): TestFileD Complete" >> $TLOG cat $TLOG >> $ALOG /home/.myaccountname./TestDir/SendLog.sh echo "MailFile: "$MailFile >> $ALOG rm $TLOG
Each script then ends with assigning the temporary individual log file name to the same $TLOG variable and calls on the SendLog sub-script, which is basically:
#!/bin/sh MailFile="$TLOG".txt cat /home/.myaccountname./TestDir/_EmailHeader $TLOG >| $MailFile cat $MailFile | /usr/sbin/ssmtp .myemailaddress.@gmail.com rm $MailFile
Finally, I created a crontab to execute all 7 test scripts at the exact same time once an hour. I did this to make sure if I wrote this into my "live" scripts, that there would not be any conflicts from the same "sub-script" being accessed by multiple scripts using the same variables at the same time. So far, the first 2 times the crontab executed, I only received 5 emails. The latest (3rd) time this executed, I did receive all 7 emails. (Each time, all 7 logs files are properly created). Does anyone see anything wrong with what I am doing before I write into the live scripts?