Cronjob is not running properly but work while run command (./)
I have this script for file testfile.sh
:
SEND_EMAIL(){
TO="[email protected]"
CC_MAIL="[email protected]"
sendmail $TO,$CC_MAIL <<EOF
From: [email protected]
To: $TO
Cc: $CC_MAIL
Subject:Report
Content-Type: text/html;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th,table {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
empty-cells: show;
}
-->
</style>
</head>
<body>
Hi Team,<br><br>
Fyi, IT Operation repot<br>
<br>
<table cellpadding="0" cellspacing="0" border="1" bordercolor="black" style="wi
dth: 500px">
<tr bgcolor="silver" align="center" style="font-weight:bold">
<td>REPORTED_BY</td>
<td>TICKET_ID</td>
<td>HELP_TOPIC</td>
<td>SUBJECT</td>
<td>CREATION_DATE</td>
<td>REOPENED</td>
<td>EST_DUEDATE</td>
<td>UPDATED</td>
<td>PRIORITY</td>
<td>USERNAME</td>
</tr>
</table>
<br>
<br>
Regards,<br>
IT Team
</body>
</html>
EOF
}
In crontab, I have this line:
* * * * * /bin/sh /opt/testfile.sh
I have restarted crontab, but nothing is happening.
If I run with the command manually, like ./test8.sh
, then I receive an email.
Why is this not working from crontab?
I solved it by adding the path /sbin/sendmail
on the script
#!/bin/bash
SEND_EMAIL(){
TO="[email protected]"
CC_MAIL="[email protected]"
/sbin/sendmail $TO,$CC_MAIL <<EOF
From: [email protected]
To: $TO
Cc: $CC_MAIL
Subject:Report
Content-Type: text/html;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th,table {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
empty-cells: show;
}
-->
</style>
</head>
<body>
Hi Team,<br><br>
Fyi, IT Operation repot<br>
<br>
<table cellpadding="0" cellspacing="0" border="1" bordercolor="black" style="wi
dth: 500px">
<tr bgcolor="silver" align="center" style="font-weight:bold">
<td>REPORTED_BY</td>
<td>TICKET_ID</td>
<td>HELP_TOPIC</td>
<td>SUBJECT</td>
<td>CREATION_DATE</td>
<td>REOPENED</td>
<td>EST_DUEDATE</td>
<td>UPDATED</td>
<td>PRIORITY</td>
<td>USERNAME</td>
</tr>
</table>
<br>
<br>
Regards,<br>
IT Team
</body>
</html>
EOF
}
SEND_EMAIL