[SOLVED] calling sleep from an awk script
I am working on an awk script which repeatedly does some work and then sleeps. Most of the time it is sleeping and while it is sleeping I would like to be able to hit control-c to abort the program. Example awk scripts I have seen suggest this should be possible by testing for a non-zero exit code from the sleep call. However, it doesn't work and my program won't let me stop it. The following test program prints "0" whether I abort the sleep with control-c or wait for it to terminate normally:
#!/bin/awk -f
BEGIN {
print system("sleep 10")
My arch system is up to date. From the "info" man page for sleep it says an abnormal termination should yield a non-zero exit code. I've tried calling other programs instead of sleep and they return non-zero exit codes when I hit control-c on them. I've tried invoking as "/bin/sleep 10" and "env sleep 10" as well. Nothing works. Any idea what I'm doing wrong?
Last edited by scottfial (2010-07-09 08:05:35)
Sleep must return something useful when you it ^C because the following lua program:
#!/usr/bin/lua
local exit_code
repeat
exit_code = os.execute("sleep 10")
print("exit_code: " .. exit_code)
until exit_code ~= 0
produces the following output if I let the sleep expire twice and then hit ^C:
exit_code: 0
exit_code: 0
^Cexit_code: 2
and then it terminates. Now here's an equivalent awk program:
#!/bin/awk -f
BEGIN {
do {
exit_code = system("sleep 10")
print "exit_code: " exit_code
} while (!exit_code)
It produces the following if I let the sleep expire twice and then hit ^C twice:
exit_code: 0
exit_code: 0
^Cexit_code: 0
^Cexit_code: 0
and it never terminates. I have to kill it. Just to make sure that awk is seeing exit codes, I compiled this C program
int main(int argc, char *argv[]) {
return 2;
and changed my awk program to call "a.out" rather than "sleep 10". The result is
exit_code: 2
and then it terminates.
I got the following on the command line:
$ ./a.out
$ echo $?
2
$ sleep 10
^C
$ echo $?
130
Excuse me? 130? Lua saw a 2. None of this makes sense. Its as if awk has singled out "sleep" to not work! Where am I going wrong?
Last edited by scottfial (2010-06-22 17:18:54)
Similar Messages
-
Calling Functions From Import Integration Script
I've got an import integration script that runs fine, however I also have several DataPump scripts that are used in FDM to change specific columns as they come in. I can take the code from the scripts and add to the Import Integration script, but I would rather just call those other functions from the VBScript. I don't see any docs on this, and I'm just wondering if anyone has done this or can describe how I can do it.
Is it possible? Since the standard import scripts reference the strField and the strRecord, can these functions be called from the import integration script?strField and strRecord are arguments passed by the application to the import function. The represent the field as defined by the import format and the record that is being processed during the import.
Given that, I'm not sure how to answer your question. -
Calling sql from a shell script
I have code like the following
sqlplus -s /nolog >> EOF
select 1 from dual;
EOF
Is it possible for me to pass result set to a shell variable or do I have to spool it to a file and then read the file?what is the best way to parse a multi-column, multi-row result set. lets say i have a query that has 9 rows and 2 columns.
this query was
select sysdate, 1
from user_objects
where rownum < 10
07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 07-DEC-2007 16:01:16 1 -
Calling sqlplus from unix shell script
Hi All,
I am executing the following code :-
sqlplus -s ${DATABASE_USER} |&
print -p -- 'set feed off pause off pages 0 head off veri off line 500'
print -p -- 'set term off time off serveroutput on size 1000000'
print -p -- "set sqlprompt ''"
print -p -- "SELECT run_command from tmp_run_batch where upper(batch_name) = upper('${PAR_PROGRAM_NAME}');"
read -p RUN_COMMAND
eval print -p -- \""execute dbms_output.put_line(${RUN_COMMAND});"\"
read -p RET_VAL
print -p -- "exit;"
The select stmt given above gives sample output as :-
pack_claims_clas_utils.func_main('$PAR_RUN_DATE','$PAR_RUN_LEVEL','$PAR_EXCLUSIVE_RUN_YN')
And then this package is executed.
The problem that I am facing is how to handle the no_data_found case of the select stmt. . When this case arises then the stmt. "read -p RUN_COMMAND" hangs.
Could you please provide any solution ?
Thanks
SudsHi,
Have you tried this:
# if [ -n means String has non-zero length
if [ -n $RUN_COMMAND ]
read -p RUN_COMMAND
fi
Hi All,
I am executing the following code :-
sqlplus -s ${DATABASE_USER} |&
print -p -- 'set feed off pause off pages 0 head off veri off line 500'
print -p -- 'set term off time off serveroutput on size 1000000'
print -p -- "set sqlprompt ''"
print -p -- "SELECT run_command from tmp_run_batch where upper(batch_name) = upper('${PAR_PROGRAM_NAME}');"
read -p RUN_COMMAND
eval print -p -- \""execute dbms_output.put_line(${RUN_COMMAND});"\"
read -p RET_VAL
print -p -- "exit;"
The select stmt given above gives sample output as :-
pack_claims_clas_utils.func_main('$PAR_RUN_DATE','$PAR_RUN_LEVEL','$PAR_EXCLUSIVE_RUN_YN')
And then this package is executed.
The problem that I am facing is how to handle the no_data_found case of the select stmt. . When this case arises then the stmt. "read -p RUN_COMMAND" hangs.
Could you please provide any solution ?
Thanks
Suds -
Calling sqlplus from shell script
Hi ,
I am calling sqlplus from a shell script. After running sql commands successfully, it fails to continue executing commands from the shell script.
There is no EXIT statement at the end of the sql.
The error i get is,
SP2-0734: unknown command beginning "echo "FFFF..." - rest of line ignored.
Can someone please help.how does your shell script looks like? did you check my other post today on this forum
sqlplus called from a shell script -
Passing Multiple Parameters to SQL Script from a Shell Script
Hi Friends,
I have SQL script which accepts 6 parameters.
I am calling this from a shell script as shown below:
sqlplus -s ${ORACLE_ID} @${SQLPATH}KORONT_041.sql ${USER_ID} ${PDC} ${item_number} ${KORDC} ${PDCSET} ${last_Updated_in_hours} Out of the six parameters, item_number is not a mandatory parameter.
When i pass all six parameters, there is no issue.
But when i leave item_number blank, i am getting the below error
Enter value for 6:
User requested Interrupt or EOF detected.Based on the error, it seems that the NULL values for item_number is ignored and SQL*PLUS is waiting for one more input from user.
How can i overcome this issue?
Regards,
SreekanthHi,
I am calling the shell script from concurrent program and below is the log file of the concurrent program.
Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
KORONT_041_SH module: KORONT - Daily Item Master Update
+---------------------------------------------------------------------------+
Current system time is 29-JUN-2011 10:09:35
+---------------------------------------------------------------------------+
REQUEST_ID: 68510795
USER_ID: 4219
PDC: 85
Item Number:
KORDC: 124
PDCSET: 1100000003
last_updated_in_hours: 24
EMAIL_ID: [email protected],[email protected]
SQLPATH: /e381/oracle/asodev01appl/custom/motont/1.0.0/sql/
RPTDIR: /e381/oracle/asodev01comn/admin/out/ASODEV01_asoprdb2
RPTFILE: o68510795.out
Table truncated.
*Enter value for 6: User requested Interrupt or EOF detected.*
Table truncated.
old 15: AND ic.organization_id = &&4
new 15: AND ic.organization_id = 1100000003
0 rows created.
Input truncated to 9 characters
old 8: AND organization_id = &&4
new 8: AND organization_id = 1100000003
0 rows created.
End of SQL
No record.
+---------------------------------------------------------------------------+
Executing request completion options...
+------------- 1) PRINT -------------+
Printing output file.
Request ID : 68510795
Number of copies : 0
Printer : noprint
+--------------------------------------+
Finished executing request completion options.
+---------------------------------------------------------------------------+
Concurrent request completed successfully
Current system time is 29-JUN-2011 10:09:38
+---------------------------------------------------------------------------+Regards,
Sreekanth -
Is it possible to call a method in a servlet from a java script ?
I need to do a dynamic html page . In the page i select some things and then these things must communicate whit a servlet because the servlet will do some DB querys and update the same webpage.
So is it possible to actually call a method of a servlet from a java script? i want to do something that looks like this page:
http://www.hebdo.net/v5/search/search.asp?rubno=4000&cregion=1011&sid=69DHOTQ30307151
So when u select something in the first list the secodn list automaticly updates.
thank you very muchYou can
1. load all the options when loading the page and
set second selection options when user selected
the first; or
2. reload the page when user select first selection
by 'onChange' event; or
3. using iframe so you only need to reload part of
the page. -
Calling a report from a shell script
We are modifying all concurrent programs to encrypt the oracle password by using the "ENCRYPT" option in the concurrent program definition for all unix based programs.
The db user/password is derived from the FCP_LOGIN within the shell script. If I submit the concurrent prorgam and go to the root directory on which the unix shell scripts are present and execute the following command :
ps -ef
I can see the call to the concurrent program and since I am using the encrypt method, i cannot see the password(I could see the password before the change)
The problem is one of the shell scripts is calling an Oracle Report by using ar25run command which needs a userid as the parameter.
So when I issue the above ps command, i can see the password in the call to this report.
Is there any other way of passing the oracle user/password to the report? This is required for SOX compliance.
thanks,I guess it should be the same problem as if you are calling CONCSUB from unix also, because both need userid and password.
If that's the case probably metalink note 104541.1 might help you. -
Calling a report from unix shell script
Hi,
I had to call a report from unix shell script.
May i know the procedure to accomplish this
Thanks in Advance
A.GopalFirst you should not include the whole path to your report in the call ...
Use like this:
/ora/u01/oracle/v101/as2/bin/rwrun.sh report=an_stati destype=file desname=/ora/u01/oracle/v101/as2/test.pdf desformat=pdf
In $ORACLE_HOME/bin/reports.sh:
1) Verify that you have updated the REPORTS_PATH variable to include your folder where you have the report in question
REPORTS_PATH=/ora/u20/app/qits/env1/run:$ORACLE_HOME/reports/templates:$ORACLE_HOME/reports/samples/demo: ....
2) Verify that the REPORTS_TMP variable is pointing to a valid location and that the oracle user has access to write on it.
After that, post the content of the tracefile located at $ORACLE_HOME/reports/logs/{in-process report server name folder}/rwserver.trc
If no file is present then it means that you need to enable trace in your reports's conf file.... go to the $ORACLE_HOME/reports/conf folder and and locate the .conf file that correspond to your in-process reports server name (as specified in the rwservelet.properties file)... open/edit the file to enable trace logs ..
i.e.
Change the following line:
<!--trace traceOpts="trace_all"/-->
to <trace traceOpts="trace_all"/>
Bounce the reports server and try to run the report again, this time the .trc file should be generated, post the content so that we can take a look. -
How to call a perl script from an apple script
Hi All,
How to Call a perl Script from an apple script.
Pls Give Your comments.
Thanx & Regards,
EstherApplescript to call a perl script named "/tmp/x.pl" passing an argument "world"
do shell script "/usr/bin/perl /tmp/x.pl world"
or if the script is given the executable atttribute (chmod +x /tmp/x.pl),
do shell script "/tmp/x.pl world"
Perl script "/tmp/x.pl" that prints a string using a passed argument
#!/usr/bin/perl
print "Hello $ARGV[$1]\n"; -
Error when calling a stored procedure from a SQL Script
Apologies if this is a really dumb question but I can't seem to call a procedure in package from a SQL script. I have a simple package.procedure containing a loop to populate a table. I would like to include a call to this procedure from my database install script, that also includes my CREATE and INSERT statements. I run the script using "@install_databae" and the CREATE and INSERT statements run fine. The script gives an error when it reaches the line below:
exec lazarus.PopulateGridPositions;
and gives the error.....
BEGIN lazarus.PopulateGridPositions; END;
ERROR at line 1:
ORA-04063: package body "LAZARUS.LAZARUS" has errors
ORA-06508: PL/SQL: could not find program unit being called: "LAZARUS.LAZARUS"
ORA-06512: at line 1
The procedure and package have both compiled without errors and the statement on its own works fine in SQL*Plus.
I've obviously missed some fundamental concept with scripts and SQL. Please can anybody help me?Histon FTM wrote:
ORA-04063: package body "LAZARUS.LAZARUS" has errors Above, obviously conflicts with the statement that follows:
>
The procedure and package have both compiled without errors and the statement on its own works fine in SQL*Plus.I suggest you take a look in the USER_ERRORS view to see, what the errors are.
And just checking:
You have schema called LAZARUS, which holds a package named LAZARUS, which holds a procedure called POPULATEGRIDPOSITIONS?
Edited by: Toon Koppelaars on Oct 1, 2009 5:55 PM -
My Iphone 4s reciever is not working properly, when i call someone from my iphone 4s. can any one help me how to solve this problem?
You might like to define "not working properly".
-
Calling stored procedure from unix shell script
Hello,
I am facing a problem while calling a stored procedure from UNIX shell script. I want to return a output variable from the stored procedure to the UNIX environment.
Here is the code-
#!/bin/sh
OUTPUT=`sqlplus cmag/magnum@dw <<ENDOFSQL
set serveroutput on;
var prd_out varchar2(100);
exec create_pm_window(:prd_out);
exit;
ENDOFSQL`
echo " output is - $OUTPUT"
The problem is :prd_out is not getting copied to shell variable OUTPUT.
I have a dbms_output.put_line in the stored proc create_pm_window and I can see that prd_out is getting populated.
Any help is really appreciated.
Thanks'
RakheeFirst step :
make sure the PL/SQL works as expected.
Does the following display the expected output executed from SQL*Plus ?
set serverout on
declare
prd_out varchar2(100);
begin
create_pm_window(prd_out);
dbms_output.put_line('output is '||prd_out);
end;
I don't have your procedure, but using a dummy procedure like :
Scott@my10g SQL>create procedure foo(p_out in out varchar2)
2 is
3 begin
4 select 'Hello '||instance_name into p_out from v$instance;
5 end;
6 /
Procedure created. and a toto.sh script as :OUTPUT=`sqlplus -s scott/tiger <<EOF
set pages 0 lines 120 trimout on trimspool on tab off echo off verify off feed off serverout on
var mavar varchar2(100);
exec foo(:mavar);
print mavar;
exit;
EOF`
echo "OUT = ${OUTPUT}"
exitIt works fine :[oracle@Nicosa-oel ~]$ ./toto.sh
OUT = Hello my10g -
Calling a pl\sql package main precedure from a SHL script
If I run this procedure from TOAD suppl_load_main MY package is executed,
I need to be able to handle this to the user, so they can run it from our application, I am using a shl script to call this precedure, I done this before and it works, I never done using the main precedure from a package where the main call other precedures, I know I am doing the right stuff in the application registering the
jobs, creating the links for the shl etc...
I guess the question is, it is possible to call the Main precedure(that call other precedures) from the shl script, or what I am doing wrong
Thank you
PROCEDURE suppl_load_main (
p_one_up_number IN NUMBER,
p_process_name IN VARCHAR2,
p_audit_or_update IN VARCHAR2,
p_user IN VARCHAR2 DEFAULT NULL
IS
Modification History
08/11/2009 Creator:
This is the precedure that will execute the all package, there are not parameters,
the package just need to be executed from this precedure.
Changes:
p_applicant_main_err_code VARCHAR2 (2000);
p_main_err_code NUMBER;
p_ora_err_msg VARCHAR2 (2000);
p_insert_err_code VARCHAR2 (2000);
p_ora_err_code VARCHAR2 (2000);
p_srtpers_err_code VARCHAR2 (2000);
p_gurmail_err_code VARCHAR2 (2000);
v_out_path VARCHAR2 (2000) := 'MIDD_LOG';
v_out_file VARCHAR2 (2000)
:= 'common_app_supl_load_pkg'
|| '_'
|| TO_CHAR (SYSDATE, 'YYYYMMDDHH');
v_file_handle UTL_FILE.file_type;
p_refresh_err_code VARCHAR2 (20000);
v_email saturn_midd.mail.email_con;
v_mailto saturn_midd.mail.email_address;
v_mailfrom saturn_midd.mail.email_address;
v_mailsubject VARCHAR2 (65) := '';
v_mailmessage VARCHAR2 (32000) := '';
v_database_name VARCHAR2 (10);
BEGIN
SELECT ora_database_name
INTO v_database_name
FROM DUAL;
v_database_name :=
SUBSTR (ora_database_name, 1, INSTR (ora_database_name, '.') - 1);
-- isolate instance name
v_file_handle := UTL_FILE.fopen (v_out_path, v_out_file, 'w');
UTL_FILE.put_line (v_file_handle, v_database_name);
UTL_FILE.put_line (v_file_handle,
' ' || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH:MI:SS')
UTL_FILE.put_line (v_file_handle, 'Starting the stuu_MISS_LOAD_main...');
srtiden_insert (p_insert_err_code, p_ora_err_code, p_ora_err_msg);
srtaddr_insert (p_insert_err_code, p_ora_err_code, p_ora_err_msg);
srtpers_insert (p_insert_err_code, p_ora_err_code, p_ora_err_msg);
upd_srtpers_day_mon_yr (p_srtpers_err_code,
p_ora_err_code,
p_ora_err_msg
srttele_home (p_insert_err_code, p_ora_err_code, p_ora_err_msg);
appl_gurmail_insert (p_gurmail_err_code, p_ora_err_code, p_ora_err_msg);
p_main_err_code := '0';
UTL_FILE.put_line (v_file_handle,
CHR (10) || 'All procedures ended successfully.'
IF p_applicant_main_err_code = 0
THEN
UTL_FILE.fremove (v_out_path, v_out_file);
END IF;
v_mailto.email := '[email protected]';
v_mailfrom.email := '[email protected]';
v_mailsubject :=
v_database_name || ': common_app_supl_load_pkg,testing email_1 ';
saturn_midd.mail.MESSAGE
(v_email,
v_mailto,
v_mailfrom,
v_mailsubject,
v_database_name
|| ': *common_app_supl_load_pkg testing email* '
|| CHR (100)
|| 'All procedures ended successfully: '
|| v_out_path
|| '/'
|| v_out_file
EXCEPTION
WHEN OTHERS
THEN
p_applicant_main_err_code := '1';
p_ora_err_msg := SUBSTR (SQLERRM, 1, 2000);
p_ora_err_code := SQLCODE;
v_mailto.email := '[email protected]';
v_mailfrom.email := '[email protected]';
v_mailsubject := v_database_name || ': commonapp_supl_load_pkg';
saturn_midd.mail.MESSAGE
(v_email,
v_mailto,
v_mailfrom,
v_mailsubject,
v_database_name
|| ': *commonapp_supl_load_pkg ended testing email_2* '
|| CHR (100)
|| 'Output log is on the server MIDD_LOG: '
|| v_out_path
|| '/'
|| v_out_file
saturn_midd.mail.message_end (v_email);
END suppl_load_main;
END commonapp_supl_load_pkg;here is the shl
v_audit_or_update VARCHAR (1) := 'A';
The application needs this parameter...
/* Formatted on 2009/02/06 15:17 (Formatter Plus v4.8.8) */
-- Author:
-- Date Written: August 2009
-- Purpose: This script calls the PROCEDURE saturn_midd. suppl_load_main
-- Version Control:
SET serveroutput ON SIZE 1000000
DECLARE
v_audit_or_update VARCHAR (1) := 'A';
job_num NUMBER := NULL;
process_name VARCHAR2 (8) := NULL;
v_user VARCHAR2 (30) := NULL;
BEGIN
job_num := TO_NUMBER (&1);
process_name := '&2';
v_user := UPPER ('&3');
-- Retrieve the parameters for this job submission, so they can be passed to
-- the stored procedure.
SELECT UPPER (gjbprun_value)
INTO v_audit_or_update
FROM general.gjbprun
WHERE gjbprun_job = UPPER (process_name)
AND gjbprun_one_up_no = TO_NUMBER (job_num)
AND gjbprun_number = '01';
-- Now call the stored procedure to do the work.
saturn_midd.commonapp_supl_load_pkg.suppl_load_main( job_num,
process_name,
v_audit_or_update,
v_user);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
-- Put a message in the job log
DBMS_OUTPUT.put_line
('No parameters in Process Run Parameter Table (GJBPRUN)');
END;
EXIT;
/what I am doing wrong supl_load_main invokes a whole bunch of commands that could each potentially fail, but it has one generic exception handler that sends an email (or that's what it looks like, maybe it desn't even do that - what do saturn_midd.mail.MESSAGE and saturn_midd.mail.message_end do?) and doesn't re-raise the exception, so anything could be failing and you wouldn't know.
There seems to be some confusion between "p_" variables (normally parameters) and "v_" (normally local variables) which suggests that some wholesale copying and pasting might have gone on and therefore that some of the assignments might not be doing what they were originally intended for. For example, after assigning SUBSTR (SQLERRM, 1, 2000) to p_ora_err_msg, it is not used again. Perhaps originally p_ora_err_msg was returned to the caller, written to a logfile etc.
I'm not a fan of including the word "main" in procedure names or the assumption that one procedure in a package should be more important than any others, but I do see it a lot so I guess you're not alone in that approach. -
Hi guys..I want to call a maxl script from a unix script. i am using ksh shell in unix..
Can anyone give me the syntax from this..I am not very familiar with this.Actually I found there was an Esscmd.sh file too.that's why wanted to be sure about the option of esscmd.
And would these scripts accept parameters like this:
<path>Middleware/user_projects/epmsystem1/EssbaseServer/essbaseserver1/bin/startMaxl.sh /maxl-Path/script.mxl 1 2
and if we place & after the script name would it be a nohup process and run the next ones parallely??:
<path>Middleware/user_projects/epmsystem1/EssbaseServer/essbaseserver1/bin/startMaxl.sh /maxl-Path/script1.mxl &
<path>Middleware/user_projects/epmsystem1/EssbaseServer/essbaseserver1/bin/startMaxl.sh /maxl-Path/script2.mxl &
Sorry if my questions seem stupid.
I know very little about this tech and just want to clear any confusion and know as much as i can.
Maybe you are looking for
-
Structure: * one main movie ** one swf loaded into that *** one mc in that I animate the mc using the timeline (movement up) and on the first frame of the same mc I generate up an interface inside it. This all works, but: When the mc has generated th
-
How to display op amp as 14-pin chip rather than 4 individual amp circuits?
As the title says; can I change the way Multisim displays an op amp from 4 individual amp circuits to 1 14-pin chip? I'm just interested in placing the chip and building my components around it. thanks. SCXI- 1000 Chassis w/ 1346 adapter PCI 6281 DA
-
I get this error when trying to start iTunes in 10.8.4 This is really anoying from a frsh install of Mountain Lion. What is going on with Apple the errors keep coming.
-
How to Kill Specific Execute Threads
Hi. Through our application server, we noticed that there were some memory issues where the memory usage would rapidly increase from ~ 15Mb to the max heap size. Issuing a few thread dumps, we realized that there was a specific thread that was churni
-
Where can i get this package com.ack.util ?
Hi all, where can i get this package com.ack.util ? Regards, Vishal