cancel
Showing results for 
Search instead for 
Did you mean: 

how to configure cron

 
SOLVED
Go to solution
Highlighted
Super Advisor

how to configure cron

Hi all,
I need to configure cron task for running several patches by turn.
I read documentation and now need some practical advices. Planning these steps:
1. I checked, does this service run or doesnt
$ps -ef |grep cron
root 1633 1 0 Oct 29 ? 0:18 /usr/sbin/cron
my_user 5535 20242 0 11:28:56 console 0:00 grep cron
so here is ok.
2. I checked, does my_user exist in cron.allow tab.
$cd cd /var/adm/cron
$less cron.allow
root
adm
uucp
so my_user doesnt exit here, should i add my user? is it ok if i add with vi?
3. My file rename.sh is in /u02/scripts/ and i manually run this script like this $./rename.sh

So how can i add command in crontab file using crontab -e? should i show my command so: /u02/scripts/./rename.sh? or it's wrong syntax? it is a bit complicated. So help me, please.

Regards,
Rustam
53 REPLIES 53
Highlighted
Honored Contributor
Solution

Re: how to configure cron

Hi,

Yes, you must add your user "my_user" with vi editor. if you not be skilled with vi editor I suggest you make first a copy of cron.allow file.
#cp -p cron.allow cron.allow.bak
You also add an entry in your cron.allow with this:
#echo my_user >> cron.allow
For "crontab -e" command you must indicate de full path and filename, the file must be enough privileges for execution, in your case "/u02/scripts/rename.sh" is fine. The correct syntax of crontab command can be viewed:
#man crontab

Rgds.
Highlighted
Honored Contributor

Re: how to configure cron

The most important thing with crontab, you must be sure all commands in your script must have full path due to cron does not use your shell.
Highlighted
Honored Contributor

Re: how to configure cron

Hi again,

Right! which indicates Hakki is important, the cron does not load the definition of environment that normally a user loads when login to the system (/etc/profile, /etc/PATH, homedir user's profile, etc). Other way could be set and export PATH variable as Global enviroment definition, and any others specific variables requested as particular environment definitions (ORACLE_HOME, ORACLE_SID, etc). With these definitions you have search/execute capabilities for commands.

Rgds.
Highlighted
Super Advisor

Re: how to configure cron

Thanks Jose and Hakki,

I did following actions:
1.Add to cron.allow file my_user
#echo my_user >> cron.allow
2.Opened crontab file with command
$crontab â e and add this line
50 14 * * * /u02/scripts/rename.sh
For running my script at 14:50 everyday
3.$crontab â l shows me
50 14 * * * /u02/scripts/rename.sh

But my script did not run. I checked log file /var/adm/cron/log and found nothing according my script.
What is problem? Does not my user have some privileges to /var/spool/cron/crontabs/my_user file? Or as Hakki said my script has problem? If script has problem log file must have error information. I guess cron doesnt know something about my job.
My script includes this line
mv my_file.log my_file_$(date +%m%d%Y).log

Regards,
rustam
Highlighted
Honored Contributor

Re: how to configure cron

Hi,

Have you tested your script at the prompt before try with the cron?
Have your script enough execution privilegues, please post us this command output:
#ls -l /u02/scripts/rename.sh

Rgds.
Highlighted
Super Advisor

Re: how to configure cron

Yeah Jose, i tested manually several times. It works perfect and does what i what. All users have privileges:
$ ls -l /u02/scripts/rename.sh
-rwxrwxrwx 1 root sys 40 Feb 21 15:34 /u02/scripts/rename.sh
Highlighted
Honored Contributor

Re: how to configure cron

Could we see the contents of the script?
Highlighted
Super Advisor

Re: how to configure cron

Jose, yeah, you could.

>>Could we see the contents of the script?

I gave at 12:40:42 GMT

>>My script includes this line
>>mv my_file.log my_file_$(date +%m%d%Y).log
Highlighted
Honored Contributor

Re: how to configure cron

Hi,

Ooops, is too simply!!! :)

Ok, I guess that directory where run this have enough privileges (execution/write).

Well, this looks a search/execution command path issue. As we have indicate you should include the full path for used commands, or set PATH variable to locate them.
A way to know the full path of a command is:
#whence date
A full path assigned in Global PATH variable will be reported.
Then replace:
date +%m%d%Y
By:
/fullpath/date +%m%d%Y

Please try this...