Operating System - HP-UX
1829553 Members
2017 Online
109992 Solutions
New Discussion

Re: how to configure cron

 
SOLVED
Go to solution
rustam_2
Super Advisor

Re: how to configure cron

but through cron my script doesnt work.
Jose Mosquera
Honored Contributor

Re: how to configure cron

Rustam,

You keep the space omission between "sh -x" and "/u02/scripts/rename.sh".
2_17_*_*_*_/usr/bin/sh_-x_/u02/scripts/rename.sh_>>_/tmp/rename.log_2>&1
_ means space between words.

Rgds.
V. Nyga
Honored Contributor

Re: how to configure cron

Hi Rustam,

>less rename.sh
>/usr/bin/mv /u02/scripts/my_file.log /u03/export/my_file_$(/usr/bin/date +%m%d%Y).log

You really should start your script with:
#!/usr/bin/sh


Have you tested a dynamic variable for the date?

V.
*** Say 'Thanks' with Kudos ***
Dennis Handly
Acclaimed Contributor

Re: how to configure cron

>Jose: WORKDIR=Please just indicates the full path where the "my_file.log" is placed.

Right. When you use cron, you start in your home directory. Where are you when you invoke the script manually?
rustam_2
Super Advisor

Re: how to configure cron

Thanks for all of you. Finally, now the rename.sh works through the cron task )). These configurations were set.
$crontab -l
35 9 * * * /usr/bin/sh -x /u02/dump/rename.sh >> /tmp/crontasks.log 2>&1
$less rename.sh
/usr/bin/mv /u02/dump/my_file.log /u02/dump/my_file_$(/usr/bin/date +%m%d%Y).log


I wanted to run some other scripts through cron.
I have script which makes dump files of database. I run it manually when we need.
$less exportSID.sh
expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp

Then I add task in cron
45 12 * * * /usr/bin/sh -x /u02/dump/exportSID.sh >> /tmp/crontasks.log 2>&1

Got error in /tmp/crontasks.log:
+ expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp
/u02/dump/exportSID.sh: expdp: not found.

Then I changed my script
/u01/app/oracle/product/10.2.0/db_1/bin/expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp

Got this error:
+ /u01/app/oracle/product/10.2.0/db_1/bin/expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp
UDE-00013: Message 13 not found; No message file for product=RDBMS, facility=UDE
UDE-00019: You may need to set ORACLE_HOME to your Oracle software directory

Showed my ORACLE_HOME in export script:
$ORACLE_HOME/bin/expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp

Got error:
+ /bin/expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp
/u02/dump/exportSID.sh: /bin/expdp: not found.

Tried another method in script:
Showed my ORACLE_HOME in export script
/ORACLE_HOME/bin/expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp

Got error:
+ /ORACLE_HOME/bin/expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp
/u02/dump/exportSID.sh: /ORACLE_HOME/bin/expdp: not found.

So how I can show expdp in correct syntax?
#whence mv
gave me /usr/bin
but #whence expdp didnâ t give me path.
So I think expdp must be run from ORACLE_HOME/bin

regards,
rustam
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi Rustam,

Congratulations, hard to solve!

The command "whence" only reports about "something" when that "something" is reachable through the global variable PATH, and also has execute permissions.

Best regards.

Dennis Handly
Acclaimed Contributor

Re: how to configure cron

>now the rename.sh works through the cron task

You can now remove the /usr/bin path for mv and date.

>I think expdp must be run from ORACLE_HOME/bin

Yes. And you must export ORACLE_HOME since your ~/.profile isn't executed by cron.
V. Nyga
Honored Contributor

Re: how to configure cron

Hi,

a cron job doesn´t know *your* path variables. You have to define it at the beginning of the script.
I think ORACLE_HOME is not the only variable you have defined in your profile for your database.

Check for all maybe needed variables in your .profile and define it at the beginning of your cron script.

Then you can use it also in your script ($ORACLE_HOME/bin/expdp).
You can also use full path of your command.
It's up to you.

HTH
V.
*** Say 'Thanks' with Kudos ***
rustam_2
Super Advisor

Re: how to configure cron

Hi Jose, Dennis and V

Jose, for global PATH do i need add path in /home/my_user/.profile or in root's directory?
I have ORACLE_HOME and other path's in /home/my_user/.bash_profile and $echo $ORACLE_HOME returns me
$/u01/app/oracle/product/10.2.0/db_1 but i log in by root and got error: sh: ORACLE_HOME: Parameter not set.

