Sponsored Content
Top Forums Shell Programming and Scripting Capture std out snapshot after 15 seconds Post 302993642 by Chubler_XL on Sunday 12th of March 2017 06:48:44 PM
Old 03-12-2017
In bash you could have process substitution manage a named pipe for you. Below I duplicate this with exec onto file descriptor 7.

You can then simply read and discard from this file descriptor for 15 seconds,. If you can be sure of a maximum amount of data going to be sent (eg here we are limited to 10000 characters) you can simplify this to a single read statement:

Code:
#!/bin/bash
exec 7< <(./program 2>&1 )

# Discard first 15 seconds of data (limit is 10000 characters)
read -u 7 -t 15 -N 10000 discard

# Now you can read line you are interested in
read -u 7 -t 3 line

or without a size limit just read lines for 16 seconds, keeping the last read:

Code:
#!/bin/bash
exec 7< <(./program 2>&1 )

# Read data for 16 seconds
for((i=SECONDS+16;SECONDS<i;))
do
    read -u 7 -t $((i-SECONDS)) line
done

# At this point, $line will be last line output after 16 secs

Edit: Solution using coprocesses (required bash4). we run the process, discard first 10,000 characters or 15 seconds of input and then read the next line. This will also kills the process once we have the required result:

Code:
coproc { ./program 2>&1 ; }

#discard 15 seconds or 10,000 characters of input (whichever is the first)
read -u ${COPROC[0]} -t 15 -N 10000 discard

# wait up to 3 seconds for the next line of output
read -u ${COPROC[0]} -t 3 line

# kill process
kill $COPROC_PID 2> /dev/null

if [ -z "$line" ]
then
    echo "timeout - no output line after discarding early stuff"
else
    echo "Last line: $line"
fi

This could also be coded using named pipes in other shell versions if needed.

Last edited by Chubler_XL; 03-12-2017 at 08:28 PM..
These 2 Users Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to redirect std out and std err to same file

Hi I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this. Thanks (2 Replies)
Discussion started by: 0ktalmagik
2 Replies

2. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

Hello all Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting The fallowing error : Undefined first referenced symbol in file std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Discussion started by: umen
0 Replies

3. Shell Programming and Scripting

reading from within the loop --std i/p problem

i have a teat file having data like one 12/3 two 23/09 three 12/12 now from another script i want to read one line at a time ,cut field one and two in two separate variable ,compare field1 with another variable but outside the loop .If i found a match i want to take from user the value... (2 Replies)
Discussion started by: mobydick
2 Replies

4. Shell Programming and Scripting

redirecting std error

Hi, I use the following command make all > output-`date +%F-%H-%M-%S`.txt 2>&1 to invoke a MAKE process that takes some weeks to complete. The ouput is redirected to a text file. Now I prefix the above command with time to get time needed for completion of the MAKE process time make... (2 Replies)
Discussion started by: gkamendje
2 Replies

5. AIX

Redirecting Both to a file and std output

Hello Friends, Can some one help me how to redirect output of a file to both a file and std output? All the help would be greatly appreciated. Regards Sridhar (1 Reply)
Discussion started by: send2sridhar
1 Replies

6. Cybersecurity

What command or script to capture a system snapshot?

Some background on what I am trying to accomplish - Accreditation/Certification for DoD (Unix/Linux) system: I am trying to improve the process for capturing key system information in preparation for performing a formal security review of a Unix or Linux system. This is in addition to the SRR... (1 Reply)
Discussion started by: SecureMe
1 Replies

7. Shell Programming and Scripting

Help with Getopt::Std

I am working on a script that lists files in a directory with a few file attributes depending on what option the user specifies at the command prompt. The script uses Getopt::Std and takes two switches. The first switch allows the user to specify a directory, the second switch gives a long... (3 Replies)
Discussion started by: Breakology
3 Replies

8. Programming

std::reverse_iterator in Sun C++

Hi, I'm having trouble compling the following code in Sun C++ (under sun studio 10). I found that it is issue with libCstd library. It can be resolved if i used stdport lib. However, i have no choice but to use libCstd. Does anyone know what can be done to resolve the issue? :confused: ... (0 Replies)
Discussion started by: shingpui
0 Replies

9. Shell Programming and Scripting

Script to capture date/time in seconds in PERL... Cant understand errors

I'm Using this script to find the time of a file. I'm very much new to PERL and found this script posted by some one on this forum. It runs perfectly fine, just that it gives me following errors with the accurate output as well. I jus want the output to be stored in another file so that i can... (0 Replies)
Discussion started by: bankimmehta
0 Replies

10. Solaris

Camouflage STD IN on output (TRU64)

Hi guys, i have a new problem, even in scripting on KSH. Given a string by standard INPUT (keyboard), i need to replace each character i print with this one '#' . It's to camouflage password while digiting on command line. For example: ---------------------------------- prompt$ ... (3 Replies)
Discussion started by: D4vid
3 Replies
SQLITE_BUSY_TIMEOUT(3)													    SQLITE_BUSY_TIMEOUT(3)

sqlite_busy_timeout - Set busy timeout duration, or disable busy handlers

SYNOPSIS
void sqlite_busy_timeout (resource $dbhandle, int $milliseconds) DESCRIPTION
Object oriented style (method): void SQLiteDatabase::busyTimeout (int $milliseconds) Set the maximum time, in milliseconds, that SQLite will wait for a $dbhandle to become ready for use. PARAMETERS
o $dbhandle - The SQLite Database resource; returned from sqlite_open(3) when used procedurally. This parameter is not required when using the object-oriented method. o $milliseconds - The number of milliseconds. When set to 0, busy handlers will be disabled and SQLite will return immediately with a SQLITE_BUSY status code if another process/thread has the database locked for an update. PHP sets the default busy timeout to be 60 seconds when the database is opened. Note There are one thousand(1000) milliseconds in one second. RETURN VALUES
No value is returned. EXAMPLES
Example #1 Procedural style <?php $dbhandle = sqlite_open('sqlitedb'); sqlite_busy_timeout($dbhandle, 10000); // set timeout to 10 seconds sqlite_busy_timeout($dbhandle, 0); // disable busy handler ?> Example #2 Object oriented style <?php $dbhandle = new SQLiteDatabase('sqlitedb'); $dbhandle->busyTimeout(10000); // 10 seconds $dbhandle->busyTimeout(0); // disable ?> SEE ALSO
sqlite_open(3). PHP Documentation Group SQLITE_BUSY_TIMEOUT(3)
All times are GMT -4. The time now is 08:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy