Getting command output and putting into newfile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting command output and putting into newfile
# 1  
Old 12-04-2008
Getting command output and putting into newfile

Hello All,

I am using the below code:
Code:
#!/bin/sh
/omp/bin/TICLI "op:alarm,all" > filename

for getting command output and then putting the output into newfile but the problem is this, that not the complete output goes into newfile and the script stops.
for example: if this commands gives this output
cell 1
cell 2
cell 3
cell 4

but the newfile contains only this:
cell 1
cell 2

Please tell how i can get the complete output.

Regards,
Waqas Ahmed
# 2  
Old 12-04-2008
did you try:

Code:
#!/bin/sh
/omp/bin/TICLI "op:alarm,all" | cat > filename

# 3  
Old 12-04-2008
I am rephrasing the same question for more explanation:

Actually i run one command and i want command's output in newfile.

For this i am using below code:
Code:
#!/bin/sh
/omp/bin/TICLI "op:alarm,all" > outputfile

But problem is this that this command: op:alarm,all takes time for output but the script stops without giving the complete output in outputfile.

For Example: if this commands gives this output:
cell 1
cell 2
cell 3
cell 4

but the output file contains only this:
cell 1
cell 2

Please tell how i can get the complete output in output file.

Regards,
Waqas Ahmed
# 4  
Old 12-04-2008
Command Output into newfile

No, the below code is still not working correctly, the output file do not contain the complete output of the command.

Actually this command takes time to generate ouput, so is there someway that the script do not ends until the complete output of the command is redirected to the output file.

Code:
#!/bin/sh
/omp/bin/TICLI "op:alarm,all" | cat > filename

Please read below for detail..

Regards,
Waqas Ahmed
# 5  
Old 12-04-2008
Hi! There maybe a way but we will find out until you post the code of that certain command.. otherwise we will not see what is really going with your script/command.
# 6  
Old 12-05-2008
worth redirecting as follows ?
/omp/bin/TICLI "op:alarm,all" > outputfile 2>&1
# 7  
Old 12-05-2008
Quote:
Originally Posted by manikantants
worth redirecting as follows ?
/omp/bin/TICLI "op:alarm,all" > outputfile 2>&1

agreed, I suspect that some of that output may be stderr and not regular stdout. The "2>&1" will catch ALL output (stderr & stdout) and send to the output file.

On that note, another method would be:

Code:
OUT=$(/omp/bin/TICLI "op:alarm,all") && echo $OUT > outputfile

This will wait until the command finshes with a return code of 0 and only then echo the variable $OUT to your file.

Last edited by ddreggors; 12-05-2008 at 04:43 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies

2. Shell Programming and Scripting

Need help putting output on one line

Good afternoon, I have been searching the web, and these forums for help. I will try my best to explain the issue, and what my desired results are. I am doing queries in MYSQL, and need the output to be sent to a file. That file needs to have things with the same ID on the same line. To... (14 Replies)
Discussion started by: brianjb
14 Replies

3. UNIX for Dummies Questions & Answers

Putting the Current -date in the Output File

Hi guys, Just want to ask how can I make a script that will perform like this. 1. Execute the command 2. Then the output of the command will be redirected to a file 2. The file that has been created will have a date on it equivalent to the date and time it was created (or maybe after the... (5 Replies)
Discussion started by: rymnd_12345
5 Replies

4. Shell Programming and Scripting

putting color on output file script

do you have any simple script on how to change the color and font of a string in a script example echo "====================================" echo " sample color script" echo "====================================" echo " hello " echo " bye" on hello,... (3 Replies)
Discussion started by: lhareigh890
3 Replies

5. Shell Programming and Scripting

Putting echo output as input to stat

I have a string with escape differentiators as a result of searching for a file using find. Essentially find returned to my shell variable several absolute paths each ending with the file name and each path/file separated by \n. Echo recognizes the escape sequence and is able to print the paths... (3 Replies)
Discussion started by: Ebodee
3 Replies

6. Shell Programming and Scripting

How to redirect the output to multiple files without putting on console

How to redirect the output to multiple files without putting on console I tried tee but it writes to STDOUT , which I do not want. Test.sh ------------------ #!/bin/ksh echo "Hello " tee -a file1 file2 ---------------------------- $>./Test.sh $> Expected output: -------------------... (2 Replies)
Discussion started by: prashant43
2 Replies

7. Shell Programming and Scripting

sed *.csv from file > newfile with /n

I have a an output file with a format: something blah1.csv blah2.csv blah3.csv somethingelse and I'm trying to use sed to pull all the *.csv entries out and put them 1 per line on a new file. I can't quite figure out how to write them to a new file with carriage returns, is there a simple way... (8 Replies)
Discussion started by: unclecameron
8 Replies

8. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

9. Shell Programming and Scripting

How to compare 2 file to newfile......

Hi all Member i want compare 2 file to newfile I am new to shell script, just wanted you guy to help. example file A CM-00000BN_Oth-VAS-0000392 CM-00000BNSEED_Oth-Spe-0000392 CM-00000KJ_Pos-Pro-0000806 CM-00000KJ_Pos-Pro-0000810 CM-00000KJ_Pos-Pro-0000812 CM-00000KJ_Pos-Pro-0000814... (1 Reply)
Discussion started by: ooilinlove
1 Replies

10. Shell Programming and Scripting

Putting screen output in a log file

I want to output screen messages to a logfile when executing an automated script. I have tried the script and command to do this but with no luck. Thanks, Nicole (5 Replies)
Discussion started by: nsutti
5 Replies
Login or Register to Ask a Question