Getting command output and putting into newfile

Hello All,

I am using the below 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

did you try:

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

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:

#!/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

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.

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

Please read below for detail..

Regards,
Waqas Ahmed

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.

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:

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.

I have a feeling this may have something to do with the amount of data you are attempting to write into the file. If so, it's possible that the resources just aren't there on the box. If you're on a shared vhost the admins could be killing the process off before it completes writing as it may alert as a runaway process. So on that note, I hope your on a managed or doing from your own box at home.

If it is a large amount of data, better to save yourself from having to open that file. My suggestion would be to redirect stderr to an empty file. Then look for broken pipes or another from there.

Hello All,

Below code is giving the same output as this:/omp/bin/TICLI "op:alarm,all" > outputfile.can you please explain what 2>&1 is doing.

/omp/bin/TICLI "op:alarm,all" > outputfile 2>&1

Second Solution:

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

Above code is giving this error on execution:

KarachiOMP root> ./code2
./code2: syntax error at line 5: `OUT=$' unexpected

Can you please find whats the issue.

Third there is no issue of resources as i have the admin rights of the box.

My requirement is to just get complete output of the command in the outputfile.
/omp/bin/TICLI "op:alarm,all" > outputfile

but problem is this that everytime differnet amount of data comes into output file, sometimes only few lines and sometime enough but not complete.

Regards,
Waqas Ahmed

OK "$(command)" is a command expansion technique to get the output of a command into a variable, if your shell does not like that format then you could use:

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

Instead of "$(...)" you use backticks (not single quotes) like `...`

By "resources" I believe phpfreak is referring to physical resources NOT permissions.

You could be limited by memory, cpu, file handles, drive space, etc...

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

I used the above code and it is also not giving the complete output, second it is also changing the output format.

i also want to share one more thing. That we have one log folder in which our logs files are maintained on daily basis. Every command we run on TICLI shell that command's output also goes into that logs files.

So whenever i run my script so it do not gives complete output, but in log file complete output of the command comes.

Any idea how that happens, but why its not happening through my script.

Actually "op:alarm,all" takes time for giving complete output. Those commands which output is not very large are working properly with my script but because "op:alarm,all" command takes time for output, the complete output is not coming through script.

That is because you need to quote the "$OUT" variable as follows:

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

Note:

echoing a variable that has newlines in the variable contents can cause all \n (newline) characters to be stripped out when not quoting.

Is "/omp/bin/TICLI" a compiled application? Does it call a compiled application? What you may be running into is that the code inside the compiled application is told to output MORE info to a log than what it does on the command line. If that is the case you may be unable to change this without editing the source code to that application and re-compiling.

Okay is there is someway that i run the command on TICLI "op:alarm,all"
and at the sametime try to grep the output of that command through log file.

The output of the command is something like this:

     CELL 3 PACKET PIPE (PP) 3
     CELL 3, CDM 1 CBR 3 TRANSMIT PORT (TXPORT) 1

     CELL 4 PACKET PIPE (PP) 1

     CELL 5 RECEIVE AMPLIFIER FAILURE 4
     CELL 5 RECEIVE AMPLIFIER FAILURE 6

     CELL 6 RECEIVE AMPLIFIER FAILURE 2

     CELL 7 TIME FREQUENCY UNIT (TFU) 1
     CELL 7 TEST AND DIAGNOSTIC UNIT 2
     CELL 7, CDM 1 PRIMARY SIGNALING LINK
     CELL 7, CDM 1 ALTERNATE SIGNALING LINK
     CELL 7 PACKET PIPE (PP) 2
     CELL 7 PACKET PIPE (PP) 3
     CELL 7 PACKET PIPE (PP) 4
     CELL 7 CDMA RADIO CONTROLLER (CRC) 1
     CELL 7, CDM 1 CDMA BASEBAND RADIO (CBR) 1
     CELL 7, CDM 1 CDMA BASEBAND RADIO (CBR) 2
     CELL 7, CDM 1 CDMA BASEBAND RADIO (CBR) 3
     CELL 7, CDM 1 CBR 1 TRANSMIT PORT (TXPORT) 1
     CELL 7, CDM 1 CBR 2 TRANSMIT PORT (TXPORT) 1
     CELL 7, CDM 1 CBR 3 TRANSMIT PORT (TXPORT) 1
     CELL 7, CDM 1 CBR 1 TRANSMIT PORT (TXPORT) 2
     CELL 7, CDM 1 CBR 2 TRANSMIT PORT (TXPORT) 2

But it will be little hard to get the exact output as command through log files as log file contain lots of data of others commands too.

What is the possibility and from where i start?

background the TICLI "op:alarm,all" comand and tail the log file?

TICLI "op:alarm,all" &
tail -f /path/to/log |grep ^CEL\s.*$

Not sure if that is quite what you mean but there are MANY ways to do this, this is just one way.

Hello All,

#/bin/ksh
/omp/bin/TICLI "op:alarm,all" &
tail -f /omp/omp-data/logs/OMPROP1/081206.APX | grep "CELL" > all

Now i am using the above code to run the command (op:alarm,all) on TICLI shell, and then trying to grep the output of command through the log file and then putting it into output file.
But now my question is that how i will stop the script when the output of the command will finish. I mean how i can make the script intelligent enough to stop giving output in the output file. And there is one more problem that because i am using grep on LOG file so it will also grep many other unwanted things.

Regards,
Waqas Ahmed

If the above gives you all the output then try this;

#/bin/ksh
/omp/bin/TICLI "op:alarm,all" &
wait $!
tail -n 100 /omp/omp-data/logs/OMPROP1/081206.APX | grep "CELL" > all

This will wait until the background process is finished and then output all log entries that have "CELL" in them in the last 100 lines of the log.

deleted