Yeah Dennis, thanks. Now mv and date work without full path. Last night rename script run correctly.
>>Yes. And you must export ORACLE_HOME since your ~/.profile isn't executed by cron.

should i add under root or my_user catalog /home/user_name/ ?

V,
can i add in my script these values?

export NLS_LANG=AMERICAN_CIS.AL32UTF8
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
$ORACLE_HOME/bin/expdp system/password@SID FULL=y DUMPFILE=my_file%U.dmp DIRECTORY=my_dir FILESIZE=4G LOGFILE=my_file.log JOB_NAME=FULLexp

>>You can also use full path of your command.
I did this trip and got error. I wrote about it on my previous post.

Regards,
rustam
Dennis Handly
Acclaimed Contributor

Re: how to configure cron

>V. Nyga: I think ORACLE_HOME is not the only variable you have defined in your profile for your database.

You can have the real shell give errors if you try to use an uninitialized variable:
set -u
V. Nyga
Honored Contributor

Re: how to configure cron

Hi again,

>should i add under root or my_user catalog /home/user_name/ ?

No - the problem is that cron will NOT read any user profile settings, so you have to define it in the cron script.

>>You can also use full path of your command.
>I did this trip and got error. I wrote about it on my previous post.

Yes, you got errors, but the script was executed - but it seems like the script itself needs more variables like ORACLE_HOME!
(-> error code UDE-00019)

So yes, try the cron job with the added export lines.
Hopefully the other error (UDE-00013) doesn't appear, else you need more investigation and search for a text file which translates this UDE-00013 error.
Or ask the hotline of this application, they should know it.

HTH
V.
*** Say 'Thanks' with Kudos ***
rustam_2
Super Advisor

Re: how to configure cron

Thanks a lot for all of you!
I could run my script for taking dump of database via cron. I use these configurations:
$crontab -l
14 13 * * * /usr/bin/sh -x /u02/dump/exportSID.sh >> /tmp/crontasks.log 2>&1
$less export SID.sh
export NLS_LANG=AMERICAN_CIS.AL32UTF8
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
$ORACLE_HOME/bin/expdp system/pass@SID ..

regards and thanks a lot,
rustam
rustam_2
Super Advisor

Re: how to configure cron

sorry, i have another question.
are there any option of cron which stops for few days\weeks\months some tasks?
or all i need is run crontab -e and delete needed line(task)?
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi Rustam,

A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

By other hand if you comment (# character) the crontab line (crontab -e) the task will not executes.

Rgds.
rustam_2
Super Advisor

Re: how to configure cron

Hi Jose, thanks for your another help!

Dump files generate with sysdate and then log file renames to sysdate via cron tasks. Everything is ok.
But there is one task which i do manually everyday. Dump file(s) size are ~35Gb and i need to compress them and put ziped dump file and log file in one archive, coz have limited space in my disk arrays.

I run command everyday:
$ zip my_filename.dmp
$ tar cvf myfile_$(date +%m%d%Y).tar myfile_.dmp.gz myfile_.log

Is it possible in my situation do script and then run via cron job which uses variable file name (sysdate parameter is changed everyday)

regards,
rustam
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi Rustam!

If there is real guarantee that the of the dump file is the same as the current day of the machine, then you could:
#gzip -9 my_filename_$(date +%m%d%Y).dmp
#tar cf my_filename_$(date +%m%d%Y).tar my_filename_$(date +%m%d%Y)*.[gl]*

By the way, how is generated the dump file (. dmp)? It is generated from a previous command (ie: a database export using the command "exp")?
I mention this because we see the possibility to compress the file while being generated (On the fly).

Rgds.
rustam_2
Super Advisor

Re: how to configure cron

Hi and thanks a lot Jose.
I think it's what i needed:
#gzip -9 my_filename_$(date +%m%d%Y).dmp
#tar cf my_filename_$(date +%m%d%Y).tar my_filename_$(date +%m%d%Y)*.[gl]*
i checked several times manually. it works fine.
You used tar with option cf. Before i used cvf so it's not problem i will not use v? as official document says - this parameter gives information about archived files.

>>By the way, how is generated the dump file (. dmp)? It is generated from a previous >>command (ie: a database export using the command "exp")?
>>I mention this because we see the possibility to compress the file while being >>generated (On the fly).

Yeah, dump file(s) generates from expdp utility which i mentioned before:
expdp system/password@SID FULL=y DUMPFILE=my_file_$(date +%m%d%Y).dmp DIRECTORY=my_dir LOGFILE=my_file.log

so what does mean - on the fly? Do you mean that i can compress my dump file(s) while it is generated? i think i need to read expdp syntax.

regards,
rustam
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi Rustam,

The -v option is the verbose option, just create an execution output for your default output file, in this case your display.

Compress a file at the time of generation is not an option of the DB Utility. The trick is to use a file "pipe" to make a bridge between the dump's output and gzip's input. This is a compression "On the Fly".

As a major benefit is the saving of disk space. The impact on the processing time will depend more of CPU power and RAM available.

Please see the attachment example
Remember, this is guide, you must adapt to your work environment. :)

