Cron job Topic is solved

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Godisard

Cron job

Post by Godisard »

Hi,

How do I set up a new cron job? Can I just edit crontab in /etc and add whatever I need (I want to add a weekly job to run the gravity.sh script for pihole)? It seems to work slightly different than in wheezy and before I break anything ...

Thanks
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Cron job

Post by Fourdee »

Godisard wrote:Hi,

How do I set up a new cron job? Can I just edit crontab in /etc and add whatever I need (I want to add a weekly job to run the gravity.sh script for pihole)? It seems to work slightly different than in wheezy and before I break anything ...

Thanks
Hi,

You can setup a simple weekly cron job for this. Please see below for a guide and example on how to set this up:

Create and edit your weekly cron job:

Code: Select all

nano /etc/cron.weekly/my_cron_job
Enter the following into your new cron job:

Code: Select all

#!/bin/bash

#Run Gravity
/usr/local/bin/gravity.sh

#Restart dnsmasq
service dnsmasq restart
Give your cron job execute permissions so it can run:

Code: Select all

chmod +x /etc/cron.weekly/my_cron_job
Test your cron job:

Code: Select all

/etc/cron.weekly/my_cron_job
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
Godisard

Re: Cron job

Post by Godisard »

Yep that works :) . Many thanks!
slook
Posts: 5
Joined: Mon Jan 20, 2020 8:52 pm

Re: Cron job

Post by slook »

i know its super old but still first entry on google search :lol:

i did everything like Fourdee said.
the test worked as well. but the cron job is not executed :/

did anything change?
User avatar
Joulinar
Posts: 2076
Joined: Sat Nov 16, 2019 12:49 am

Re: Cron job

Post by Joulinar »

Hi,
many thanks for your report.

pls can you past the following command

Code: Select all

ls -l /etc/cron.weekly
just replace cron.weekly with the cron folder you used.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
slook
Posts: 5
Joined: Mon Jan 20, 2020 8:52 pm

Re: Cron job

Post by slook »

i will try it later today.
just for the learning curve: what is ls -l doing?
User avatar
Joulinar
Posts: 2076
Joined: Sat Nov 16, 2019 12:49 am

Re: Cron job

Post by Joulinar »

ls is going to show the content of a directory
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
slook
Posts: 5
Joined: Mon Jan 20, 2020 8:52 pm

Re: Cron job

Post by slook »

-rwxr-xr-x 1 root root 1478 Mai 28 2019 apt-compat
-rwxr-xr-x 1 root root 1621 Jan 19 19:54 dietpi
-rwxr-xr-x 1 root root 1187 Apr 19 2019 dpkg
-rwxr-xr-x 1 root root 96 Jan 20 20:56 my_job
-rwxr-xr-x 1 root root 249 Sep 27 2017 passwd
User avatar
Joulinar
Posts: 2076
Joined: Sat Nov 16, 2019 12:49 am

Re: Cron job

Post by Joulinar »

Are you able to show the content of your script?
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
slook
Posts: 5
Joined: Mon Jan 20, 2020 8:52 pm

Re: Cron job

Post by slook »

the script is huge.

if i run /etc/cron.daily/my_job

it works without problems, does cron have logs somewhere?
Post Reply