I want to send an automatic email from Unix server after checking particular log is running or not. Every three hours, i want to login in and check X.log and y.log ran or not and taking manaully when it ran. Can anyone help to automate it ?
Hey You can use below script to check if file exists & set it in cronjob to run it every three hours.
CODE:
#!/bin/bash
export LOGNAME="x.log"
export DATE=$(date "+%Y-%m-%d-%T")
export MAILID="Emailid"
if [[ -e "$LOGNAME" ]];then
mail -s "$HOSTNAME: is having $LOGNAME on @ $DATE" $MAILID < "$LOGNAME"
else
mail -s "$HOSTNAME: is not having $LOGNAME on @ $DATE" $MAILID
fi
Setting up in crontab:
#crontab -e
Add the below lines:
* */3 * * * <path of your script to run>
$LOGNAME overrides a POSIX reserved variable. Generally it's better to use lowercase variables, i.e. $logname in this instance - Chris Davies
cronservice to run every three hours... and more details needed for "ran" meant for.... - Siva