Creating Cronjob using .sh file


 
Thread Tools Search this Thread
Operating Systems Solaris Creating Cronjob using .sh file
# 1  
Old 09-24-2010
Creating Cronjob using .sh file

Hi all,

I have created .sh file which contains oracle's export command to export the tables for backup.

Also, used crontab for scheduling the above.

currently, cronjob is defined manually using crontab -e command from the root user, but
want to know how to write a shell script which on running by the support team will schedule the cronjob automatically.?


thanks
# 2  
Old 09-24-2010
I guess crontab is just like any other normal file so you should be able to edit it from other scripts without any issues.
# 3  
Old 09-24-2010
It's not that simple, because cron would not know about the changed file. You have to use the crontab command to change the crontab file and signal cron to reread the file. The crontab command reads $EDITOR to find out, which editor to start to edit a temporary copy of the crontab file. If the editor exits with exit code 0, the temporary copy is used to overwrite the real crontab file and cron is signalled to reread it.

This can be used to call a shellscript to modify the temporary copy, let's say to add a new entry.

First you need a shellscript like this (the name of the temporary file is passed as argument):

Code:
#!/bin/ksh
print "0 0 * * 0 echo Hello world" >>$1

Save this script as change_crontab.sh and execute it:

Code:
$ crontab -l
# my crontab
$ EDITOR=./change_crontab.sh crontab -e
$ crontab -l
# my crontab
0 0 * * 0 echo Hello world

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Cronjob output to file AND to email (as attachment)

I have a shell script that runs on our webserver logs, and grabs various useful data and then outputs this data to a .csv file. What I want to do now is schedule a cronjob to run this script for me each week at a designated time, AND email the .csv file that is created as an attachment to... (1 Reply)
Discussion started by: xdawg
1 Replies

2. Shell Programming and Scripting

Cronjob script not renaming file

Hello, I have below script, which connects to ftp server, pull a file and then it renames it after deleting previous day file. This was working before but now it is not able to rename 'Red_bill.txt' to `Red_bill.V01.txt`. If I run manually 'rename Red_bill.txt Red_bill.V01.txt', I am able to... (5 Replies)
Discussion started by: solaris_1977
5 Replies

3. UNIX for Dummies Questions & Answers

Creating cronjob

Guys I am a complete newbie to UNIX and I need some help. My team has taken on support of a very old UNIX box which is running version 2.4.21. I need to create an urgent cronjob to restart the sladp process every sunday at 1am. This is to to provide a temp fix to a production issue. Problem I... (1 Reply)
Discussion started by: strawdogz
1 Replies

4. UNIX for Dummies Questions & Answers

How to Update DB table from txt file using CRONJOB in Unix Shell Script

Hi Experts, can guide how we can Update a Database Table using a txt file source Using Unix Shell Scripts. What are the Cron Jobs codes can written to Update DB table. txt file contains record like data. US 09/03/2012 User DocType DocID. these above feilds in txt files need to be updated in... (4 Replies)
Discussion started by: mahesh.sap
4 Replies

5. UNIX for Dummies Questions & Answers

Run a cronjob only when a file is modified?

Hello, I am new to cron. I have a cronjob that updates a dataset in a 3rd party application. The contents of this dataset come from a text file, which is updated irregularly. Currently my cronjob runs once every week, to update this dataset (irrespective of whether the file was updated or not).... (7 Replies)
Discussion started by: ad23
7 Replies

6. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

7. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

8. Shell Programming and Scripting

Check a condition in cronjob to execute a sh file

Hi, I need to execute a crontab based on a condition where one SH file should be executed only based on the output of a file in a folder. I have written the following cron job which is not working. 00 01 * * * read a < /px/batch/reslut.txt && && sh /px/batch/check.sh where my... (2 Replies)
Discussion started by: shanth_chandra
2 Replies

9. Solaris

Creating a CronJob Script

Hi All, Good Day. Anyone can guide me on how to create a cronjob script that run prstat -a and vmstat 10 10 on the certain time of the day and produce a log which will be kept in a specific directory? I am running on Solaris 10. Thanks. (2 Replies)
Discussion started by: ronny_nch
2 Replies

10. Shell Programming and Scripting

Cronjob - Redirect mail output to file, LINES & COLUMNS

I currently have an expect script that issues the 'mail' command and sends an 'x' when it receives the & prompt from mail to quit. The expect script is able to do stty rows 100 columns 200 < $spawn_out(slave,name) to set up the number of columns and rows. I would like to get rid of the expect... (0 Replies)
Discussion started by: jharvey
0 Replies
Login or Register to Ask a Question