Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Read data from given filename or stream Post 302588117 by curleb on Friday 6th of January 2012 07:16:01 PM
Old 01-06-2012
You'd really need to base it upon some evaluation that you can control. You'd test the inputs, and based on behavior, you'd fork off in whatever direction you need. The following function provides a similar test for logging purposes (with some additional chatter for documentation purposes):

Code:
function LOG
{
 #  Takes positional args or pipes...and print verbatim
  #     -  eg:   LOG   $(date )
  #              LOG   "something happening here... "
  #              echo  "something happened - $(date )" |LOG

  #  Passive assignment of Debugging var...
  ${_dbg_mode:-}

  #  Arg count >0 means args given...
  if    [[ $# -gt 0 ]]
  then
     #  If $MY_LOG is defined...
     if    [[ -n "${MY_LOG}" ]] \
        && [[ -f "${MY_LOG}" ]]
     then
        #  tee to $MY_LOG...
        print "${@}" >&1 2>/dev/null |tee -a "${MY_LOG}"
     else
        #  just echo to screen...
        print "${@}" >&1 2>/dev/null
     fi
  #  No args means we're probably piping...
  else
     #  If $MY_LOG is defined...
     if    [[ -n "${MY_LOG}" ]] \
        && [[ -f "${MY_LOG}" ]]
     then
        #  tee to $MY_LOG...
        read     P
        print "${P}" >&1 2>/dev/null |tee -a "${MY_LOG}"
     else
        #  just echo to screen...
        read     P
        print "${P}" >&1 2>/dev/null
     fi
  fi
}

This User Gave Thanks to curleb For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Stream Read And Write Queues

Is there any possibility that a Stream Read and Write queues will interchange messages of any kind. If so what are the different possiblites and under what circumstances ? Thanks in advance. (4 Replies)
Discussion started by: S.P.Prasad
4 Replies

2. Shell Programming and Scripting

read a part of filename from the list in the script

how can i read a part of filename from the list in the script? all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number. CDBACKUPFILEJOHN00001 CDBACKUPFILEMARRY00004 CDBACKUPFILEPETER00003 I will use:... (3 Replies)
Discussion started by: happyv
3 Replies

3. UNIX for Advanced & Expert Users

how to read the data from an excel sheet and use those data as variable in the unix c

I have 3 columns in an excel sheet. c1 c2 c3 EIP_ACCOUNT SMALL_TS_01 select A.* from acc; All the above 3 col shoud be passed a variable in the unix code. 1.How to read an excel file 2.How to pass these data as variable to the unic script (1 Reply)
Discussion started by: Anne Grace
1 Replies

4. Shell Programming and Scripting

Breaking down a Serial data stream

I'm running Debian ib Bash shell. currently I'm streaming the data from ttyS1 . The data stream is 13 fields comma delimited cat /dev/ttyS1 02/04/2009,10:57:18,1401.0,7.5,424.9,0.0,0.0,159.8,1401.0,7.5,265.2,34.4,2.5 The data is grouped for specific systems. 02/04/2009,10:57:18 ... (1 Reply)
Discussion started by: Mikey
1 Replies

5. Shell Programming and Scripting

read mp3 filename and create one XML for each file

Hi: I have a collection of mp3s and I need to create 1 xml file per mp3. I have: recording1.mp3 recording2.mp3 etc and I want to generate this kind of files. recording1.xml recording2.xml and inside each xml file I need to add a url prefix and then the filename at the end. ... (4 Replies)
Discussion started by: jason7
4 Replies

6. Programming

read() blocks process until the stream is closed

Hi @all, i really stuck in programming a tool with bidirectional process communication (popen(cmd, "rw") ... something like that ;-)). Here is the code: if(pipe(p_stdin) != 0 || pipe(p_stdout) != 0) { fprintf(stderr, "Aufruf von pipe() schlug fehl.\n"); exit(1); } ... (6 Replies)
Discussion started by: jens.g
6 Replies

7. Shell Programming and Scripting

[Video stream] network stream recording with mplayer

Hi I used this command: mplayer http://host/axis-cgi/mjpg/video.cgi -user root -passwd root \ -cache 1024 -fps 25.0 -nosound -vc ffh264 \ -demuxer 3 -dumpstream -dumpfile output.avi It's ok but... Video Playing is very fast! Why? Is it a synch problem? What parameter I have to use for... (1 Reply)
Discussion started by: takeo.kikuta
1 Replies

8. Shell Programming and Scripting

Data stream between min and max

Hi, I have a text file containing numbers. There are up to 6 numbers per row and I need to read them, check if they are 0 and if they are not zero check if they are within a given interval (min,max). If they exceed the max or min they should be set to max or min respectively, if they are in the... (4 Replies)
Discussion started by: f_o_555
4 Replies

9. Shell Programming and Scripting

Extract & Manipulate continous data stream-- tcpdump

Hello; I have this rather tricky problem to solve --(to me, anyways) .. I am processing the following one liner with tcpdump.. tcpdump -i T3501 -A ether host 00:1e:49:29:fc:c9 or ether host 00:1b:2b:86:ec:1b or ether host 00:21:1c:98:a4:08 and net 149.83.6.0/24 | grep --line-buffered -B... (5 Replies)
Discussion started by: delphys
5 Replies

10. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies
fclose(3S)																fclose(3S)

NAME
fclose(), fflush(), fclose_unlocked(), fflush_unlocked() - close or flush a stream SYNOPSIS
Obsolescent Interfaces DESCRIPTION
causes any buffered data for the named stream to be written out, and the stream to be closed. Buffers allocated by the standard input/out- put system may be freed. is performed automatically for all open files upon calling exit(2). If stream points to an output stream or an update stream in which the most recent operation was output, causes any buffered data for the stream to be written to that file; otherwise any buffered data is discarded. The stream remains open. If stream is a null pointer, performs this flushing action on all currently open streams. Obsolescent Interfaces and close or flush a stream. RETURN VALUE
Upon successful completion, and return 0. Otherwise, they return EOF and set to indicate the error. ERRORS
If or fails, is set to one of: The flag is set for the file descriptor underlying stream and the process would be delayed in the write operation. The file descriptor underlying stream is not valid. An attempt was made to write a file that exceeds the process's file size limit or the maximum file size (see ulimit(2)). or was interrupted by a signal. The process is in a background process group and is attempting to write to its controlling terminal, is set, the process is neither ignoring nor blocking the signal, and the process group of the process is orphaned. There was no free space remaining on the device containing the file. An attempt was made to write to a pipe that is not open for reading by any process. A signal is also sent to the process. Additional values may be set by the underlying and functions (see write(2), lseek(2) and close(2)). WARNINGS
and are obsolescent interfaces supported only for compatibility with existing DCE applications. New multithreaded applications should use and SEE ALSO
close(2), exit(2), lseek(2), write(2), flockfile(3S), fopen(3S), setbuf(3S), thread_safety(5). STANDARDS CONFORMANCE
fclose(3S)
All times are GMT -4. The time now is 05:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy