Operating System - HP-UX
1752809 Members
5831 Online
108789 Solutions
New Discussion юеВ

Re: how to configure cron

 
SOLVED
Go to solution
rustam_2
Super Advisor

Re: how to configure cron

Hakki,

>>try 1:
>>11 11 * * * /usr/bin/sh -x/u02/scripts/>>rename.sh >> /tmp/rename.log 2>&1

it gave nothing new. In log file:
-x/u02/scripts/rename.sh: A specified flag is not valid for this command.

>>try 2:
>>chmod 755 /u02/scripts/rename.sh
>>11 11 * * * /u02/scripts/rename.sh >> /tmp/>>rename.log 2>&1

file didnt rename but in log file new event. Event about privileges
mv: my_file.log: cannot access: No such file or directory

crontab -l
15 15 * * * /u02/scripts/rename.sh >> /tmp/rename.log 2>&1

less rename.sh
/usr/bin/mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
V. Nyga
Honored Contributor

Re: how to configure cron

Hi,

I don't know if I had the same problem, but I've splited it, so you can try this:

#!/usr/bin/sh

DATUM='date +%m%d%Y'
mv my_file.log my_file_$DATUM.log


HTH
V.
*** Say 'Thanks' with Kudos ***
Jose Mosquera
Honored Contributor

Re: how to configure cron

Hi Rustam,

Happens because you have a space omission among "sh -x" and /u02/scripts/rename.sh. Please ensure this one into "crontab -e" session:
11 11 * * * sh -x /u02/scripts/rename.sh >> /tmp/rename.log 2>&1

Would you matter changing the syntax of your script with this one? (the result is the same):
#!/usr/bin/sh
TIMESTAMP=`date +%m%d%Y`
WORKDIR=Please just indicates the full path where the "my_file.log" is placed.
cd $WORKDIR
mv my_file.log my_file_${TIMESTAMP}.log


Rgds.

Hakki Aydin Ucar
Honored Contributor

Re: how to configure cron

one second though;
>/usr/bin/mv my_file.log my_file_$(/usr/bin/date +%m%d%Y).log

are you sure in yur file is on correct place ?
/usr/bin/mv //my_file.log my_file_$(/usr/bin/date +%m%d%Y).log
rustam_2
Super Advisor

Re: how to configure cron

I tested various methods.
Now i have:
$crontab -l
32_17_*_*_*_/usr/bin/sh_-x/u02/scripts/rename.sh_>>_/tmp/rename.log 2>&1
_ means space between words

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

and checked this command line also:
/usr/bin/mv /u02/scripts/my_file.log my_file_$(/usr/bin/date +%m%d%Y).log

Still all various commands in rename.sh work correct manually.
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