Amazon auto start Server via cronjob - shell

I have created a cron job to start and stop instance at particular times.
I have set up amazon APIs against user ubuntu. saved script start.sh in home folder
#!/bin/bash
ec2-start-instances i-instanceID
I placed the job in cron tab.
0 18 * * 5 /home/ubuntu/scripts/dev/stop.sh
The script is exicuiting on specific times but the instances are not stopping/starting.
Can anyone suggest a way out.
I also tried setting up the same job in root user that also failed

You need to define which binary is executing the script. Hence, try with this:
0 18 * * 5 /bin/bash /home/ubuntu/scripts/dev/stop.sh
^^^^^^^^^

Related

How to create cron job to run shell script every minute

I wan to create cron job that runs a shell script every minute I've tried editing contrab -e with:
1 * * * * sh ~/test.sh
to no avail
I recommend using: https://crontab.guru/
This is a really insightful way to create and understand cron jobs.
This should trigger every minute. However, when a cron runs it can run as a different user and that script location might be different. Adding a log file might help you track down what is going on.
* * * * * /bin/sh /home/user/test.sh >> /var/log/myjob.log 2>&1

How to write shell script to restart tomcat7 automatically using cron?

I am very new to shell script,in my company i need restart all application servers in production at or before 12.30 pm everyday.can i automate this process by shell script also will it affect any other application running on the server.
Thanks in Advance
At last i found answer to restart tomcat automatically by writing a simple script and setting-up that script on cron whatever time sequence i need restart application server.
Script
#! /bin/sh
SERVICE=/etc/init.d/tomcat7
$SERVICE restart
Cron job
30 12 * * * /root/restarttomacat.sh
It wont affect any other applications.

Magento Cron not working: no heartbeat task

I noticed the cron jobs not working because some tasks were not performed (automatic feed generation, google sitemap, ...).
1) I installed the (very useful) AOE scheduler
2) I've checked cron_schedule SQL table via PHPmyAdmin: no task is generated, but if I press Generate schedule in AOE scheduler, a list of task is generated. All tasks remain in pending status (executed at NULL).
3) I've set (crontab -e)
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/fpl/webapps/magento/cron.sh
I've tried to run cron.sh manually via SSH. When I run manually the sh the heartbeat task is run. So I'm also sure the problem is not in the cron.sh script.
Cron is properly running on the server.
Configuration
Webfaction hosting
Magento ver. 1.8.0.0
Cron schedule Configuration on magento admin panel
Generate Schedules Every 1
Schedule Ahead for 20
Missed if Not Run Within 15
Heartbeat task schedule (cron syntax) 0,5,10,15,20,25,30,35,40,45,50,55 * * * *
Thanks for your help!
my guess is that your cron.sh is not executable and that's why nothing is happening.
Please check the file persmission and add the executable flag
chmod +x /home/fpl/webapps/magento/cron.sh
You might also want to check your server's log files for cron (e.g. https://askubuntu.com/questions/56683/where-is-the-cron-crontab-log)
Instead of relying on the fact that cron is executable you could also run it like this
/bin/bash /home/fpl/webapps/magento/cron.sh
And: instead of writing down the minutes like that you should be using this:
*/5 * * * * /bin/bash /home/fpl/webapps/magento/cron.sh
Did you check the status for crontab?
service crond status // depends on your OS
If its not running, start it
service crond start
And configure for system startup
chkconfig crond on
HTH
Good luck!
edit cron.sh and change line 39 to:
PHP_BIN=`/usr/local/bin/php56`
It tries to use which php but that isn't so great on webfaction servers as there are lots of php versions.
Adding
crontab -e */5 * * * * /usr/bin/wget -O /dev/null -q http://www.partsfortreadmill.com/cron.php
and setting a proper cron.php in the above path

Cronjob won't run 80% of the time

I have a raspberrypi setup with emulation station and retropie. I have a cronjob set up so I can send myself an email at 8am everyday written in ruby. This script has worked effectively 100% when I first set it up but ever sice I upgraded my raspberrypi to the newest version of retropie and emulationstation, the cronjob has stopped work 80% of the time.
0 8 * * * ruby /home/pi/Facebook/facebook.rb
Is what it is currently. It worked yesterday.
I've tried these methods as well:
0 8 * * * 'ruby /home/pi/Facebook/facebook.rb'
0 8 * * * /bin/bash ruby /home/pi/Facebook/facebook.rb
0 8 * * * /bin/bash 'ruby /home/pi/Facebook/facebook.rb'
0 8 * * * /bin/bash -l -c 'ruby /home/pi/Facebook/facebook.rb'
I am not sure what the -l and -c is supposed to mean. However this one worked all the time when I had it set up before upgrading. Is the pi skipping the job at 8am or doing another job at that time which causes it to miss it? Or is it my script which may take forever to send the email via ruby to my gmail account?
Usually cron sends a error mail to the owner of the crontab, so check that owner's emails on that machine.
It is most likely a problem with the cron environment. Cron uses its own environment when starting jobs.
It sounds like the cron job is running your script, but your script may be erroring-out or timing out. You might want to add some logging to your script, so you can see where the problem is.

shell script as cron job

Several people have had this problem, but none of the fixes mentioned around the net have worked for me.
I have a simple shell script that copies log files from a few directories, and puts them in one single directory on a remote machine. The script works fine.
I then create a cronjob, which doesnt seem to execute. My crontab looks like:
1 * * * * /bin/bash /home/user/myscripts/getlogs.sh > /tmp/cronscript.out 2>&1
/var/log/cron shows this every minute
Aug 20 17:02:01 hostname crond[2614]: (root) RELOAD (/var/spool/cron/root)
so it cron job executes, but it doesnt seem to run the shell script.

Resources