Using cron Chef cookbook to run a command every 30 mins - cron

I am using the cron cookbook to run every 30 minutes in the following way:
cron_d 'logrotate_check' do
minute "*/30"
command "logrotate -s /var/log/logstatus /etc/logrotate.d/consul_logs"
user 'root'
end
Please let me know if it is correct?

Yes, that is fine. In the future, please just try it yourself rather than asking the internet and waiting 10 hours.

Related

Wget Timeout if download takes too long

Is there any way to stop awgetdownload if the download is not completed in x seconds?
For example if in 2 seconds the download is not complete, to get a timeout?
wget has following timeout related options
--timeout=seconds
--dns-timeout=seconds
--connect-timeout=seconds
--read-timeout=seconds
see linked man page for explanation.
Is there any way to stop awgetdownload if the download is not
completed in x seconds?
You might find timeout command useful, it does kill provided command if it does not end in given amount of seconds. For example
timeout 5 wget https://www.example.com
does give 5 seconds wget to download example and if it fails to do kill it. Note that timeout command might be used with other commands that wget.

What is wrong with this cron job?

03 20 * * * do_snapshot --digital-ocean-access-token notreallymyaccesstoken96notreallymyaccesstoken3 --only 52713483 -k 3 -c -v
Running do_snapshot to take snapshot of my digital ocean droplet. I am able to do this manually via this command
do_snapshot --digital-ocean-access-token notreallymyaccesstoken96notreallymyaccesstoken3 --only 52713483 -k 3 -c -v
This works perfectly well and takes a snapshot of my droplet. However when i try to run cron job of the same - I fix time 2-3-5 mins ahead and save the cron job. But nothing happens. Been stuck on this for too long - I tried to read about cron job - and followed this tutorial word to word too
I am still not able to figure out what am I doing wrong?
Well no error in cron job script - it was difference in timezone as pointed out by #parttimeturtle. Also checking logs also helped, thank you both. This was really informative.

Crontab reboot job reboot multiple times instead of once

I am trying to schedule my debian jessie machine to shutdown at 9:00 p.m. every 3 days. I currently use a cronjob:
00 21 */3 * * root bash /home/pi/scripts/reboot.sh
where reboot.sh is:
sudo reboot
The machine shuts down on schedule but what is strange is that it just keeps rebooting for several times. how am I able to get rid of this issue. is this related to maybe the RTC clock no have enough time to update itself and so the cron job still thinks the time is still 9... I really doubt this.. any help
its better to use the internal command shutdown instead of using the script. shutdown now shuts the computer and -r flag is for reboot system. you can also pass specific time instead of now like shutdown -r 11:00.
For now you can use
shutdown -r now

Long running service check in Nagios

I have a service check that I've found on the Nagios Exchange site which works well for small directories, but not well for larger ones that take longer than 30 or 60 seconds to complete.
http://exchange.nagios.org/directory/Plugins/Uncategorized/Operating-Systems/Linux/CheckDirSize/details
The problem I'm having is that I need to configure a service check that Nagios can run once a day but will remain open for 1440 minutes (one day). The directory listing is huge and takes many hours to complete (up to 20 hours).
This is my service check (check every day, when using nrpe, the timeout is 86400 seconds which is also one day). But for some reason, even though I can see the du -sk running on the command line in ps -ef | grep du, Nagios is reporting "(Service Check Timed Out)":
define service {
use generic-service,srv-pnp
host_name IMAGEServer1
service_description Images
check_command check_nrpe!check_dirsize -t 86400
check_interval 1440
}
In my nrpe.cfg file on the linux server i have these two directives as well:
command_timeout=86400
connection_timeout=86400
How can I get Nagios to complete the check and not time out? I was under the impression that my directives above were correct.
What's timing out is the check_nrpe command on the local side (it has a default timeout of 2 minutes). You could edit its command definition to use a long timeout.
Alternatively, you might want to do this as a passive check on IMAGEServer1, running as a cron job.

About system time in a bash script

I'm starting work on a bash script that will shutdown my computer at a certain time of day, but I'm not really sure what all specifically needs to go into that. Could someone post an example of how they would do it?
If you want to shut down at 22:15 every day, be root, run crontab -e, then add
15 22 * * * shutdown -h 5
on a line by itself.
Then save. At 22:15 every day, you will get a warning that the system will shut down in 5 minutes, and five minutes later, true to its word, it shuts down. If you want to abort the shutdown, run shutdown -c as root after the warning.

Resources