0

Following is my script, for which I am getting an error when I try to kill a process. The error states the process does not exist:

select case when max(LAST_MODIFIED_DATE) > to_date('$TO_EXTRACT_VALUE', 'YYYY-MM-DD HH24:MI:SS')  then 0
else 1
    end
    from $ORACLE_TABLE;" > $SQL_TMP_FILE

    PID=$(ps -ef | grep sqlplus | head -1 | awk '{print $2}')
    print $PID
    sleep 10  > $SQL_TMP_FILE
    kill -9 $PID > $SQL_TMP_FILE

     #echo "FILE_ID: $FILE_ID"
    check_result=$(sqlplus -S  ${ORA_USERNAME}/${ORA_PASSWORD}@$TNS_NAME < $SQL_TMP_FILE)

Also below is the debugged output:

select case when max(LAST_MODIFIED_DATE) > to_date('2014-03-25 00:00:00', 'YYYY-MM-DD HH24:MI:SS')  then 0
    else 1
        end
        from SHIPPING_TRANSACTION;
+ 1> /dw/etl/home/dev/tmp/extract/dw_da/check_shplx_stby_sync.dw_shpmt.ssa_shpmt_trans_fact_shpmt_trans.tmpfile
+ + ps -ef
+ grep sqlplus
+ head -1
+ awk {print $2}
PID=2303
+ print 2303
2303
+ sleep 10
+ 1> /dw/etl/home/dev/tmp/extract/dw_da/check_shplx_stby_sync.dw_shpmt.ssa_shpmt_trans_fact_shpmt_trans.tmpfile
+ kill -9 2303
+ 1> /dw/etl/home/dev/tmp/extract/dw_da/check_shplx_stby_sync.dw_shpmt.ssa_shpmt_trans_fact_shpmt_trans.tmpfile
kill: 2303: no such process

Can someone help me with this

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
user1496783
  • 29
  • 2
  • 9
  • 1
    How do you know that `grep sqlplus` isn't returning the PID of the `grep sqlplus` command? It **does**, after all, contain `sqlplus`, and that explains why it's not still running 10 seconds later. – Charles Duffy Mar 25 '14 at 22:29
  • 2
    If you want to avoid that, use `pgrep` -- don't grep through ps yourself. – Charles Duffy Mar 25 '14 at 22:29
  • 1
    Also, avoid all-uppercase variable names except when referring to environment variables or builtins -- following that rule avoids namespace collisions. – Charles Duffy Mar 25 '14 at 22:30
  • ...even better would be to start the specific sqlplus command you want this to kill in a way that records its PID or maintains a lockfile -- that way you don't risk killing other random processes that happen to have `sqlplus` in their name (say, `vi my-sqlplus-script`). – Charles Duffy Mar 25 '14 at 22:58
  • + echo set verify off set feedback off set heading off set pagesize 0 set numwidth 15 select case when max(LAST_MODIFIED_DATE) > to_date('2014-03-26 00:00:00', 'YYYY-MM-DD HH24:MI:SS') then 0 else 1 end from SHIPPING_TRANSACTION; + 1> /dw/etl/home/dev/tmp/extract/dw_shpmt/check_shplx_stby_sync.dw_shpmt.ssa_shpmt_trans_fact_shpmt_trans.tmpfile + pgrep sqlplus + PID=$ dw_adm_dev@zaisetldev01:/dw/etl/home/dev/bin > – user1496783 Mar 26 '14 at 23:40
  • Above is the output i get if i replace grep and ps -ef with pgrep sqlplus – user1496783 Mar 26 '14 at 23:41

1 Answers1

0

You should use grep sqlplus | grep -v grep or pgrep sqlplus instead of grep sqlplus Maybe 2303 is PID of grep command, not sqlplus.

AkihikoTakahashi
  • 159
  • 2
  • 10
  • Even better than "grep |grep -v " as you can avoid the overhead of a pipe and an instance of grep: "grep [s]qlplus" This matches "sqlplus" but not itself. – Gary_W Mar 27 '14 at 01:32