0

I have the Below Script to check the size of my Log file. Should it grow to beyond 84M to should be renamed with the current date and a a new one is automatically generated by my APP. However it doesnt run automatically using cron tasks. Help me to add code to check if it reaches 84M to send me an email then I can run the script manually.

#!/bin/bash
#Andrew O. MBX 2016-01-26
#HansaWorld Script to Check Size of Hansa.log file
# and move it to a new folder HansaLogs

tstamp=$(date "+%m%d%Y")                    #Set Timestamp
logdir="/u/HansaWorldLive/HansaLogs"            #Set path to where hansa.log will be moved
logname="/u/HansaWorldLive/hansa.log"               #Set Path to hansa.log file
maximumsize= +83500K                    #Set maximumsize
actualsize=$(wc -c<"$logname")
if [ $actualsize -ge $maximumsize ]; then
    mv "$logname" "$logdir/hansa_${tstamp}.log" #Move the Log file and rename by adding timestamp
    else
    echo size is under $maximumsize bytes
exit 1
fi
0
sudo gedit /etc/crontab

Add the following line to the bottom of the document:

00 *  * * *  MYUSERNAME  bash /path/to/my/file &> /dev/null

This will run the /path/to/my/file with bash every hour, if you want to change the frequency, read more about CronTab.

As for email sending, that is a much larger setup for another question, that has already been answered. Something like this is a start, but Google is your friend for this one.

  • @Cbhihe ... Look if you are trying to help... Great, help. But no need for this attitude. If you see an issue with my answer, let me know and how I should fix it. I've done the above work before on my machine and it has worked for scripts that have echos and possible errors. – Zzzach... May 9 '16 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.