Sponsored Content
Top Forums Shell Programming and Scripting Switching stdout redirection on-the-fly Post 302229096 by aigles on Tuesday 26th of August 2008 07:36:38 AM
Old 08-26-2008
You can try the technique used in the following script (where a function simulates the program) :
Code:
program() {
   while (( count++ <= 60 ))
   do
      date +"$count %Y%d%d %H%M%S"
      sleep $(( $RANDOM % 10 ))
   done
}

initial_sec=$SECONDS
program |
while IFS= read line
do
   sec=$SECONDS
   (( min = (sec - initial_sec) / 60 + 1 ))
   out=$min.txt
   echo "$line" >> $out
done

Code:
> ls *.txt
/bin/ls: cannot access *.txt: No such file or directory
> date; sky.sh; date
Tue Aug 26 13:28:44     2008
Tue Aug 26 13:33:24     2008
> ls -l *.txt
-rw-r--r-- 1 Jean-Pierre Aucun 276 Aug 26 13:29 1.txt
-rw-r--r-- 1 Jean-Pierre Aucun 209 Aug 26 13:30 2.txt
-rw-r--r-- 1 Jean-Pierre Aucun 209 Aug 26 13:31 3.txt
-rw-r--r-- 1 Jean-Pierre Aucun 285 Aug 26 13:32 4.txt
-rw-r--r-- 1 Jean-Pierre Aucun 171 Aug 26 13:33 5.txt
> cat 1.txt
1 20082626 132844
2 20082626 132845
3 20082626 132854
4 20082626 132858
5 20082626 132900
6 20082626 132903
7 20082626 132905
8 20082626 132910
9 20082626 132918
10 20082626 132920
11 20082626 132922
12 20082626 132926
13 20082626 132928
14 20082626 132934
15 20082626 132940
> cat 5.txt
53 20082626 133243
54 20082626 133253
55 20082626 133254
56 20082626 133300
57 20082626 133301
58 20082626 133306
59 20082626 133310
60 20082626 133310
61 20082626 133319
>

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Rename files on the fly

Hi everyone, I am sort of new to shell scripting, I have a bunch of files that begin with 'blah' and I want to rename those files with something different (renamedFile1, renamedFile2, renamedFileN). I don't want to go through each file and rename them with the mv command. Could I just use a for... (4 Replies)
Discussion started by: kcor
4 Replies

2. UNIX for Dummies Questions & Answers

mv and compress on the fly

I want to move and compress a big export file. Like mv file_exp /filesystem/file_exp |compress The file system is too small to compress and move with 2 steps. What is the best command for me. I'm running solaris. :confused: (1 Reply)
Discussion started by: simquest
1 Replies

3. Shell Programming and Scripting

Grep logs on the fly

Hi, We use an application that is dumping logs to a file on disk. However, this is dumping very verbosely and there is no method of turning down the logging level. We need to remove certain contents from these before they are commited to disk. Has anybody got any ideas how I can do this... (3 Replies)
Discussion started by: harperonline
3 Replies

4. Shell Programming and Scripting

Read Files on the Fly

Hi, I am creating files in a folder on the fly with arbritrary names but same extension (say, ".img"). How can I read each filename from the folder through a script. regards Angshuman (2 Replies)
Discussion started by: angshuman_ag
2 Replies

5. What is on Your Mind?

The Only Way To Fly !

This is great! Lqh8e2KYIrU (8 Replies)
Discussion started by: Neo
8 Replies

6. Shell Programming and Scripting

STDOUT and STDERR redirection within a script

Hello all, I have a for loop executing in a script that I want to redirect STDOUT to screen and to file, while directing STDERR to the bit bucket. Here is the general sentax of what I'm doing: for i in thingy do some_command ${i} done 1>&1 | tee ${LOGFILE} 2> /dev/null What I am... (2 Replies)
Discussion started by: LinuxRacr
2 Replies

7. Shell Programming and Scripting

stdout, stderr redirection

Hi all, can someone help me with the next redirection? i want to redirect the stdout+stderr of a command to the same file (this i can do by prog &> file) but in addition i want to redirect only the stderr to a different file. how can i do this please? (in BASH) thanks. (4 Replies)
Discussion started by: eee
4 Replies

8. HP-UX

Compress dbexport on the fly

Hi, I have an old HPUX 10.20 server running Informix 7.23 I need to dump the database to get it off that hardware before it dies. Unfortunately there is insufficient local diskspace to do so. I have set up a linux box with sufficient disk onto which I can export the database. Having... (1 Reply)
Discussion started by: fella
1 Replies

9. OS X (Apple)

Creating An Executable On The Fly...

Hi all... Had an idea tonight which could really enhance shell scripting for me. Yes I am aware there could be difficulties but...... Creating a C script inside the shell script to do a task, (a simple text print to stdout in this example), compiling it on the fly, making sure it is... (4 Replies)
Discussion started by: wisecracker
4 Replies

10. Shell Programming and Scripting

Execute script on the fly

Hi all, I am calling a zsh script from batch file . This zsh just removes the trigger file in a particular directory.File name is passed as a parameter from the batch file Problem is this batch is called in multiple other batch files and sometimes system says file cant be used as it is used... (4 Replies)
Discussion started by: Hypesslearner
4 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a file name containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 05:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy