0

Not sure what's going on as this cronjob is pretty straighforward. I want my cronjob to run every 5 minutes. Below is the script (memory.sh) in it's entirety.

Below that is the schedule it's requested to run on via the crontab.

I've replicated the crontab and run crontab memory.sh both under my username and as root, but each time I get the same error:

"/opt/memory.sh":4: bad minute
errors in crontab file, can't install.

memory.sh

#!/bin/bash

now=`date +%Y-%m-%d.%H:%M:%S`

echo "$now" >>/opt/memory.out
ps aux --sort -rss>> /opt/memory.out


echo "$now" >>/opt/memory_free.out
free -m>> /opt/memory_free.out

crontab

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command*
*/5 * * * * /opt/memory.sh

directory

enter image description here

NealR
  • 10,189
  • 61
  • 159
  • 299

1 Answers1

0

crontab memory.sh installs a new crontab file. memory.sh is not a crontab, it is a script references from the crontab file. You need to pass the crontab file to the crontab command, or edit the existing file using crontab -e to add the line you indicated.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • Not sure I'm following. The code pasted under my `crontab` section is what comes up when I input `crontab -e`. It was originally blank until I added the schedule/command you see on the final line. I then try to run `crontab memory.sh` from the command line and get the bad minute error. Is there something different/further I need to do? – NealR Oct 03 '18 at 12:12
  • You don't need to run `crontab memory.sh` if you have edited the crontab using the `-e` option. What are you attempting to do with this command? – Florian Weimer Oct 03 '18 at 12:14
  • I see. I want the script to run every 5 minutes and run a quick memory profile. I've set it to output a file `memory.out` in the `/opt` folder, but I'm not seeing anything (I set it to run yesterday morning) – NealR Oct 03 '18 at 12:16