Operating System - HP-UX
1834200 Members
2959 Online
110066 Solutions
New Discussion

Running scripts fron cron

 
SOLVED
Go to solution
N Gopal
Frequent Advisor

Running scripts fron cron

Hi All,

I am using HP-UX taaput01 B.11.11 U 9000/800.
I have one sh scripts xyz.sh.

./xyz.sh

it ask enter the port no .

If i want to run it fron cron then how can i supply the input to this scripts.

Could some one please give some thought.

Regard's
7 REPLIES 7
Srikanth Arunachalam
Trusted Contributor

Re: Running scripts fron cron

Hi Gopal,

You modify your script xyz.sh to accept the first parameter $1 with port number. In the script the value of variable $1 is the one passed as parameter to xyz.sh from the prompt. If port number is static, you need not have this parameter rather you could hardcode it.

you can define cron job as

0 15 * * */home/abc/xyz.sh 5320 >/dev/null 2>&1

Thanks,
Srikanth
N Gopal
Frequent Advisor

Re: Running scripts fron cron

Hi Srinikant,

I can understand this. But suppose we can not update the scripts, in that case is it possible or not?

Thanks
Yogeeraj_1
Honored Contributor

Re: Running scripts fron cron

hi,

Cron is more for non-interactive scripts! You cannot change its behaviour. Of course, you can run the script using the cron and which takes its input from a file.

e.g.
...
INPUT=$(cat /home/yogeeraj/mvar.txt)
if [ $INPUT = 'XYZ' ]; then
...


hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: Running scripts fron cron

hi,

Cron is more for non-interactive scripts! You cannot change its behaviour. Of course, you can run the script using the cron and which takes its input from a file.

e.g.
...
INPUT=$(cat /home/yogeeraj/portnum.txt)
if [ $INPUT = 'XYZ' ]; then
...


hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
rajdev
Valued Contributor
Solution

Re: Running scripts fron cron

Hi Gopal,

you can do the following :

1. create a file abc and put the port no. into it

# cat 999 > /tmp/abc

2. now run xyz.sh and redirect input to /tmp/abc.

# ./xyz.sh < /tmp/abc

3. Now use the same in cron
10 10 * * * /path/xyz.sh < /path/abc

Regards,
RD
N Gopal
Frequent Advisor

Re: Running scripts fron cron

Hi Raj,

Thanks it is working for me.

Thanks
N Gopal
Frequent Advisor

Re: Running scripts fron cron

Hi,

I am closing this thread. I got satisfactory answer.

Thanks