1829141 Members
6801 Online
109986 Solutions
New Discussion

Re: crontab

 
amit singh_3
Advisor

crontab

hey ,
does any one knows how to execute shell script
interactively by using crontab.
9 REPLIES 9
Mitra Bhanu Rath
Occasional Advisor

Re: crontab

hi,
i think just edit ur crontab file and give the path to ur executable file and ask it to give the std output to /dev/console
like "sh /tmp/file >/dev/console".Hope,this might solves ur problem.

Bhanu
Jeroen Peereboom
Honored Contributor

Re: crontab

Amit,

cron jobs are non-interactive.
A user may change his cron jobs by usinge 'crontab -e' (edit user's crontab file).

You may also want to consider the 'at' command.

I'm not sure what you mean by interactively.

JP
Sanjay Kumar Suri
Honored Contributor

Re: crontab

I am wondering as which kind of script/jobs be fired using crontab and simultaneously be interactive.

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Sunil Sharma_1
Honored Contributor

Re: crontab

Hi,

main function of cron is to run jobs silently in background.

If you want to do it interactively it's batter to run script manually.


Sunil
*** Dream as if you'll live forever. Live as if you'll die today ***
Mark Grant
Honored Contributor

Re: crontab

Guys, I don't think this is entirely true.

You could start a script in an xterm scheduled by cron I iamgine.

a cron job that did something like

00 10 * * * xterm -e "/usr/local/bin/myscript" -display :0

Would start an interactive script at 10.00 in the morning on the console if it was a X console.

However, I can only see this working for X applications.
Never preceed any demonstration with anything more predictive than "watch this"
Jeroen Peereboom
Honored Contributor

Re: crontab

Mark,

that's tricky. Such a cronjob will only end if the xterm is closed?

JP.
R. Allan Hicks
Trusted Contributor

Re: crontab

If you mean by "interactive", providing a script with stored operator input, I think I have a solution for you.


Consider the following script (I call foo.ksh):

#!/bin/ksh
#
read mystuff
echo $mystuff

You run it and get

foo.ksh
Hello World
Hello World

If you create yet another script (I call foo2.ksh):

#!/bin/ksh
#
/mydir/foo.ksh<Hello World
EOF

The second script is submitted as a cronjob.
It calls the first script with the operator responses directed into the first script. So, you can take a standard script or program put the responses after the line that runs the script or program and submit it as a job.

0 0 * * * * /mydir/foo2.ksh

foo2.ksh runs foo.ksh every night at midnight
"Only he who attempts the absurd is capable of achieving the impossible
amit singh_3
Advisor

Re: crontab

hey mark,

I have tried it but still it is not
working.ya but it is manually working,
I mean.....
#xterm -e test.sh
after firing this manually it is working but
in crontab it is not .
so pls help me.
Peter Nikitka
Honored Contributor

Re: crontab

Hi,

you have to set all the Env-vars usually set
in .profile,... in your cronjob BEFORE using them or supply options,.. instead.
Put localhost / your hostname in /etc/X0.hosts
to get permanent access to your display and try

xterm -display localhost:0 ...

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"