Sponsored Content
Top Forums Shell Programming and Scripting Capture std out snapshot after 15 seconds Post 302993604 by Aia on Saturday 11th of March 2017 09:13:02 PM
Old 03-11-2017
Quote:
Originally Posted by Riker1204
I have a program that scans and updates its results to std out every second. I would like to capture its output for further processing, but there is a catch. I would like to capture a snapshot after about 15 seconds as the results become more accurate and close the program.
Obviously I can simply use > temp_file which I can use by grabbing the last n lines, and close the program after 15 seconds but surely there is a better way?

Just looking for a general idea to get me in the right direction.

TLDR: Is there a way to capture the std out of a program directly before it closes?
Code:
#!/bin/bash
program > program.log 2>&1 &
pid=$!
for s in {1..15}
do
  sleep 1
done
kill $pid

This User Gave Thanks to Aia 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
EDITCAP(1)						   The Ethereal Network Analyzer						EDITCAP(1)

NAME
editcap - Edit and/or translate the format of capture files SYNOPSYS
editcap [ -F file format ] [ -T encapsulation type ] [ -r ] [ -v ] [ -s snaplen ] [ -t time adjustment ] [ -h ] infile outfile [ record# ... ] DESCRIPTION
Editcap is a program that reads a saved capture file and writes some or all of the packets in that capture file to another capture file. Editcap knows how to read libpcap capture files, including those of tcpdump, Ethereal, and other tools that write captures in that format. In addition, Editcap can read capture files from snoop and atmsnoop, Shomiti/Finisar Surveyor, Novell LANalyzer, Network General/Network Associates DOS-based Sniffer (compressed or uncompressed), Microsoft Network Monitor, AIX's iptrace, Cinco Networks NetXRay, Network Asso- ciates Windows-based Sniffer, AG Group/WildPackets EtherPeek/TokenPeek/AiroPeek, RADCOM's WAN/LAN analyzer, Lucent/Ascend router debug out- put, HP-UX's nettl, the dump output from Toshiba's ISDN routers, the output from i4btrace from the ISDN4BSD project, the output in IPLog format from the Cisco Secure Intrusion Detection System, pppd logs (pppdump format), the output from VMS's TCPIPtrace utility, the text output from the DBS Etherwatch VMS utility, traffic capture files from Visual Networks' Visual UpTime and the output from CoSine L2 debug. There is no need to tell Editcap what type of file you are reading; it will determine the file type by itself. Editcap is also capable of reading any of these file formats if they are compressed using gzip. Editcap recognizes this directly from the file; the '.gz' extension is not required for this purpose. By default, it writes the capture file in libpcap format, and writes all of the packets in the capture file to the output file. The -F flag can be used to specify the format in which to write the capture file; it can write the file in libpcap format (standard libpcap for- mat, a modified format used by some patched versions of libpcap, the format used by Red Hat Linux 6.1, or the format used by SuSE Linux 6.3), snoop format, uncompressed Sniffer format, Microsoft Network Monitor 1.x format, the format used by Windows-based versions of the Sniffer software, and the format used by Visual Networks' software. A list of packet numbers can be specified on the command line; the packets with those numbers will not be written to the capture file, unless the -r flag is specified, in which case only those packets will be written to the capture file. Ranges of packet numbers can be specified as start-end, referring to all packets from start to end (removing them all if -r isn't specified, including them all if -r is specified). If the -s flag is used to specify a snapshot length, frames in the input file with more captured data than the specified snapshot length will have only the amount of data specified by the snapshot length written to the output file. This may be useful if the program that is to read the output file cannot handle packets larger than a certain size (for example, the versions of snoop in Solaris 2.5.1 and Solaris 2.6 appear to reject Ethernet frames larger than the standard Ethernet MTU, making them incapable of handling gigabit Ethernet captures if jumbo frames were used). If the -t flag is used to specify a time adjustment, the specified adjustment will be applied to all selected frames in the capture file. The adjustment is specified as [-]seconds[.fractional seconds]. For example, -t 3600 advances the timestamp on selected frames by one hour while -t -0.5 reduces the timestamp on selected frames by one-half second. This feature is useful when synchronizing dumps collected on different machines where the time difference between the two machines is known or can be estimated. If the -T flag is used to specify an encapsulation type, the encapsulation type of the output capture file will be forced to the specified type, rather than being the type appropriate to the encapsulation type of the input capture file. Note that this merely forces the encap- sulation type of the output file to be the specified type; the packet headers of the packets will not be translated from the encapsulation type of the input capture file to the specified encapsulation type (for example, it will not translate an Ethernet capture to an FDDI cap- ture if an Ethernet capture is read and '-T fddi' is specified). OPTIONS
-F Sets the file format of the output capture file. -T Sets the packet encapsulation type of the output capture file. -r Causes the packets whose packet numbers are specified on the command line to be written to the output capture file, and no other pack- ets to be written to the output capture file. -v Causes editcap to print a number of messages while it's working. -s Sets the snapshot length to use when writing the data. -t Sets the time adjustment to use on selected frames. -h Prints the version and options and exits. SEE ALSO
tcpdump(8), pcap(3), ethereal(1), mergecap(1) NOTES
Editcap is part of the Ethereal distribution. The latest version of Ethereal can be found at http://www.ethereal.com. AUTHORS
Original Author -------- ------ Richard Sharpe <sharpe@ns.aus.com> Contributors ------------ Guy Harris <guy@alum.mit.edu> 0.9.8 2002-08-08 EDITCAP(1)
All times are GMT -4. The time now is 03:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy