
我使用此 cron 收到 406 錯誤頁面。
編輯
我已經更新了 cron 以使用 wget 代替,但我仍然沒有從頁面獲得輸出。這是新的 crontab:
/usr/bin/wget "https://abc.com/cron/sendBulletinEmails.php" >> /home/abc/public_html/cron/logs/sendBulletinEmails.log
但是,這甚至沒有使用日誌檔案。我收到一封電子郵件。這是電子郵件輸出:
--09:20:01-- https://abc.com/cron/sendBulletinEmails.php
=> `sendBulletinEmails.php'
Resolving abc.com... 69.91.162.123
Connecting to fin-iq.com|69.91.162.123|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
0K 122.58 B/s
09:20:02 (122.58 B/s) - `sendBulletinEmails.php' saved [101]
我也嘗試過這個 crontab (以獲得正確的輸出):
/usr/bin/wget --append-output=/home/abc/public_html/cron/logs/sendBulletinEmails.log "https://abc.com/cron/sendBulletinEmails.php"
但是,這也給了我與電子郵件相同的日誌。該頁面輸出文本,這就是我想要記錄在日誌文件中的內容。關於如何使其發揮作用有什麼想法嗎?
再次感謝!
老的
這是 crontab(從 cPanel 複製):
* * * * * GET https://abc.com/cron/sendBulletinEmails.php >>
/home/abc/public_html/cron/logs/sendBulletinEmails.log
這是日誌:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource /cron/sendSurveyEmails.php could not be found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
另外,當我從自己的瀏覽器運行它時,它可以工作。
關於為什麼會發生這種情況有什麼想法嗎?謝謝=)
答案1
從 cron 取得電子郵件是設計使然。您可以透過新增>/dev/null 2>&1
到行尾來停用此功能。 (在這裡閱讀有關 cron 的更多資訊:
http://adminschoice.com/crontab-quick-reference)
我認為問題的其餘部分可以透過更多地閱讀有關 wget 的內容來解決。您正在嘗試使用標準輸出重定向將輸出傳送到日誌檔案。該文件的內容將永遠是您通常在螢幕上看到的內容。 Wget 不顯示檔案本身,因此輸出重定向在這裡不起作用。好消息是 wget 有一個用於管理輸出檔案的內建開關。
嘗試這個:
/usr/bin/wget -O /home/abc/public_html/cron/logs/sendBulletinEmails.log "https://abc.com/cron/sendBulletinEmails.php" >/dev/null 2>&1
答案2
伺服器可能正在尋找 HTTP_USER_AGENT 來阻止自動化工具。如果可以的話,請嘗試“wget”。它支援-U or --user-agent=AGENT
命令列上的開關,以幫助您的腳本看起來像是有效的 Firefox / Interner Explorer 瀏覽器會話。
否則,您可能需要編寫一個小腳本來使用該 Perl 模組的更強大的功能,並讓 cron 作業運行該腳本,而不是直接呼叫 get。我在這裡找到了一些例子:http://perlmeme.org/tutorials/lwp.html