Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

You install oracle database but need to shutdown at night every Friday at 10pm so that you can make backups. How would you achieve this automatically using the crontab utility? Assume that the script that shutdown and backups the database in called backup.sh and located in /opt/scripts

share|improve this question

2 Answers 2

Back up /etc/crontab and then edit it to add this line:

0 22 * * 5 root /opt/scripts/backup.sh

(This assumes the script has execute permissions. If not, then put sh in front of the command.)

If the script is to be run by some user other than root, replace root with the appropriate username.

By the way, I highly recommend man 5 crontab, which documents the full format for crontabs. (Also available online.)

share|improve this answer
Great...this is awesome..Now which utility can i use to backup my Linux PC once only. assuming that the script to run in is /opt/script/once.sh? –  Lukesh Nov 14 '11 at 12:35
Depending on when you want it to happen, you might just run the script (/opt/script/once.sh or sh /opt/script/once.sh, or with sudo if it needs to run as root: sudo /opt/script/once.sh or sudo sh /opt/script/once.sh), or you might schedule it with the at command if you want it to run at a single particular date/time later (echo /opt/script/once.sh | at now + 10 3 days or, to give an example with sudo and where once.sh is non-executable: echo sh /opt/script/once.sh | sudo at 11pm). –  Eliah Kagan Nov 14 '11 at 17:36
But that sounds like a separate question; if you want more information about running scripts or scheduling actions to occur at a single specific date/time, I recommend posting a new question. –  Eliah Kagan Nov 14 '11 at 17:38

Open your crontab with crontab -e. If it's your first time, you'll be presented with a list of editors to choose from.

Now add this line to your crontab file

0 22 * * 5 sh /opt/scripts/backup.sh

save and close.

share|improve this answer
This is for a system administration task, so the user crontab is probably not the most appropriate way to achieve this. (The script likely has to run either as root or as a user that cannot actually log in, but exists only for running the database. In the former case, this must be the systemwide crontab or--much less preferably--the root user's per-user crontab. In the latter case, the special database user likely doesn't have the ability to schedule tasks via cron.) –  Eliah Kagan Nov 13 '11 at 17:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.