DEV Community

laidah
laidah

Posted on

2 1

Crontab

Today I stumbled upon a flaky test. It's been bothering our developers for some time already, but usually, it took about two runs to have it turn green. So no big deal for them.
But it is for me.

As soon as I've opened it, I realized that this test is about cron jobs. And I know almost nothing about cron.
No worries! 10 minutes of intense googling and I am ready to tackle it.

Cron (Command Run ON) - is a program in Unix-based systems that can run scripts and tasks at specific time and order.

For example, you download a lot of cat pictures, videos, and memes every day, and o-oh! Your disk space is running low, there is no place to store your work files.
Have no fear! You can schedule crone to delete pictures and videos from download folder once a week.
Prepare your bash script:

cd /users/user_name/Downloads
find . -type f \( -name \*jpg -o -name \*png -o -name \*gif -o -name \*mp4 \) -delete
Enter fullscreen mode Exit fullscreen mode

Save it to file , for ex clean_dowloads.sh

Now open your terminal and write:
crontab -e
This will open a text redactor where you can write your task:

# Every Sunday at 00:00 run bash script clean_downloads.sh
@weekly bash /home/www/clean_dowloads.sh
Enter fullscreen mode Exit fullscreen mode

Save and exit. Now you are all set up, no more worries about too many cat pics.
Cron can schedule jobs using different time parameters:

# at every minute
* * * * *  <command>

# at 02:00 on Friday in July
0 2 * 7 5  <command>

# every 15 minutes after 2:00
*/15 2 * * * <command>
Enter fullscreen mode Exit fullscreen mode

Use Crontab.gury for easy planning.

And I should go back to my flaky test.
┐( ̄∀ ̄)┌

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
pramon18 profile image
pramon18

Simple and really helpful. Good article.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay