I have a cron job to execute a file upload to GCP storage. I am able to run the script is working fine.
When I changed it to a cron job it stops working.
*/5 * * * * (eval mydate=`date +\%m\%d\%Y` ; /home/script/uploadFile.sh dev | tee -a /home/script/upload_log_$mydate)
It is creating an empty log file and file upload is not happening.
Related
I am deploying a cron file abcd.cron in /etc/cron.d/ location during EC2 bootstrap time using Cloudformation user-data(Uses clod-init). This is not triggering the execution(Checked /var/log/cron log file) unless I modify the cron file /etc/cron.d/abcd.cron (updating time). I tried to restart crond service in the cloud-init section after cron file copy, but that didn't help.
Is there a way to fix this issue during bootstrap time without manual modification ?
Try like this in your CloudFormation:
crontab -l > /tmp/mycrontab
echo '0 * * * * ls -la' >> /tmp/mycrontab
crontab /tmp/mycrontab
I have created one command which will add some record to mysql database.
When I execute command with terminal, command is adding data to database.
Then I have modified Kernel.php, added command in commands array and scheduled task as below.
protected $commands = [
\App\Console\Commands\AddData::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('word:add')->everyMinute();
}
I have setup cron job in CPanel.
Command Setting : Once per minute.
Command added as :
/usr/local/bin/php /home/username/public_html/sitename/projectPath &&
php artisan schedule:run >> /dev/null 2>&1
But it is not working - i.e. not adding row to database table neither I am getting any error from in CPanel for cron job. am I missing anything or I am doing something wrong with it?
I have figure out the problem.
for this case, we need to give path of artisan file, so the command would be
* * * * * /usr/local/bin/php /home/username/public_html/sitename/projectPath/artisan schedule:run >> /dev/null 2>&1
I have a cron job that runs the script every 30 minutes. The problem is each time it runs the cron it creates a file in the root directory. It'll create files like this:
wp-cron.php?doing_wp_cron.1
wp-cron.php?doing_wp_cron.2
wp-cron.php?doing_wp_cron.3
This is my cron:
*/30 * * * * wget http://yourdomain.com/wp-cron.php?doing_wp_cron 2>&1 > /dev/null
How can I make it auto delete after it finishes running the cron job or make it not create the file?
wget primarily is for downloading files, it might be better to use curl
curl http://yourdomain.com/wp-cron.php?doing_wp_cron
I have a script abc.sh which runs a command to generate a csv file and send an email. This script runs fine when I manually execute it.
I have added the following entry to my crontab using crontab -e command:
00 18 * * * /home/abc.sh
However, this cron job does not execute at all.
I checked
service crond status
and the CRON service is running.
Am I missing some permissions?
I have build a bash script that gets .tar.gz files from IMDb and writes to a log file, the script works when run on its own as I can see the folder with the files present, but when I run the script via cron it doesn't work. Would this be due to permissions? I have edited the sudo crontab file, but I'm not sure what else I need to do.
Try this solution:
Cronjob is a file that contains your job:
cat cronjob
* * * * * bash /path/to/script.sh >> /path/to/log.txt
Then you should set executable permission and start cron service:
chmod +x cronjob
/etc/init.d/crond start #redhat based servers like centos
/etc/init.d/cron start #debian based servers like ubuntu
After that you should tell cron service to run cronjob file:
crontab cronjob
Your script should download a file.
If your script doesn't run you should run it from good path[full path], so your cronjob file would be something like this:
* * * * * /bin/bash /path/to/script.sh >> /path/to/log.txt