Reputation: 1
I’m trying to run a bash script as a cronjob to make table data offline. I updated my Dockerfile and added the following configuration for this. While I can see the folders being created, the cronjob itself isn’t running. I’ve checked the logs, but unfortunately, they are blank.
I believe I’m starting the cron service correctly and using the correct syntax for scheduling the cronjob.
I can see the cronjob listed when I run crontab -l, but I’m unsure why it’s not functioning as expected. I’m accessing my environment via the AWS CLI using a bastion host.
Any help or suggestions would be greatly appreciated!
Here is the cronjob configuration:
30 9 * * * /opt/scripts/partition-offline.sh --env=sb --remove_days=5 --table=all >> /opt/utility/offline_partition_log/cron_partition_offline_sb.log 2>&1
Dockerfile Configuration.
# Install cronie and rsyslog for cron job logging
RUN dnf install -y cronie rsyslog
# Create necessary directories
RUN mkdir -p /opt/scripts \
&& mkdir -p /opt/utility/offline_partition_log \
&& chmod -R 777 /opt/utility/offline_partition_log
# Copy the partition script
COPY files/opt/utility/partition_offline_script/partition-offline.sh /opt/scripts/
RUN chmod +x /opt/scripts/partition-offline.sh
# Setup cron jobs (5 PM PST (1 AM UTC) and 9:30 AM for dev environment)
RUN echo "38 3 * * * /opt/scripts/partition-offline.sh --env=sb --remove_days=5 --table=all >> /opt/utility/offline_partition_log/cron_partition_offline_sb.log 2>&1" > /var/spool/cron/root \
&& echo "38 3 * * * /opt/scripts/partition-offline.sh --env=dev --remove_days=5 --table=all >> /opt/utility/offline_partition_log/cron_partition_offline_dev.log 2>&1" >> /var/spool/cron/root \
&& echo "* * * * * echo \"Cron is working - this is to test cron service\" >> /opt/utility/offline_partition_log/test_cron.log 2>&1" >> /var/spool/cron/root \
&& chmod 600 /var/spool/cron/root
# Enable cron and rsyslog logging
RUN echo "cron.* /var/log/cron" >> /etc/rsyslog.conf \
&& touch /var/log/cron \
&& chown root:root /var/log/cron \
&& chmod 600 /var/log/cron
# Start rsyslog and crond in the foreground
CMD /usr/sbin/rsyslogd && /usr/sbin/crond -n -s
I was expecting this cronjob to run and generate log responses under the directory: /opt/utility/offline_partition_log
Upvotes: -2
Views: 37