print the output of strace command in a text file - linux

I need to write the result of below command to a text file but this command doesn't work and when using cat output.txt show me nothing.
could please help me to correct the problem?
strace -r -y -e read Program -l -o output.txt
thanks

For future reference, I think the person should have ran it like this:
strace -o outputfile.txt ./Program

Related

bzip command not working with "tee -a"

I want to redirect stdop of bzip command to logfile using tee command but its not working and giving error for '-a' in tee command. Please see error below,
> bzip2 file -c 1> tee -a logfile
bzip2: Bad flag `-a'
bzip2, a block-sorting file compressor. Version 1.0.5, 10-Dec-2007.
usage: bzip2 [flags and input files in any order]
-h --help print this message
-d --decompress force decompression
-z --compress force compression
-k --keep keep (don't delete) input files
-f --force overwrite existing output files
-t --test test compressed file integrity
-c --stdout output to standard out
-q --quiet suppress noncritical error messages
-v --verbose be verbose (a 2nd -v gives more)
-L --license display software version & license
-V --version display software version & license
-s --small use less memory (at most 2500k)
-1 .. -9 set block size to 100k .. 900k
--fast alias for -1
--best alias for -9
If invoked as `bzip2', default action is to compress.
as `bunzip2', default action is to decompress.
as `bzcat', default action is to decompress to stdout.
If no file names are given, bzip2 compresses or decompresses
from standard input to standard output. You can combine
short flags, so `-v -4' means the same as -v4 or -4v, &c.
What is the issue? why bzip is considering the '-a' flag of tee command.
Try:
bzip2 -c file | tee -a logfile
The | (pipe) is redirecting the stdout of the left command to the stdin of the right command.
-c is is an option from bzip2 that says Compress or decompress to standard output.. see man bzip2
Your problem is that 1>does not pipe output of the bzip2 command to the tee command, but instead redirects the output to a file which will be named tee. Furthermore you probably don't want to use -c. You should be using the pipe | instead, as follows:
bzip2 file | tee -a logfile
Also, the reason why bzip2 is complaining is because the command as you mentioned above will be interpreted exactly as this one:
bzip2 file -a logfile 1> tee
And hence all arguments after the teeare actually added to the bzip2 command.
As others have pointed out, you want a pipe, not output redirection:
bzip2 file | tee -a logfile
However, bzip2 doesn't produce any output; it simply replaces the given file with a compressed version of the file. You might want to pipe standard error to the log file:
bzip2 file 2>&1 | tee -a logfile
(2>&1 copies standard error to standard output, which can then be piped.)

execute cygwin sort command from batch file

I am trying to run the sort command from a batch file to take the lines from new.txt and output them into unique.txt
C:\cygwin64\bin\bash -c "sort -u new.txt > unique.txt"
This is not working
However, if I place new.txt into the home/Administrator directory and run the command in the terminal it works just fine.
wrote a script:
#!/bin/bash
sort -u /home/Administrator/new.txt > unique.txt
batch file:
set PATH=C:\cygwin64\bin;%PATH%
c:\cygwin64\bin\bash.exe /usr/bin/u.sh
all good :)
Or you can do it directly from cmd without using bash:
C:\cygwin64\bin\sort -u new.txt > unique.txt

scp output as logfile

I am relatively new to using scp - and I am trying to do some simple stuff over ec2 - something like the following:
scp -i ec2key.pem username#ec2ip:/path/to/file ~/path/to/dest/folder/file
What I would like to have is the log of the above command (i.e the screen output to a text file) - Is there a way to achieve this?
Thanks.
You can redirect both outputs (stdout, stderr) of the command with &> provided you use the verbose (-v) argument. Otherwise, scp will suppress the output as it expects its stdout to be connected to a terminal. But then you get too much information, which you can get rid of with grep:
scp -v -i ec2key.pem username#ec2ip:/path/to/file ~/path/to/dest/folder/file |& grep -v ^debug > file.log
If you want to have the output both to the screen and the file, use tee
scp -v -i ec2key.pem username#ec2ip:/path/to/file ~/path/to/dest/folder/file |& grep -v ^ debug tee file.log
scp -v -i ec2key.pem username#ec2ip:/p/t/file ~/p/t/d/f/file >> something.log 2>&1
-v and 2>&1 will append your extended details (i.e. debug info) in the existing something.log file.
How about (untested, compressing /path/to for readability):
(scp -i ec2key.pem username#ec2ip:/p/t/file ~/p/t/d/f/file ) 2>/p/t/textfile

how to redirect result of linux time command to some file

I'm running the following command (on Ubuntu)
time wget 'http://localhost:8080/upLoading.jsp' --timeout=0
and get a result in the command line
real 0m0.042s
user 0m0.000s
sys 0m0.000s
I've tried the following:
time -a o.txt wget 'http://localhost:8080/upLoading.jsp' --timeout=0
and get the following error
-a: command not found
I want to get the result to be redirected to some file. How can I do that?
-a is only understood by the time binary (/usr/bin/time), When just using time you're using the bash built-in version which does not process the -a option, and hence tries to run it as a command.
/usr/bin/time -o foo.txt -a wget 'http://localhost:8080/upLoading.jsp' --timeout=0
Checking man time, I guess what you need is
time -o o.txt -a ...
(Note you need both -a and -o).
[EDIT:] If you are in bash, you must also take care to write
/usr/bin/time
(check manpage for explanation)
You can direct the stdout output of any commmand to a file using the > character.
To append the output to a file use >>
Note that unless done explicitly, output to stderr will still go to the console. To direct both stderr and stdout to the same output stream use
command 2>&1 outfile.txt (with bash)
or
command >& outfile.txt (with t/csh)
If you are working with bash All about redirection will give you more details and control about redirection.
\time 2> time.out.text command
\time -o time.out.text command
This answer based on earlier comments. It is tested it works. The advantage of the \ over /usr/bin/ is that you don't have to know the install directory of time.
These answers also only capture the time, not other output.
Exactly the time from GNU writes it's output to stderr and if you want to redirect it to file, you can use --output=PATH parameter of time
See this http://unixhelp.ed.ac.uk/CGI/man-cgi?time
And if you want to redirect stdout to some file, you can use > filename to create file and fill it or >> filename to append to some file after the initial command.
If you want to redirect stderr by yourself, you can use $ command >&2 your_stderr_output
Try to use /usr/bin/time since many shells have their own implementation of time which may or may not support the same flags as /usr/bin/time
so change your command to
/usr/bin/time -a -o foo.txt wget ....
How about your LANG ?
$ time -ao o.txt echo 1
bash: -ao: コマンドが見つかりません
real 0m0.001s
user 0m0.000s
sys 0m0.000s
$ export|grep LANG
declare -x LANG="ja_JP.utf8"
$ LANG=C time -ao o.txt echo 1
1
$ cat o.txt
0.00user 0.00system 0:00.00elapsed 0%CPU (0avgtext+0avgdata 1984maxresident)k
0inputs+0outputs (0major+158minor)pagefaults 0swaps
Try:
command 2> log.txt
and the real-time output from "command" can be seen in another console window with:
tail -f log.txt
This worked for me:
( time command ) |& tee output.txt
https://unix.stackexchange.com/questions/115980/how-can-i-redirect-time-output-and-command-output-to-the-same-pipe
You can do that with > if you want to redirect the output.
For example:
time wget 'http://localhost:8080/upLoading.jsp' --timeout=0 > output.txt 2>&1
2>&1 says to redirect STDERR to the same file.
This command will erase any output.txt files and creates a new one with your output. If you use >> it will append the output at the end of any existing output.txt file. If it doesn't exist, it will create it.

JMeter command line: Can I output the run log to STDOUT?

I just want the JMeter run log (-l parameter) piped to STDOUT for processing in a script, is there an easy way to do this? Using /tmp files is so icky.
didn't try it, but may be JMeter -l /dev/stdout will help?
Maybe you can try mkfifo:
$ mkfifo log.txt
$ cat log.txt | ./script.sh
$ JMeter -l log.txt
This worked for me -j /dev/stdout as per this solution:
https://stackoverflow.com/a/71508222/2303693

Resources