Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi there ,
i assume you have the script ready thats going to accomplish your job. About writing the crontab here is how you do it.
First make sure which user is going to run the cron. login with that users name and password and issue a crontab -l commans .. but since there is no cron running you wont get any crontab listing. For writing the cron issue a crontab -e command. This will open up a editor window very similar to the vi editor environment. I assume you are at ease working with the vi. About crontab -r .... be careful it doesnt issue a warning !!
Every crontab entry is of the following form. There are 5 fields that you need to fill in for running the script. They are ::
(Minutes) (Hours) (Day_Of_Month) (Month) (Day_Of_Week)
These take the form (0-59) (0-23) (1-31) (1-12) (0-6) respectively , thats reasonable as you can set the minute range between 0-59.
For writing the cron :: Issue that crontab -e and u r ready to write.Remember there should always ba space between two fields.
some general examples
0 1 * * 1-5 Path_To_Your_Script/scriptname This will run every Monday-Friday at 1 A.M
0 1 * * 1,3,5 Path_To_Your_Script/scriptname This will run every Monday,Wednesday and Friday at 1 a.m
10 2 1 * * Path_To_Your_Script/scriptname This will run at 2:10 a.m on the first of every month
0 1 1 1 * Path_To_Your_Script/scriptname This will run at 1 a.m on January 1 every year
0/15 * * * * Path_To_Your_Script/scriptname This will run evry 15 minutes every day, every month, evry week , every year
I hope this will help ... do tell me if it works .. All the Best
Shaheen
thanks shaheen it worked ..
but there is one little problem .. this is wrtten in my \etc\crontab file in the beginning
mailto = user
now wht it does is it mails the result to the user ...like forexample i was running a ls command in the script and it mailed all the list to the user . i want the list to be shown on the terminal when the script runs ..
Originally posted by usman thanks shaheen it worked ..
but there is one little problem .. this is wrtten in my \etc\crontab file in the beginning
mailto = user
now wht it does is it mails the result to the user ...like forexample i was running a ls command in the script and it mailed all the list to the user . i want the list to be shown on the terminal when the script runs ..
If you want something outputed to console windows then you probably want to use wall. cron will not put anything on the console by default kind of like when you do a ls in one window it doesn't put it in every window. (unless you do a ls | wall )
oh .. o k . i get it .. thanks for the help .. i thought that when the cronjob runs its suppose to show wht going on the screen .. or show my some message that the job has been performed automatically ..
wht do i have to do to get notified when a certain job runs ?
hi,
about that mailto user problem , u can change the mailto=user to mailto=root , the mail will be delivered to you , not individual users , or if you dont want to use that just hash it out , wont be a problem anymore , cron doesnot display any messages in the screen , it just performs the job it has been assigned to , its the script that will print out the output , like an ls command .... so try editing the script ..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.