Storing process Id of a nohup command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Storing process Id of a nohup command
# 1  
Old 05-05-2014
Storing process Id of a nohup command

Hi,

I am running below code:
Code:
 
for i in `ls`
do
nohup sqlldr userid=apps/apps data=data01.dat log=my1.log control=my.ctl bad=my1.bad direct=yes silent=all parallel=true &
done

This will run the sqlldr command in parallel as a background process.
I want to store the process Id each time the command is run and store it in a Oracle table with status if the process is running or completed.

Any kind of help is highly appreciated.
Thanks.

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 05-05-2014 at 05:35 AM.. Reason: code tags
# 2  
Old 05-05-2014
you can gather the process id using $!, store it into a file and at the end, load them into the table

Code:
for i in `ls`
do
nohup sqlldr userid=apps/apps data=data01.dat log=my1.log control=my.ctl bad=my1.bad direct=yes silent=all parallel=true &
Process_ID=$!
echo "${Process_ID}" >> file.out
done

anyways, it if is oracle, v$session table will hold the current running sql processes id
Code:
SELECT process FROM v$session WHERE username = 'SCOTT';

This User Gave Thanks to SriniShoo For This Post:
# 3  
Old 05-05-2014
Thanks for help,
Could you also tell me After storing the process Id how can i check if that particular process is running or completed?
# 4  
Old 05-05-2014
if you want to wait till that process is completed,
Code:
wait ${Process_ID}

You can capture multiple process id's is different variables and run the above command to wait for each

---------- Post updated at 05:00 AM ---------- Previous update was at 04:55 AM ----------

Code:
if [[ $(ps -eaf | awk -v pid="${Process_ID}" '$2 == pid {} END {print NR}') > 0 ]]; then
echo "Running";
else
echo "Completed";
fi

This User Gave Thanks to SriniShoo For This Post:
# 5  
Old 05-05-2014
How about this ?
Code:
#!/bin/bash

sqlplus -s apps/apps << EOF
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
delete from tablename;
exit;
EOF


for i in `ls`
do
nohup sqlldr userid=apps/apps data=data01.dat log=my1.log control=my.ctl bad=my1.bad direct=yes silent=all parallel=true &
Process_ID=$!

sqlplus -s apps/apps << EOF
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
insert into tablename (id,status) values ($Process_ID,'Running');
exit;
EOF

done

RunningProcess {

count=$(sqlplus -s apps/apps << EOF
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
select count(id) from tablename where status='Running';
exit;
EOF)

}

RunningProcess;
while [ $count -gt 0 ]
do

echo "
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
select id from tablename where status='Running';
" |sqlplus -s apps/apps | while read Pid
do
      ps -f $Pid 2>/dev/null
      if [ $? -eq 1 ]
      then
          sqlplus -s apps/apps << EOF
          whenever sqlerror exit sql.sqlcode;
          set echo off
          set heading off
          update tablename set status='Completed' where id=$Pid;
          exit;
          EOF
      fi
  done
  RunningProcess;
done


Last edited by pravin27; 05-05-2014 at 07:27 AM..
This User Gave Thanks to pravin27 For This Post:
# 6  
Old 05-05-2014
Thanks for detailed help!

---------- Post updated at 05:08 AM ---------- Previous update was at 05:02 AM ----------

when I run the command
ps -f 29097
echo $? prints 1 although this process has already completed.
Any idea why its happening

---------- Post updated at 05:24 AM ---------- Previous update was at 05:08 AM ----------

when I do ps -f 29097
it displays: PID TTY STAT TIME COMMAND
and the status of command is false...
i.e
echo $?
1
# 7  
Old 05-05-2014
Hi,

Updated my previous post. Please check "if" condition

Thnx,
Pravin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Running process in nohup

Hi All, I am facing issue in running a process in nohup. I ran a process in terminal since it is taking too long to complete I need to make it as background and nohup. I tried below and was able to make it in back ground 1. Cntrl + Z 2. bg I am using Korn Shell so disown is not working... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

2. Shell Programming and Scripting

How to pause process running under nohup?

Hi ALL, Is there any way to pause a running process under nohup ? I have fired a build commands with required flags under nohup as below. now how can I pause the started build process. nohup make DEVICE=ap DEBUG=1 & I understand we can use ctrl + z to pause a foreground process... (3 Replies)
Discussion started by: useless79
3 Replies

3. UNIX for Dummies Questions & Answers

Can I convert a foreground process to NOHUP ?

OS : AIX 6.1/Solaris 10 After I started running a shell script, I've realized that it will take another 5 hours to complete. Is there anyway I could convert this foreground process to run in nohup mode so that I can go home peacefully ? I have the process ID $ ps -ef | grep... (4 Replies)
Discussion started by: kraljic
4 Replies

4. UNIX for Dummies Questions & Answers

Process status for NOHUP command

Hi, I have run a shell script as a background process using 'nohup' command. I want to see the process id of this, so that I will be able to kill it later on when required. I tried to collect these details using 'ps' command and could not view this information. How do we get this... (5 Replies)
Discussion started by: Dev_Dev
5 Replies

5. UNIX for Dummies Questions & Answers

Run process with nohup every certain time

Hi, I need execute a script every 30 minutes. As might be done without using cron Thx. (6 Replies)
Discussion started by: pepeli30
6 Replies

6. UNIX for Advanced & Expert Users

Bringing a nohup process to foreground

Hi, I have used nohup command to run a process in background. i ran successfully and i exit from that terminal. But when i login for the next time I am not able to see the process but it is working, since I am getting a e-mail alert for error issue. Please let me know how to bring that process... (3 Replies)
Discussion started by: mbguy
3 Replies

7. Shell Programming and Scripting

Process id of the exe started with nohup

Hi, I have a strange problem. In my shell script, i am startting another program (a c++ exe) with nohup . I am getting the process id of this started process with using $! I am writing this process id into another file so that i can keep checking for this process ids to check whether the... (2 Replies)
Discussion started by: parvathi_rd
2 Replies

8. UNIX for Advanced & Expert Users

nohup and background process

What is the difference between running a process using nohup and running a process in background ? Please explain (6 Replies)
Discussion started by: srksn
6 Replies

9. Shell Programming and Scripting

pid of nohup process

I want to print the pid of a nohup process to a file so later I can use the list of pid's in that file to stop the background processes again. I use ksh on AIXv5.3: nohup /start/script.ksh 1>/dev/null 2>&1 print $$ > .pid nohup /start/script2.ksh 1>/dev/null 2>&1 print $$ >> .pid But... (2 Replies)
Discussion started by: rein
2 Replies

10. Shell Programming and Scripting

nohup process hangs

Hi All, I tried searching for this, but I have yet to find anything useful. So here goes, if a script executed from another script with nohup & hangs, does it affect the parent script? Reason I ask, we have a windows box with NFS, and we use it to store some of our files. Currently, I mount the... (2 Replies)
Discussion started by: Sully
2 Replies
Login or Register to Ask a Question