Rgds.
rustam_2
Super Advisor

Re: how to configure cron

Hi Jose,
Ok, i got that i may not use -v option. Also i understood the 'on the fly' concept.
Should i create pipe file where is my script or it doesnt matter(path)? I attached edit version of your script. would you check it? so in this case i dont need to use rename script, right? i mean if i run script via cron then all tasks must be done? generation dump file, rename log file, gzip all files with sysdate and archive them.

regards,
rustam
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi Rustam,

>>Should I create pipe file where is my script or it doesnt matter (path)?
As you see, the size of pipe file is minimal and never change, is just a pipe. You must place it as your order convenience, I suggest you place it into same dump file generation path to avoid possible permission issues among involved directories. Also I suggest you that uses a pipe name related with your SID to avoid any possible concurrent use in future (i.e: ${SID}exp_pipe)

>>I mean if I run script via cron then all tasks must be done?
As you see the script done an export/compress of the data at a specific timestamp, using this timestamp as part of name of related files (compressed and log files).

By other hand, I guess that this script file will be run by oracle's user. Then must ensure that directories and file permission will be adecuated, also configure this task in the oracle's user cron.

Rgds.
rustam_2
Super Advisor

Re: how to configure cron

Hi Jose,

>>By other hand, I guess that this script >>file will be run by oracle's user. Then >>must ensure that directories and file >>permission will be adecuated, also >>configure this task in the oracle's user >>cron.
yeah, oracle user must run this script. I will configure cron as OS oracle user.

I made last version of your script(in attached). Is it ok?

>># so it is not appropriate to delete the files that should be contained inside it.
>># When this script have been tested and works fine, uncomment the following comment >>lines:
>>#if [ "$?" = "0" ]
>>#then
>># rm /u02/dump/$DUMPFILE.dmp.gz =/u02/dump/$LOGFILE.log

So if i will uncomment rm /u02/dump/$DUMPFILE.dmp.gz =/u02/dump/$LOGFILE.log then all files(which have been created on sysdate) after archiving will delete, right? i think it's great.

regards,
Rustam
Dennis Handly
Acclaimed Contributor

Re: how to configure cron

>Jose: #if [ "$?" = "0" ]

If you want to check the exit status you should do a numeric compare:
if [ $? -eq 0 ]; then
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi,

On second thought, is not very wise to encapsulate the files (. gz and. log) within a file. tar. You need longer run time and at some time need enough disk space to accommodate .gz (usually large) and the .tar files. In my opinion a waste of resources. Do not worry about maintaining two types of files (.gz and .log) in /u02/dump.

Your last attached file was not the latest version. I now include a final version reflects the latest tips.

By the way, this question has become so large that it is difficult to follow, when you consider appropriate should start a new one. :)

Rgds.
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi Dennis!

By habit I always use symbols (=, != ,> ,<) and not operators (-eq, -ne, -gt, -lt) for comparison within an "if. " It is a personal habit, good or bad. For this reason you also notices that the compared variables are forced to be interpreted as alphanumeric enclosing them within double quotes. The right thing is to do it as you say. Thank you for your comment.

Rgds
rustam_2
Super Advisor

Re: how to configure cron

Hi Jose,
I tested final version and got error like this.
$./370653.sh
./370653.sh[12]: mknod: not found.
./370653.sh[15]: /u02/dump/my_sidexp_pipe: Cannot find or open the file.
LRM-00101: unknown parameter name 'file'

rm: /u02/dump/my_sidexp_pipe non-existent

seems couldnt create pipe file?

Maybe better i should use on fly compress? how much it will be faster? for instance, taking dump takes 1.2 h and making compress 40min.

Regards,
Rustam