If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > How to configure crontab

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Feb 2004
Posts: 16
How to configure crontab

Appreciate if you can show me the correct way to configure a cron job in unix. FYI, I need to create a cron job to run a shell script daily and this script must be run by user 'abc'. How can I acheive that?

FYI, I have tried to configure them but it doesn't work. Below is the steps I took:

1. run commad 'crontab -e -u abc'. It gave me 'ed' editor and I totally not familar at all. How can I change to vi editor?

2. Since I cannot write/append a cron job in the crontab file (due to the unfamilarity with ed editor), I cheatly copied 'root' crontab file in /var/spool/cron/crontab folder to a new 'abc' crontab file and removed the entire content and insert a new cron job. I restarted the server and it still didn't run the program. Am I doing the right way?
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: May 2003
Location: France
Posts: 112
Re: How to configure crontab

login as abc

export EDITOR=vi
crontab -e



Quote:
Originally posted by tanboonhoe
Appreciate if you can show me the correct way to configure a cron job in unix. FYI, I need to create a cron job to run a shell script daily and this script must be run by user 'abc'. How can I acheive that?

FYI, I have tried to configure them but it doesn't work. Below is the steps I took:

1. run commad 'crontab -e -u abc'. It gave me 'ed' editor and I totally not familar at all. How can I change to vi editor?

2. Since I cannot write/append a cron job in the crontab file (due to the unfamilarity with ed editor), I cheatly copied 'root' crontab file in /var/spool/cron/crontab folder to a new 'abc' crontab file and removed the entire content and insert a new cron job. I restarted the server and it still didn't run the program. Am I doing the right way?
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 320
You can also do :

Code:
crontab -l > crontab.dat
vi crontab.dat
crontab crontab.dat
same as 'crontab -e', but 3 commands instead of only one ....
__________________
Jean-Pierre.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Feb 2004
Posts: 16
Quote:
Originally posted by aigles
You can also do :

Code:
crontab -l > crontab.dat
vi crontab.dat
crontab crontab.dat
same as 'crontab -e', but 3 commands instead of only one ....
Thanks.. it helps a lot... Cheers
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Apr 2009
Posts: 2
Need help!!!!!!!!!!!!

Hi,

I am extremely new to Crontab stuffs. The problem i am facing is i need to run a shell script every 15 minutes by itself.

I need to use crontab to accomplish the task. I tried to use the above steps but the message i am getting is " cannot create mycrontab".

Consider me as a layman in this crontab technology and please let me know the steps i can follow to solve the problem.

Thanks in advance.
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,721
"man crontab" didn't help you?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
Join Date: Apr 2009
Posts: 2
Red face

Quote:
Originally Posted by stolze
"man crontab" didn't help you?
After doing enough RnD on net i have sufficient idea about crontab. My basic problem is how to configure it.

"man crontab" also gave me some idea. The problem is i am not able to open crontab file using crontab -l. I thought of creating a crontab file where i can write down the commands and access my shell script, but when i am trying, its giving cant create. When i am trying to open the crontab , its giving cant open your crontab.

Now i am wondering what shd i do.
Reply With Quote
  #8 (permalink)  
Old
Registered User
 
Join Date: Jun 2009
Location: South Africa
Posts: 33
Quote:
Originally Posted by pkumar5
After doing enough RnD on net i have sufficient idea about crontab. My basic problem is how to configure it.

"man crontab" also gave me some idea. The problem is i am not able to open crontab file using crontab -l.

Now i am wondering what shd i do.
If no valid crontab has been created for the user yet, "crontab -l" has nothing to display. You might have also created the file as root, with the group set as root as well. This means that accessing the file as user 'abc' will not work, as 'abc' might not have permissions to access the file.
Crontab files usually exists with permissions as follow (linux example) :
[root@srvtst ~]# ls -l /var/spool/cron
total 8
-rw------- 1 abc root 1960 Jun 10 2009 abc

Note that the file here belongs to user abc, and group is set as root. File permission is set to 600 (chmod), which is user has rw, no-one else has access.

Either fix the permissions, or possibly delete / rename the crontab file that you created. Log in as the abc user. Ensure you can access the crontab with "crontab -e" and add / edit the intended line(s).
If there is no crontab file, the first -e invocation will create it if you add at least one character/line to the file.

It's always a good idea to add a similar "comments" heading to the file, just for your own reference :
Code:
# Crontab layout :
# The first five fields shall be integer patterns that specify the following:
#  1. Minute [0,59]
#  2. Hour [0,23]
#  3. Day of the month [1,31]
#  4. Month of the year [1,12]
#  5. Day of the week ([0,6] with 0=Sunday)
# Each  of  these  patterns  can be either an asterisk (meaning all valid
# values), an element, or a list of elements separated by commas. An ele-
# ment  shall  be  either  a  number or two numbers separated by a hyphen
# (meaning an inclusive range).

################################################################################
# Run doyourthang.sh script daily at 03:00 on weekdays to "do your thang"
################################################################################
00 03 * * 1-5 /home/abc/scripts/doyourthang.sh > /dev/null 2>&1

#######
# Fin #
#######
Edit: Wanted to add the comment on the " > /dev/null 2>&1" at the end of the crontab line. We always cat unwanted output from crons to /dev/null, so no mails are generated from the crons - in most cases nobody will ever read this. Our scripts do error checking internally, and mails required output to the various admins or groups accordingly.

Last edited by Lerac; 06-22-09 at 12:27.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On