What I need is the export to run, in the background, the script to wait for that to run and then return the row count (this is the start of a script which will kill the WAITPID and processes associated if it runs for longer than a specified time.
Would be easy if I didn't need the export... ideas?
I can't, the "td" command connects to the database and returns the rows. Initially I had:
export NUMROWS=`td "select * from dbc.database" 2> /dev/null |
grep "Query completed" | sed -e 's/.*Query completed. //g' -e 's/row.*found.*//g'`
That works. What I need is to run that in the background as it can take minutes or hours to run the SQL, if after, say in our test, 30minutes, this process is still running I want to kill it. So need the & to run in background. But without writing the results to a file can't see any obvious way of doing it...
@methyl this is a perf test suite of scripts and this "test" is to simulate Teradata, and network performance to the ETL box.
So currently have a script to run X predefined queries for Y minutes. Queries are re-submitted after they complete until Y minutes is up. Any running at this point stay running and have to be manually forced off. So am trying to re-code this process.
The reports are then generated from the number of queries run, run time for each, a seperate report is done from the log tables in the database. All this is then put in a report database available to managers after any major changes.
Think the solution is going to be pipe the rows to awk, generate the print statement into a temp file, (export NUMROWS=402) and then run that file to get that figure. bit more hassle but easy to implement.
---------- Post updated at 08:23 AM ---------- Previous update was at 08:14 AM ----------
Or we can use the basic shell "jobs" command. Obviously we would need to build a counter into the loop to allow us to stop after a given amount of time.
while [ "`jobs`" ]
do
echo "still running"
sleep 10
done
Tip. The "ps -ef" command sequence posted assumes unique matches for the "grep". You are very likely to get false matches.
Confining the search to one pid with "ps -fp<pid>" would be safer and quicker.
Actually for anything mission critical I would never rely on "ps -ef" because it occasionally misses processes (or does not reply at all) when the kernel is busy.
@radoulov
no expect, the other shells do exist will investigate - didn't realise we even had those installed lol
@methyl
Yeah ps -ef is not my favourite. In the real script I am using:
while [ -d /proc/${WAIT_PID} ]
along with proctree to get the process I am after which I need to kill, in this case bteq for Teradata. Figure it must be better, and quicker than a ps -ef....