Crontab не может запускать скрипты?

Я гуглил и смотрел на это весь день. Я чувствую, что что-то наполовину очевидно, что мне здесь не хватает. Я все еще новичок, когда дело доходит до Linux, и даже больше, когда дело доходит до Cron. Может ли один из вас, гуру, помочь мне найти решение?

cron entry

1 * * * * /data/cronScripts/weeklyPageCreate.sh

i Я хочу, чтобы он запускался каждую минуту, чтобы подтвердить, что он вообще будет работать , До сих пор я не видел каких-либо ошибок в / var / log / cron

самого скрипта

#!/bin/bash

DATE_TODAY=$(/bin/date +'%Y-%m-%d')
DATE_TODAYMINUSFIVE=$(/bin/date +'%Y-%m-%d' -d '7 day ago')
#echo $DATE_TODAY
#echo $DATE_TODAYMINUSFIVE

curl -u 'user':'pass' -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"Weekly Report ('$DATE_TODAY')","ancestors":[{"id":316048939}], "space":{"key":"ITC"},"body":{"storage":{"value":"<ac:structured-macro ac:name=\"hideelements-macro\" ac:schema-version=\"1\"><ac:parameter ac:name=\"metas\">true</ac:parameter><ac:parameter ac:name=\"comments\">true</ac:parameter><ac:parameter ac:name=\"edit\">true</ac:parameter><ac:parameter ac:name=\"watch\">true</ac:parameter><ac:parameter ac:name=\"create\">true</ac:parameter><ac:parameter ac:name=\"favorite\">true</ac:parameter><ac:parameter ac:name=\"labels\">true</ac:parameter><ac:parameter ac:name=\"likes\">true</ac:parameter></ac:structured-macro><h1>B2B</h1><ac:structured-macro ac:name=\"jira\" ac:schema-version=\"1\"><ac:parameter ac:name=\"server\">JIRAAPPLINK</ac:parameter><ac:parameter ac:name=\"columns\">key,summary,created,assignee,reporter,resolution</ac:parameter><ac:parameter ac:name=\"maximumIssues\">20</ac:parameter><ac:parameter ac:name=\"jqlQuery\">project = AND resolved >= '$DATE_TODAYMINUSFIVE' AND resolved &lt;= '$DATE_TODAY' </ac:parameter><ac:parameter ac:name=\"serverId\">d9064433-ee34-3ef3-8b28-1606bcb513a1</ac:parameter></ac:structured-macro><h1>Data</h1><ac:structured-macro ac:name=\"jira\" ac:schema-version=\"1\"><ac:parameter ac:name=\"server\">JIRAAPPLINK</ac:parameter><ac:parameter ac:name=\"columns\">key,summary,created,assignee,reporter,resolution</ac:parameter><ac:parameter ac:name=\"maximumIssues\">20</ac:parameter><ac:parameter ac:name=\"jqlQuery\">project = AND resolved >= '$DATE_TODAYMINUSFIVE' AND resolved &lt;= '$DATE_TODAY' </ac:parameter><ac:parameter ac:name=\"serverId\">d9064433-ee34-3ef3-8b28-1606bcb513a1</ac:parameter></ac:structured-macro><h1>SalesForce</h1><ac:structured-macro ac:name=\"jira\" ac:schema-version=\"1\"><ac:parameter ac:name=\"server\">JIRAAPPLINK</ac:parameter><ac:parameter ac:name=\"columns\">key,summary,created,assignee,reporter,resolution</ac:parameter><ac:parameter ac:name=\"maximumIssues\">20</ac:parameter><ac:parameter ac:name=\"jqlQuery\">project =  AND resolved >= '$DATE_TODAYMINUSFIVE' AND resolved &lt;= '$DATE_TODAY' </ac:parameter><ac:parameter ac:name=\"serverId\">d9064433-ee34-3ef3-8b28-1606bcb513a1</ac:parameter></ac:structured-macro><h1>Oracle</h1><ac:structured-macro ac:name=\"jira\" ac:schema-version=\"1\"><ac:parameter ac:name=\"server\">JIRAAPPLINK</ac:parameter><ac:parameter ac:name=\"columns\">key,summary,created,assignee,reporter,resolution</ac:parameter><ac:parameter ac:name=\"maximumIssues\">20</ac:parameter><ac:parameter ac:name=\"jqlQuery\">project = Oracle AND resolved >= '$DATE_TODAYMINUSFIVE' AND resolved &lt;= '$DATE_TODAY' </ac:parameter><ac:parameter ac:name=\"serverId\">d9064433-ee34-3ef3-8b28-1606bcb513a1</ac:parameter></ac:structured-macro><ac:structured-macro ac:name=\"previous-next-navigation\" ac:schema-version=\"1\"><ac:parameter ac:name=\"next-button-text\">Next Week</ac:parameter><ac:parameter ac:name=\"previous-button-text\">Previous Week</ac:parameter><ac:parameter ac:name=\"button-style\">Primary</ac:parameter><ac:parameter ac:name=\"parent-button-text\">Directory</ac:parameter></ac:structured-macro>","representation":"storage"}}}' https://site.domain.com/rest/api/content | python -mjson.tool

Это прекрасно работает из командной строки, и у меня есть chmod + x на это.

Я думаю, побочный вопрос. Существует / etc / crontab , и затем вы можете отредактировать crontab с помощью crontab -e , но была ли разница? Всегда ли выполняются оба, и есть ли причина, по которой вы помещаете задания в одно, а не в другое?

2
задан 16 June 2020 в 23:32

2 ответа

Your script is probably fine!

Your crontab instructions are not right:

1 * * * * /data/cronScripts/weeklyPageCreate.sh will not run every minute.

A numeral in any column represents the specific minute/hour/day/month/weekday when the cronjob is scheduled to run.

The * expression is the notation that stands for "all" or "every"

So 1 * * * * will actually schedule the job to run on all weekdays, all months, every day, and every hour, at the first minute of each hour. ie. 4:01; 5:01; 6:01

If you want the job to run every minute, you would use the notation * * * * *. This means the job will scheduled for all weekdays, all months, every day, and every minute of every hour.

If you want your script to run every minute, the full crontab line should be:

* * * * * /data/cronScripts/weeklyPageCreate.sh

If you need help deciphering crontab notation in the future, use your favorite search engine and search for a "crontab calculator". There are many out there!

2
ответ дан 19 June 2020 в 21:23

I would always ensure you output your scripts to script logs so something like

1 * * * * /data/cronScripts/weeklyPageCreate.sh >> /path/to/weeklyPageCreate.log 2>&1

That way you have a log of any errors/messages from that script to see if it's running or causing errors.

One common issue with cron is that the environment is not the same as a user shell environment so environment variables that may be present in your shell will not be present when the script is run in cron. So your scripts may need to explicitly set variables or source scripts to set variables etc.

Have a read here at the bottom for cron "gotchas": https://www.pantz.org/software/cron/croninfo.html

1
ответ дан 19 June 2020 в 21:23

Другие вопросы по тегам:

Похожие вопросы: