Link to home
Create AccountLog in
Avatar of contacto_rangel
contacto_rangel

asked on

Launching a script using the crontab

Hello Experts

I've a shell (mxprdxi_ora_XIP_arch) this shell actually runs manually, but I need it to run under automatically if this file system: /oracle/XIP/oraarch reaches the 50% use.

I've acces to the crontab, but I don't know how to program the instructions to do that, Could you please help me with it?, Any Ideas are welcome, including links to pages or manuals to program using shells for unix.
Avatar of arnold
arnold
Flag of United States of America image

entry under the oracle user such as:
0 23 * * * /fullpathto/mxprdxi_ora_XIP_arch

This will run the script on a daily basis at 11pm.
Any output or error will be emailed to the oracle account.  Once you see it working as intended, adding 2>/dev/null >/dev/null which will resolt in:
2>/dev/null = ignore error messages
>/dev/null = discard output

This assumes the script you referenced does the calculation for the 50% threshold.
- put the code below in a file e.g. call it myscript

fs=` /usr/sbin/df -k /oracle/XIP/oraarch  | /usr/bin/tail -1 | /usr/bin/awk '{print $5}' | /usr/bin/awk -F% '{print $1}'`
if test $fs -gt 50
then
        /path/to/mxprdxi_ora_XIP_arch
fi

- make it executable

chmod +x myscript

- run

EDITOR=vi ; export EDITOR
crontab -e

and add line similar to

0,10,20,30,40,50 * * * * /path/to/myscript

save and exit

This will schedule the script to run every 10 minutes
Avatar of contacto_rangel
contacto_rangel

ASKER

Thank you omarfarid

This is exactly what I was asking for!
I just have one doubt: Does the script checks also if the FS goes upon the 50% limit?
For example if between the every 10 minutes check the FS goes to more than the 50%, 51 or 52% or more?
If not, what else in the myscript needs to be changed?

Best regards
Edgar
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
No, I don't want to check it more frequent just check if the FS has 50% is there any way to check the >50 condition?
Omarfarid:

I tried the script just as you wrote it, and worked perfectly fine: when the FS goes to 51% or more it launches the second script.

I'm very glad with your support, thank you very much!.
The test:
if test $fs -gt 50
Is testing the result that is stored in FS, if it is greater then (-gt) 50.
This was a perfect answer for my problem.