Amazon Web Services - cronjob not running every minute - amazon-web-services

I have a cronjob defined on an AWS ec2 (so it uses crontab). I did crontab -e and added this line into it:
*/1 * * * * /usr/bin/php /path/to/file/file.php
I saved it with vim and it says crontab: installing new crontab. I also made the permissions on the file 755, using chmod, and I put the proper shebang (#!/usr/bin/php -q) at the top of file.php. The script should update a database every minute, but I am not seeing the database get updated at all. What did I do wrong?

logging example:
*/1 * * * * >> /var/log//your_cron.log 2>&1

Related

Schedule gsutil command

I am using gsutil to load data from local machine file to GCS.But now I want to schedule it like 20 minutes interval the data will be exported from local machine to google cloud storage.How can we create this type of cron job and where should I create?
You should create a script within your local machine to achieve this task.
It could look like this (making sure you give the file executable permissions):
#! /bin/bash
PATH="$PATH":[REPLACE with /path/to/gsutil/]
# The ".boto" file contains the settings that helps you do operations with your bucket: https://cloud.google.com/storage/docs/boto-gsutil
export BOTO_CONFIG=[REPLACE with "/home/username/.boto"]
# upload the file with the relevant gsutil command
gsutil cp [Replace with OBJECT_LOCATION] gs://[REPLACE with DESTINATION_BUCKET_NAME]/
The following cron schedule expression: */20 * * * * should trigger the job every 20 minutes, so edit the crontab file with crontab –e and add the following line:
*/20 * * * * [PATH-TO-SCRIPT]/[NAME-OF-SCRIPT].sh >/dev/null 2>&1
The following site is an excellent resource for you to calculate the cron schedule expression and this is a very nice tutorial on how to set up a cronjob with linux.

Cron with elastic beanstalk and symfony - not working

I'm a newbie developer and I am messing around with Symfony and AWS. I have a Symfony app deployed via elastic beanstalk and I am trying to add a cron job every minute.
Basically I want the cron job to execute a Symfony command I created : update-pings, that is supposed to update some fields in my RDS DB.
I'm using a 02-crons.config file in my ./ebextensions directory that looks like this (greatly inspired from AWS documentation https://aws.amazon.com/fr/premiumsupport/knowledge-center/cron-job-elastic-beanstalk/ ) :
files:
"/etc/cron.d/mycron":
mode: "000644"
owner: root
group: root
content: |
* * * * * root php /var/app/current/bin/console app:update-pings
commands:
remove_old_cron:
command: "rm -f /etc/cron.d/mycron.bak"
Well, first of all, this is not working, the fields in the DB are not updating. So i connected in SSH to my EC2 instance to see what's happening.
The mycron file in /etc/cron.d/was correctly created with * * * * * root php /var/app/current/bin/console app:update-pingsinside of it.
Now, I tried replacing the content of this file by a simple * * * * * root echo test >> /tmp/cron_temp, this is working perfectly, a line with 'test' is added in my cron_temp file every minute
I tried running the initial command php /var/app/current/bin/console app:update-pingsmanually on the instance, works perfectly as ec2-user
When I switch to root user using sudo su -, the command still works. But when I try to run it with sudo, it fails, not sure if that's any relevant :
In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_DBNAME".
I believe there is something I'm missing with linux users/rights, but I'm a total newbie with that and cannot find what's going on
Any ideas ? Thanks a lot in advance ! :)
Edit 1 : I'm know logging the sterr of the commande into a file and I get the same environment variable error as when I try to run the command manually with sudo
In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_DBNAME".
The command works fine without sudo though

AWS s3 file overwrite not working with crontab

I have a script which downloads a file from my s3 bucket, overwriting the existing file. The intention is to run the script once a day so that the file is constantly overwritten and updated.
Here's the command, on crontab:
03 23 * * * /Library/Frameworks/Python.framework/Versions/3.7/bin/aws s3 cp s3://sfbucket.bucket/sf_events.json /Users/Documents/TownSounds_Javascript/data/sf_events.json >> /Users/Documents/logs3.txt 2>&1
Really, I only need it to run once every day. However, the script is failing to replace the existing file - it's not overwriting it. The only way I can get it to overwrite the file is if I change the crontab to: * * * * *
The output logs appear normal, and appears as if the command is being executed normally.
My question is: why would the command not work with this:
03 23 * * *
But * * * * * works - (only once, the file is replaced, but then fails to be updated still).
Thanks.
If the cron job is running on an Amazon EC2 instance, please note that the instances use UTC as their timezone.
So, the crontab is probably working, but you haven't waited until the time that it has actually run. If you leave it alone for 24 hours, you'll probably discover that it did work, but it would have run at 11pm UTC rather than 11pm in your personal timezone.
To fix this, translate your local time into UTC. (There are online tools to assist with this.)

How to fix cron schedule issue?

I tried to run this command manually and working fine
/var/www/html/crm/cron/vtigercron.sh
but when I schedule cron with the below to run automatically nothing happens
* * * * * root /var/www/html/crm/cron/vtigercron.sh
just gives me
Redirecting to /bin/systemctl status crond.service

Crontab visible in logs but still doesn't seem to run?

I'm on an AWS server. I wrote a crontab and placed it on the server under /etc/cron.d. The contents of the crontab are the following:
SHELL=/bin/bash
PATH=/sbin:/bin:usr/sbin:/usr/bin
MAILTO=root
HOME=/
*/5 * * * * root <full-path-to-write-command> >> <full-path-to-txt-output-file>
After running sudo service crond restart, I check the logs by doing sudo tail -f /var/log/cron.
I can observe the cronjob in the logs:
<date-time-stamp> ip-<ip-address> CROND[12930]: (root) CMD (<full-path-to-write-command> >> <full-path-to-txt-output-file>)
However, when I check the <full-path-to-txt-output-file>, I don't see file being written to.
What could be the problem, if I see that the cronjob is executing? Thanks