Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a shell script everyday at specific time [duplicate]

I have a simple shell script that just checks the contents of a directory and if anything was added during the day makes a copy of it to a backup folder. I'd like to execute this script at the end of each day (let's assume at 23:55).

The system(Debian) which this scripts reside on it, is always on (kind of server)

How can I do that?

like image 833
Sina Sh Avatar asked Jan 12 '16 21:01

Sina Sh


People also ask

What should I do to run a script on specific time without cron?

If not using cron, you will have to arrange for the script to re-execute itself at a particular time in the future, maybe using at (which is part of cron), or by sleeping (which would make the executions drift over time), and you would additionally have to set up an initial execution of the script at reboots (again, ...

How do I run a shell script multiple times?

How To Run a Command Multiple Times in Bash. Wrap your statement for i in {1..n}; do someCommand; done , where n is a positive number and someCommand is any command. To access the variable (I use i but you can name it differently), you need to wrap it like this: ${i} . Execute the statement by pressing the Enter key.


1 Answers

To add a crontab job, type the following command at a UNIX/Linux shell prompt:

$ sudo crontab -e 

Add the following line:

1 2 3 4 5 /path/to/script 

where

1: Minutes (0-59) 2: Hours (0-23) 3: Days (1-31) 4: Month (1-12) 5: Day of the week(1-7) /path/to/script - your own shell script 

In your case it would be:

55 23 * * * /path/to/yourShellScript 
like image 132
Kurt Van den Branden Avatar answered Oct 11 '22 13:10

Kurt Van den Branden