2

I have been googling and looking at this all day. I feel like there is something semi obvious that I am missing here. I am still a newbie when it comes to linux, and even more so when it comes to cron. Could one of you gurus help me find the solution?

cron entry

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

I want it to run every minute to confirm its going to run at all. So far, I have not seen any errors coming out in /var/log/cron

Script itself

#!/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

This runs just fine from command line, and I have chmod +x on it.

I guess side question. There is /etc/crontab and then you can edit crontab with crontab -e, but was is the difference? Do both always run, and is there a reason you put jobs in one rather than the other?

13
  • what does the script do when you run from command line? – pLumo Jun 16 '20 at 20:44
  • It returns a 200 response with a json dump of the page being create from the curl command. The script is used to create a page in the company internal wiki on a weekly basis pull stats from our issue tracker – BlueBaroo Jun 16 '20 at 20:48
  • If it does tasks that need admin level permissions then you will need to create that cron job using the command sudo crontab -e – George Udosen Jun 16 '20 at 20:49
  • Also, check cron service is running service cron status – codlord Jun 16 '20 at 20:52
  • 2
    1 * * * * means the cronjob is run on the 1st minute of every hour. It's not every minute. * * * * * is every minute. Could this be your problem? – Nmath Jun 16 '20 at 21:12
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!

1

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
  • So what is strange is that I do have that in there now, but it doesnt output anything to that file – BlueBaroo Jun 16 '20 at 21:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.