1825010 Members
3841 Online
109678 Solutions
New Discussion юеВ

Sleeper - Scripting help

 
SOLVED
Go to solution
Fred Myers_1
Occasional Contributor

Sleeper - Scripting help

I have just migrated an Application from DEC/ALPHA over to HP-UX, and have a bunch of scripts in a job scheduler (maestro) that run database (progress) sessions. Their are jobs that need the previous progress sessions to finish so that I can mark the next one to start (dependancies).

On the dec they used the following logic to accomplish this:
## Sleeper - MUST be present to maintain dependencies.
sleep 60
PID="$(ps x | awk '/\/exec\/.*po[s]/ {print $1}')" # I had to change this to a ps -x as HP needs the - for it to recognize this as a flag
i=1
while [ -f /proc/${PID} ] #Test to see whether loader is running.
do
echo "Elapsed time: ${i} min."
sleep 60 #Snooze a bit longer if it is.
i="$(expr ${i} + 1)"
if [ ${i} -eq 180 ]
exit 1;
fi
done

I get the following error off of the ps command.
+ps -x
ps: don't know which terminal to select

Also I am getting the following errors in the top of the script:
+ stty erase ^H kill ^U intr ^C eof ^D
stty: : Not a typewriter
+ stty hupcl ixon ixoff
stty: : Not a typewriter


So I re wrote the sleeper to look like this.
## Sleeper - MUST be present to maintain dependencies.
sleep 60
PID="$(ps -ex | grep ${USER} | awk '/\/exec\/.*po[s]/ {print $1}')"
i=1
while [ 0 -ne `ps -ef | grep ${PID} | grep -v grep | wc -l` ] #Test to see wh
ether loader is running.
do
echo "Elapsed time: ${i} min."
sleep 60 #Snooze a bit longer if it is.
i="$(expr ${i} + 1)"
if [ ${i} -eq 180 ]
then
exit 1
fi
AND get the following ERROR's
+ ps -ef
+ grep
+ wc -l
+ grep -v grep
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] -e pattern_list...
[-f pattern_file...] [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] [-e pattern_list...]
-f pattern_file... [file...]
usage: grep [-E|-F] [-c|-l|-q] [-bhinsvx] pattern [file...]

WICH LEADS to my 2 Questions.

1.) is thier a better way to do this sleeper, or how do I fix this way. Would a perl script maybe be better?
2.) What do I do about the stty settings, they seem to cause problems, I also see the following error message related to the terminal on login.
unknown mode: dec

the .profile looks like this.
PATH=$HOME/bin:/usr/local/bin:/T008/titan/scripts:${PATH:-/usr/bin:.}
export PATH
if [ ! "$DT" ]; then
stty dec
tset -I -Q
fi
#stty erase ^H
PS1="[`whoami`@`hostname`]$ " ; export PS1
#LOGICALS SETUP FOR REPORTING
. /usr/users/dba/scripts/logicals
EDITOR=vi;export EDITOR
ORCDB=/db/t008att/attoholder
export ORCDB
PROTERMCAP=/T008/titan/scripts/awstermcap
alias l="ls -lrt"
TERM=vt320;export TERM

Thanks
Fred
6 REPLIES 6
Jean-Louis Phelix
Honored Contributor

Re: Sleeper - Scripting help

Hi,

I didn't invest on the grep error, but you could test the process rather using :

while ps -p $PID >&- 2>&-
do
...
done

Regards
It works for me (┬й Bill McNAMARA ...)
Elmar P. Kolkman
Honored Contributor

Re: Sleeper - Scripting help

The problem is with some of the commands.

It seems you'd better do a ps -fu ${USER} and make sure ${USER} is set before doing that. Because it seems that that is causing the error message from grep. And the message from ps comes from the 'x' option that ps doesn't recognize on HP-UX.

For stty I would do something like look at the result from the tty command. If it doesn't result a string like '/dev/...', stty won't work. So in your .profile do:
if [ tty | grep -q '^/dev/' ]
then
stty erase ^H
stty dec
...
fi

Hope this solves your issues.
Every problem has at least one solution. Only some solutions are harder to find.
Jdamian
Respected Contributor

Re: Sleeper - Scripting help

I suggest to change

while [ 0 -ne `ps -ef | grep ${PID} | grep -v grep | wc -l` ]
do

for the following

while ( UNIX95= ps -e -o pid= | grep -q "${PID}"a )
do

This new command line reports 0 if PID is found or 1 if not.

UNIX95= ps -e -o pid=
prints ONLY all existing PID.

grep -q "${PID}"
catches only that PID

The error messages:
stty: : Not a typewriter
are due to running the script without associated terminal (cron job or nohup job).

I don't know what 'x' means as option of 'ps' command.
Jdamian
Respected Contributor

Re: Sleeper - Scripting help

I a PID is given, the shortest ways to check if it is alive are:

a) using 'ps -p PID' as Jean-Louise wrote.
b) using '/usr/bin/kill -s NULL'. Note that I typed the whole path of kill command because internal command called 'kill' embeded in POSIX shell or Korn shell don't accept signal NULL.

I hope this lines be useful.
Graham Cameron_1
Honored Contributor
Solution

Re: Sleeper - Scripting help

Problem 1
"ps -ex" apparently behaves different on alpha.
For hp-ux, change "ps -ex | grep ${USER}" to "ps -fu${USER}" in your first ps line.
Note that if this line returns > 1 PID then the next section fails.
Your while loop seems to be missing the closing "done".
Assuming this is a typo, then I would also suggest changing your while line (all of it) to:
"while { ps -fp$PID >/dev/null 2>&1 ;}"
--
Problem 2
In .profile, change
--
if [ ! "$DT" ]; then
stty dec
tset -I -Q
fi
-- to --
if [ -t ];then ## Tests for interactive terminal
eval $(ttytype -s) ## set up tty type
fi
--
man ttytype for more info
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Fred Myers_1
Occasional Contributor

Re: Sleeper - Scripting help

the -x does exist on HP 11.i It allows the whole line to appear, ie doens't truncate the command. I need to save this part because the command's path is so long, the end gets trunced off.

Thanks for the help!!!