Sponsored Content
Top Forums Shell Programming and Scripting How to schedule a shell script in Linux centos? Post 302898034 by Palak Sharma on Friday 18th of April 2014 01:52:07 AM
Old 04-18-2014
How to schedule a shell script in Linux centos?

Hi All,

I have a script that I need to schedule on daily basis. How can I schedule a script in centos. Like I want to run that script evryday at 10 AM and can I store the output of the script in a log file.


Thanks

---------- Post updated 04-18-14 at 12:52 AM ---------- Previous update was 04-17-14 at 11:23 PM ----------

To schedule a script, you'll need to use crontab. You can add a schedule entry by doing:

Code:
crontab -e

Once you are inside, the cron accepts pattern in the form:

Code:
<Minute> <Hour> <Day> <Month> <Day of Week> <Command>

So a correct crontab entry for 10am would be

Code:
0 10 * * * /path/to/script

If you want to capture the output you can specify the logfile inside cron like
0 10 * * * /path/to/script > /path/to/log/output.log

Just ensure you put a she-bang header in your script. Alternatively, you can specify the shell interpreter inside cron by saying:

Code:
0 10 * * * bash /path/to/script > /path/to/log/output.log

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Schedule an interactive shell script

Hi, I need to schedule a shell script which executes another shell script along with a series of other commands. When the inner shell script is executed it prompts for a password..... This inner shell cannot be changed How can I do this???? Regards, Chaitrali. (4 Replies)
Discussion started by: Chaitrali
4 Replies

2. Shell Programming and Scripting

How to schedule a job in shell scripting.

Hi all I have made a shell script to check jobs' status and send an alert based on the result. I want to run this script to run every 4 hours and I don't have access to cron. Can we schedule using shell scripting instead of cron facility? (2 Replies)
Discussion started by: johnl
2 Replies

3. Shell Programming and Scripting

General Q: how to run/schedule a php script from cron jobs maybe via bash from shell?

Status quo is, within a web application, which is coded completely in php (not by me, I dont know php), I have to fill out several fields, and execute it manually by clicking the "go" button in my browser, several times a day. Thats because: The script itself pulls data (textfiles) from a... (3 Replies)
Discussion started by: lowmaster
3 Replies

4. Linux

LINUX Cron Schedule - Newline character issue

we have one simple script that works fine as expected while running it manually. However, it does not work the way it should be when scheduled through CRON. Script: a="Perform" b="Test" output="$a\n$b\n" echo "$output" while executing the above script, it should print the values of a and b... (2 Replies)
Discussion started by: jansat
2 Replies

5. Shell Programming and Scripting

Shell script to schedule jobs

Dear all, I have to create a shell script which will run the job during weekday/weekend in following manner: - There are 3 jobs JB_1 JB_2 JB_3 These jobs changes its flag to "COMPLETED" in below 2 ways 1. These 3 jobs which runs after the completion of previous one i.e JB_1 runs and... (5 Replies)
Discussion started by: prajaktaraut
5 Replies

6. Shell Programming and Scripting

Schedule tasks in shell script

shell=ksh, How could I schedule tasks in shell script INSTEAD OF using the crontab -e functionality? For example, I want a script to print "Hello World" every 10 seconds (i.e., INTERVAL = 10s) until external termination signal is triggered. Thanks, (2 Replies)
Discussion started by: isaacniu
2 Replies

7. Shell Programming and Scripting

Schedule and Run By weekly shell script in cronjob

Hi All, How to schedule a shell script(script name- byweeklyreport.sh) it should run by weekly in corn job or is there any script have to write to check week and then run the above script. example-1st run March 06 2013 2nd run March 20 2013 3rd run April 3 2013... (13 Replies)
Discussion started by: krupasindhu18
13 Replies

8. Shell Programming and Scripting

Want to Schedule Shell Script on AIX

Hi All, I want to schedule a shell script on AIX. But Crontab is not working in my AIX Server.Is there any alternative? Please Suggest.. (2 Replies)
Discussion started by: bharat1211
2 Replies

9. Shell Programming and Scripting

Schedule a shell script without crontab every Wednesday at 10 AM

HI Guys I need one shell script to be scheduled to run one shell script to be executed automatically every Wednesday at 10 AM Without crontab and "at" command.. Could you provide your suggestions ? Thanks and Regards kshitij Kulshreshtha (6 Replies)
Discussion started by: kshitij
6 Replies

10. Cybersecurity

Is there an Automated script for CIS CentOS Linux 7 Benchmark please?

Hi, Apologies if this is not right section to post my requirement. We have a requirement to enhance our Centos 7 Servers' security as per "CIS CentOS Linux 7 Benchmark" ( CIS WorkBench / Home ) that provides guidance for establishing a secure configuration posture for CentOS 7. Just... (2 Replies)
Discussion started by: prvnrk
2 Replies
cron(8) 						      System Manager's Manual							   cron(8)

NAME
cron - The system clock daemon SYNOPSIS
/usr/sbin/cron DESCRIPTION
The cron daemon runs shell commands at specified dates and times. Commands that are to run according to a regular or periodic schedule are found within the crontab files. Commands that are to run once only are found within the at files. You submit crontab and at file entries by using the crontab and at commands. Because the cron process exits only when killed or when the system stops, only one cron daemon should exist on the system at any given time. Normally, you start the cron daemon from within a run command file. During process initialization and when cron detects a change, it examines the crontab and at files. This strategy reduces the overhead of checking for new or changed files at regularly scheduled intervals. The cron command creates a log of its activities. The cron daemon must be started from the system startup scripts because it must begin execution without a login user ID set. The cron daemon starts each job with the following process attributes stored with the job by the invoking process: Login user ID Effective and real user IDs Effective and real group IDs Supplementary groups It also establishes the following attributes from the authentication profile of the account associated with the login user ID of the invok- ing process: Audit control and disposition masks Kernel authorizations DIAGNOSTICS
The at and batch programs will refuse to accept jobs submitted from processes whose login user ID is different from the real user ID. FILES
Specifies the command path. Main cron directory Directory containing the crontab files. List of allowed users. List of denied users His- tory information for cron Queue description file for at, batch, and cron RELATED INFORMATION
Commands: at(1), crontab(1), rc0(8), rc2(8), rc3(8) Files: queuedefs(4) delim off cron(8)
All times are GMT -4. The time now is 06:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy