My chain command: mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py;
- Redirect
stdout
andstderr
ofmyscript.py
tolog.txt
.
$ mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1 | tee log.txt
$ cat log.txt
stdout and stderr are shown here.
- Insert the chain command to the beginning of
log.txt
.
$ echo 'mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1' | tee log.txt | bash >> log.txt
$ cat log.txt
mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1
stdout and stderr are shown here.
- Time the command
$ (time python3 mydir/myscript.py) 2> log.txt
$ cat log.txt
real 0m0,302s
user 0m0,003s
sys 0m0,001s
My question is how to concatenate 3 items above so the log.txt
looks like
mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1
stdout and stderr are shown here.
real 0m0,302s
user 0m0,003s
sys 0m0,001s
Thanks.
CodePudding user response:
After some tries and errors, I think the following code is working.
(time echo 'mkdir mydir; mv myscript.py mydir/; python3 mydir/myscript.py 2>&1' | tee log.txt | bash >> log.txt) 2>> log.txt