1834149 Members
2491 Online
110064 Solutions
New Discussion

crontab

 
SOLVED
Go to solution
sam kim_1
Frequent Advisor

crontab

i just typed as:

#./crontab -l
[result is: /sbin/sh: ./crontab: not found.]

what's wrong!?

i am trying to create crontab.
how to create a crontab ??
very step-by-step pls!!!
57 REPLIES 57
Victor BERRIDGE
Honored Contributor

Re: crontab

Hi Sam
Create your cronfile
and then to activate crontab cronfile
crontab -l will display what scheduled
crontab -r will remove
crontab -e if you wish to modify (I prefer editing cronfile..)
Regards
Victor
John Palmer
Honored Contributor

Re: crontab

Because you typed './crontab', the shell is looking in the current directory for the crontab command.

Just try 'crontab -l' to list your current crontab.

To create a crontab, use your favourite editor to create a file containing your cron information. (see the man pages for crontab and cron). Then just type 'crontab '.

You can also use the 'crontab -e' command to edit the current crontab file.

cron keeps crontab files in the directory
/usr/spool/cron/crontabs.

It is worth having a set procedure for editing crontab files, saving the previous version is a good idea.

Regards,
John
Rita C Workman
Honored Contributor

Re: crontab

To create a crontab file....(I store mine under /var/spool/cron/crontabs..)
You would enter:
crontab -e (you can now key the when/what you want to run)
Quick example:

00 1 * * 1,2,3,4,5 /usr/local/bin/startup_oracle.sh

This would kick off the job startup_oracle.sh at 1 minute past midnight every Monday-Friday.

Then save the file. And run:
crontab 'your_new_file' to start your file to run.

To display what is set to run/cron:
crontab -l
To start or run the cronfile
crontab /full_path/cronfile_name

Hope this helps,
Antoanetta Naghiu
Esteemed Contributor
Solution

Re: crontab

cd /var/spool/cron
ls -al crontab.root (if exists, go to the next)
cd crontabs
cp /var/spool/cron/crontab.root /var/spool/cron/crontabs/root
(copy the crontab.root example file one lever down in crontabs directory with the name as root.
vi root
add your modifications.
/sbin/init.d/cron stop
/sbin/init.d/cron start
crontab -l
That's it.
sam kim_1
Frequent Advisor

Re: crontab

i logged in this server as root.

And, what i did:
# cd /var/spool/cron/crontabs
# ls
[result : there is nothing]

this means there is no user ???

1)as far as know, in order to use 'crontab' command, i have to know username, is that right??
2)in order to check username, i can check from #cd /vsr/spool/cron/crontabs then #ls,
is that right??
3)once i know the username, then i can do
# ./crontab -l username,
is that right???

pls, give a clue, thanks!
Victor BERRIDGE
Honored Contributor

Re: crontab

Well if /var/spool/cron/crontabs is empty , then you have no cron running Its time to create one...
Good luck
Antoanetta Naghiu
Esteemed Contributor

Re: crontab

