How to create an Automatic Task

I have linux/redhat/apache server and all my stuff is written in php
how can i create an automatic task, for example i have a code
that sends reports to customers.
I want this code to be launched lets say every Monday at 10am.

where can i create this schedule?
Who is Participating?
0renConnect With a Mentor Commented:
to add a task lets say a script called /usr/local/bin/do_something

open crontab by using

crontab -e

to add a task

00 2 * * * /usr/local/bin/do_something

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
use crontab
if crontab -e does not opening any text editor then you must set the environment variable  EDITOR or VISUAL
to do it :
export EDITOR=vi
export EDITOR=/usr/bin/gedit

to view all tasks in crontab run
crontab -l

each user has his own crontab files.

also make sure the file /etc/cron.deny does not contain your username
and if the file /etc/cron.allow exist make sure your name is in it.
if you dont need to allow or deny crontab just remove them both
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

to run a task every monday at 10am
00 10 * * 1 /task/to/run
omarfaridConnect With a Mentor Commented:
to run scripts/tasks on linux, take the following points into consideration

1- make the script executable (use chmod command)
2- set required env. variables since cron will not read the user .profile file
3- refer to files amd commands with full path names e.g. /usr/bin/cp
4- redirect stdin/stdoout/stderr as required

CMDAIAuthor Commented:
Thank's that does it
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.