에 작업을 추가했습니다 crontab
.
20 2 * * * sh /home/tomcat/bin/test3.sh
20 2 * * * sh /home/tomcat/bin/test.sh
권한을 확인했습니다 ..
-rwxr-xr-x 1 root root 58 May 19 02:04 test3.sh
-rwxr-xr-x 1 root root 3223 May 16 08:20 test.sh
그리고 test3.sh
명령 줄과 crontab
.
#!/bin/sh
echo "test test test..." > /test3_sh.txt
하지만 test.sh
에서 작동하지 않습니다 crontab
. 코드는 약간 복잡하고 복잡해 보이지만 목적은 간단합니다. MYSQL에서 데이터를 검색하고 sendmail
. test.sh
명령 줄에서 실행하면 작동하지만 crontab
그렇지 않습니다.
#!/bin/sh
results=`mysql -N -h mysqlhost.com -u user -pmypassword -e "USE MYDB;
SELECT
column1,
column2,
column3,
column4
FROM MYTABLE
ORDER BY REG_DT DESC
LIMIT 10;"`
IFS=$'
'
x="<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style><table class="gridtable">
<tr>
<th>column 1</th><th>column 2</th><th>column 3</th><th>column 4</th>
</tr>"
for i in $results;
do
x+="<tr>"
x+="$i
"
x+="</tr>"
done
x+="</table>"
cat - /home/tomcat/bin/test.log << EOF | sendmail -t -f [email protected]
to:[email protected]
from:[email protected]
subject:test mail
Mime-Version: 1.0
Content-Type: text/html
<html>
<body>
<h3>my recent articles..</h3>
$x
<br><hr>
</body>
</html>
EOF
나는이 문제를 검색했고 일부는 일부 pahts 및 ENV 변수가 명령 줄 및 crontab과 다르게 작동한다고 말했습니다. 그러나 내 sh에는 ENV 변수와 같은 것이 없습니다. 내 sh에 로그 경로가 있습니다. 약간 의심 스럽지만 이것이 문제가 될 수 있을지 모르겠습니다.
cat - /home/tomcat/bin/test.log << EOF | sendmail -t -f [email protected]
길이었다. 이 경로를 추가 crontab
하고 잘 작동합니다!
# path
SHELL=/bin/bash
PATH=/usr/local/bin/:/sbin:/bin:/usr/sbin:/usr/bin
LANG=en_US.UTF-8
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다