0

I have a script I want to update every day. So I have to use a crontab. How can I run the script using the Crontab?

UPDATE

i use ubuntu.

script file

Erdem Aydemir
  • 389
  • 1
  • 6
  • 26
  • 1
    write a bash file that runs the query through MongoDB and then schedule the bash (.sh) file in cronjob with crontab. what version of linux are you using and please post your bash file – Jpsh Apr 05 '17 at 18:20
  • 1
    This should resolve your queries. http://stackoverflow.com/questions/19754784/running-a-simple-shell-script-as-a-cronjob – Rahul Apr 05 '17 at 18:24
  • I will examine and try. @RahulLakhanpal – Erdem Aydemir Apr 05 '17 at 18:38
  • Is there a sample created with the MongoDB script you can use as an example? @user3299379 – Erdem Aydemir Apr 05 '17 at 18:48
  • here is an example http://stackoverflow.com/questions/4837673/how-to-execute-mongo-commands-through-shell-scripts. this is a really bad question you have asked as you haven't provided any sample code or even put an example of the query you're trying to run – Jpsh Apr 05 '17 at 18:51
  • i add script file for you @user3299379 – Erdem Aydemir Apr 05 '17 at 19:06

1 Answers1

2

Suppose you want to update using you bash script everyday at 12:15am. Then add an entry into /etc/crontab like this

15 0 * * * /home/your_bash_script.sh

Just for additional information, the time entries in cron are added as

* * * * * * <your-bash-script-path>
| | | | | | 
| | | | | +-- Year              (range: 1900-3000)
| | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23)
+------------ Minute            (range: 0-59)
Rahul
  • 2,580
  • 1
  • 20
  • 24
  • I have no problem for cron. I have a problem creating my bash file only. How to convert any script file to bash? – Erdem Aydemir Apr 05 '17 at 18:56
  • You are using ubuntu, so any file that uses bash commands and has a .sh file extension in the end is a bash script. – Rahul Apr 05 '17 at 18:59