I am getting "ps: no controlling terminal' when I run a shell script
from within cron. I have a shell script that has to run sequentially
and wait for the previous step to finish before the next step gets
executed. I have implemented that in shell by using ps. Here's the
example -
sh $JOB
#sleep in 3 second intervals until the job is finished
while ps |grep ${JOB}
do
sleep 3
done
The steps are dynamic; so I cant hardcode the steps in a shell script
and run. I dont want to build a shell script and run that instead (al
though that would be the last resort). The shell script works
flawlessly when I am logged on to the machine and run the job from
command prompt; but when I set it up as a cron job; I get "ps: no
controlling terminal' and it skips the while loop.
Any help will be greatly appreciated
Kiran Kodithala
Would you elaborate a bit? Is the job you are waiting on started
from the shell that is waiting? Would "wait $pid" (man -s1 wait)
to the job? Why wouldn't something like
$step1 && $step2 && $step3 ...
work for serializing the steps?
ps without any arguments displays processes associated with your TTY.
If you are running this command from a Cron, you wont have a terminal
and the command fails.
You may want to try: " pgrep your_cmd_pattern" or "ps -ef|grep ..."
HTH
Dexthor.
That must be it, duh!!!!
I will try ps -ef and will let you know. I have a good feeling it will
work.
Thanks a lot!!!!
Kiran
I have never used && - I am a newbie for shell scripting. Would that
serialize my steps?
I can grab the pid; but I need ps to get the pid too right? one of the
users suggested using ps -ef I think that will definitely work. I will
try that one also.
Kiran
>I am getting "ps: no controlling terminal' when I run a shell script
>from within cron. I have a shell script that has to run sequentially
>and wait for the previous step to finish before the next step gets
>executed. I have implemented that in shell by using ps. Here's the
>example -
By default, the current terminal is used andps will quit if can't find
it so you will need to use one of the flags such as "-u user" or "-e".
But you are probably better off using something like:
pwait `pgrep job`
Casper
job1; job2 ... starts job2 upon the completion of job1
job1 && job2 ... starts job2 upon the successful completion of job1
(ie exit code was 0)
In either case, they are "serialized", which is why I'm a bit
confused about your methodlolgy.
>
> I can grab the pid; but I need ps to get the pid too right? one of the
> users suggested using ps -ef I think that will definitely work. I will
> try that one also.
>
> Kiran
How you get the pid depends on how you started the process...
Within your shell "$!" is the pid of the most recently started
backgrounded process. Since it appears that you know the process
by name (when using ps) and that is unique, you could use pgrep
to get the pid, so something like "wait `pgrep $job`" should work
as would "pwait `pgrep $job`". I'd guess that it would be preferable
to use the shell built-in "wait", but haven't used apptrace or similar
to confirm this.
Bob