If you want to create a cron tab for different user then root (let's say oracle), under /var/spool/cron/crontabs, create a file with that user's name ( vi oracle). Record the info, chown oracle:dba oracle, chomd 444 *, stop and restart the cron (see my previous post).
Abd do not forget to go to
cd /var/adm/cron
vi cron.allow
add the user name (you'll have
root
oracle
..
Rick Garland
Honored Contributor

Re: crontab

crontab entries can be for the individual users as well. Can do a
find / -name cron.allow -print to see which users have acess to the cron facilities. If there are users in the cron.allow these users will be allowed to make-modify their own cron entries.

In the same directory as the cron.allow is a cron.deny file. Users in this file do not have access to the cron facilities.

To create/modify cron entries, can use the 'crontab -e' command. This will place you in the crontab file for that particular user. Typically the EDITOR is vi so editing is done via the vi commands. Doing a :wq at the end of modifications will write the crontab file and the will be a message that states the cron will be using /bin/sh (something to that effect.)

Doing the modifications directly to the crontab files requires that the cron process be killed and restarted so that the modifications will be re-read. The 'crontab -e' command will automatically re-read the crontab file without having to bounce the cron process.
Antoanetta Naghiu
Esteemed Contributor

Re: crontab

Sam, go just to /var/spool/cron and copy crontab.root there (see above)
sam kim_1
Frequent Advisor

Re: crontab

i just did:

# cd /var/spool/cron
# ls -al crontab.root
# cd crontabs
# cp /var/spool/cron/crontab.root
/var/spool/cron/crontabs/root
# vi root

[here i met an obtacle. how to add
modifications??]
--------------------------------------

my current screen (after 'vi root') is like:

# @(#) $Rivision: 72.1 $
#
# This is a sample crontab file for the super-user.
#
# log kernel diagnostic messages every ....
# sample nightly ......
# just uncomment .....
#0 4 *** exec /usr/bin/calendar -
~
~
~
......

------------------------------
if i can add modifications successfully, then i have to do this:

# /sbin/init.d/cron stop
# /sbin/init.d/cron start
# crontab -l

is that right??



Rita C Workman
Honored Contributor

Re: crontab

After you do your modifications and save your new file...you called root.
Just enter:
crontab root

This kicks off the root file to run at the times scheduled within your 'root' cronfile.

You do not run cron stop or cron start.....the command crontab will execute the file you specify.

Regards,
Rita C Workman
Honored Contributor

Re: crontab

...ps....plenty of folks have given great answers here..please don't forget to give them some points..

Tx,
Rick Garland
Honored Contributor

Re: crontab

If you vi the crontab, first and formost, make a copy of the file. 'cp crontab crontab.mine'.

Next, if you editing the file with vi, the command to make a new line (below the cursor)
is the letter 'o'.
sam kim_1
Frequent Advisor

Re: crontab

thanks again!
however, my current screen after '#vi root'
is:

my current screen (after 'vi root') is like:

-------------------------------
# @(#) $Rivision: 72.1 $
#
# This is a sample crontab file for the super-user.
#
# log kernel diagnostic messages every ....
# sample nightly ......
# just uncomment .....
#0 4 *** exec /usr/bin/calendar -
~
~
~
"root" [Read Only] 11 lines, 342 characters
-------------------------------------

from this screen,
what do i have to add/modify ???
(for instance,
do i have to add something like this??)

====================================

# @(#) $Rivision: 72.1 $
#
# This is a sample crontab file for the super-user.
#
# log kernel diagnostic messages every ....
# sample nightly ......
# just uncomment .....
#0 4 *** exec /usr/bin/calendar -
root, oracle
~
~
====================================
Rick Garland
Honored Contributor

Re: crontab

The entries in the cron are as follows:
minute hour day-of-month month-of-year day-of-week
minute 0-59
hour 0-23
day-of-month 1-31
month-of-year 1-12
day-of-week 0-6 (0 is Sunday)

Example
0 22 1-15 9 0 /usr/local/bin/

This says to run at 2200 hrs on the 1st to 15th day of Sept. and only on Sundays.

sam kim_1
Frequent Advisor

Re: crontab

what do i have to add or modify at 'vi editor'!?
can i see any detail sample (after added modifications) ?!
Rick Garland
Honored Contributor

Re: crontab

Not entirely sure of what you are asking.

To modify the cron, invoke the following command (using root account as example)
# crontab -e

This will place you in the crontab file for the root account.

Assuming that your editor is vi, the standard vi commands will allow you to make the modifications. After completion, use the vi commandd of ':wq' to write and quit the file.

To view the modifications, you can issue the command 'crontab -l'

Again, make a copy of the file before doing the making modifications.
Antoanetta Naghiu
Esteemed Contributor

Re: crontab

vi root
mm hh dm mo wd command

where
mm -2 digits for the minute that to what to have it executed(00-59)
hh -2 digits for hour (military time, e.g. 5 pm=17 (0-24)
dm-month day-2 digits -01-31
mo-month-1-12
wd-day of the week, 1-digit 0-Sun, 1-Monday, and so on (0-6)
Command- thatever command you like to execute.
See man crontab for details or crontab.root example.
CHRIS_ANORUO
Honored Contributor

Re: crontab

Sam,
The above contributions are good. Create a cron.allow file in /var/adm/cron and include root, adm, uucp and any user name eg oracle.
Create your cron file with crontab -e.


Cheers!


When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
sam kim_1
Frequent Advisor

Re: crontab

brief summary of this post:

1)why i want to setup crontab?
- i downloaded and installed uvscan program
on this hp server box (for test purpose).
- i am able to run/scan that program, but
am unable to run automatically (ex: 9am in
mon thru fri, scan all files automatically)
- in order to run this file (uvscan)
automatically, i have to do something
first, and that is 'crontab'

2)what did i do for crontab setting?
- with friends' help, i did

# cd /var/spool/cron/crontab
# ls
[nothing is here]

# cd /var/spool/cron
# ls -al crontab.root
# cd crontabs
# cp /var/spool/cron/crontab.root
/var/spool/cron/crontabs/root
# vi root
[i added]
0 09 1,2,3,4,5 /usr/local/bin/uvscan
[then saved it]

# /sbin/init.d/cron stop
# /sbin/init.d/cron start
# crontab -l

3) i checked make sure uvscan is under
/usr/local/bin directory, and is there.

4) now, is this antivirus program (uvscan for unix/hpux server) will run everyday (mon-fri) at 9 am automatically ???


[sorry for my writing style....]
Rick Garland
Honored Contributor

Re: crontab

You could write the crontab file as

0 9 * * 1-5 /

This would tell cron to run the command Mon-Fri at 0900 hrs.
If you would like to do the ranges, cron will accept the notation listed above.

Antoanetta Naghiu
Esteemed Contributor

Re: crontab

You can use 1,2,3,4,5 or 1-5 it is no difference, but you need to specify what month, that day of the month, and so on. Those info are mandatory, not optional.
Try 0 9 * * 1-5 /usr/local/bin/uvscan.
Restart the cron daemon afterwords.
sam kim_1
Frequent Advisor

Re: crontab

i just did/changed

# cd /usr/spool/cron/crontabs
# ls [checked root is there]
# vi root
[inside visual editor]
[modified to]
0 9 ** 1-5 /usr/local/bin/uvscan
[saved it]
# /sbin/init.d/cron stop
# /sbin/init.d/cron start

is this OK to run uvscan automatically ??


Antoanetta Naghiu
Esteemed Contributor

Re: crontab

You should be all set. As a double check, type crontab -l .
The system should return the line from crontab:
0 9 * * 1-5 /usr/local/bin/uvscan
And you be more than....
ps -ef | grep cron
If the process is running, it is ok.