"화면"(프로그램) 출력을 파일에 저장
screen
나중에 모든 내용을 확인 하기 위해의 전체 출력을 파일 에 저장해야합니다 .
그 이유는 화면을 사용하여 인터페이스를 사용하여 직렬 포트를 통해 플래시 메모리를 덤프하고 있기 때문입니다.
메모리 구조를 확인하기 위해 파일에 저장하고 싶습니다.
난 노력 했어 :
$: screen /dev/ttyUSB0 115200 >> foo.txt
$: screen /dev/ttyUSB0 115200 | tee foo.txt
화면에서 bufferfile을 사용하려고했지만 사용 방법을 모르겠습니다.
쉬운 방법이 있습니까?
로깅을위한 명령 줄 옵션이 있습니다. 출력은 screenlog.n 파일에 저장됩니다. 여기서 n은 화면 번호입니다. 화면의 맨 페이지에서 :
'-L'화면에 창에 대한 자동 출력 로깅을 켜도록 지시합니다.
Control-a + H를 사용하여 screenlog.n 파일에 로깅을 저장할 수도 있습니다. 끄려면 Control-a + H를 하나 더 누르십시오.
Ca H : "screenlog.n"파일에 현재 창의 로깅을 시작 / 종료합니다.
선택한 답변은 여러 세션에서 잘 작동하지 않으며 사용자 지정 로그 파일 이름을 지정할 수 없습니다.
여러 화면 세션의 경우 이것은 내 공식입니다.
1) 각 프로세스에 대한 구성 파일을 만듭니다.
logfile test.log
logfile flush 1
log on
logtstamp after 1
logtstamp string "[ %t: %Y-%m-%d %c:%s ]\012"
logtstamp on
"즉석에서"수행하려면 logfile
자동으로 변경할 수 있습니다 . \012
사용 \n
하면 로그 파일 source 에 인쇄하므로 "새 줄"을 의미 합니다 .
2) "-c"및 "-L"플래그로 명령을 시작하십시오.
screen -c ./test.conf -dmSL 'Test' ./test.pl
그게 다야. 첫 번째 플러시 후에 "test.log"가 표시됩니다.
...
6 Something is happening...
[ test.pl: 2016-06-01 13:02:53 ]
7 Something else...
[ test.pl: 2016-06-01 13:02:54 ]
8 Nothing here
[ test.pl: 2016-06-01 13:02:55 ]
9 Something is happening...
[ test.pl: 2016-06-01 13:02:56 ]
10 Something else...
[ test.pl: 2016-06-01 13:02:57 ]
11 Nothing here
[ test.pl: 2016-06-01 13:02:58 ]
...
구성 파일에 "로그온"이있는 경우에도 "-L"이 여전히 필요하다는 것을 알았습니다.
화면에서 사용하는 시간 형식 변수 (예 : % m) 목록을 찾을 수 없습니다. 이러한 형식의 링크가 있으면 아래에 게시하십시오.
** 추가 **
"즉시"수행하려는 경우 다음 스크립트를 사용할 수 있습니다.
#!/bin/bash
if [[ $2 == "" ]]; then
echo "Usage: $0 name command";
exit 1;
fi
name=$1
command=$2
path="/var/log";
config="logfile ${path}/${name}.log
logfile flush 1
log on
logtstamp after 1
logtstamp string \"[ %t: %Y-%m-%d %c:%s ]\012\"
logtstamp on";
echo "$config" > /tmp/log.conf
screen -c /tmp/log.conf -dmSL "$name" $command
rm /tmp/log.conf
사용하려면 저장 (screen.sh)하고 + x 권한을 설정합니다.
./screen.sh TEST ./test.pl
... ./test.pl을 실행하고 /var/log/TEST.log에 로그 파일을 생성합니다.
다음 명령은 화면 버전 4.06.02에서 작동합니다.
screen -L -Logfile Log_file_name_of_your_choice command_to_be_executed
화면의 맨 페이지에서 :
-Logfile file : By default logfile name is "screenlog.0".
You can set new logfile name with the "-Logfile" option.
screen -version을 사용하여 기존 화면 버전을 확인할 수 있습니다 . https://www.gnu.org/software/screen/ 에서 최신 화면 버전을 다운로드하여 설치할 수 있습니다 .
Mac 터미널의 경우 :
script -a -t 0 out.txt screen /dev/ttyUSB0 115200
세부
script
"터미널 세션의 타이프 스크립트 만들기"를위한 앱 내장-a
출력 파일에 추가-t 0
time between writing to output file is 0 seconds, so out.txt is updated for every new charout.txt
is just the output file namescreen /dev/ttyUSB0 115200
- command from question for connecting to external device
you can then use tail to see that the file is updating
tail -100 out.txt
Ctrl+A then Shift+H works for me. You can view the file screenlog.0
while the program is still running.
The 'script' command under Unix should do the trick. Just run it at the start of your new console and you should be good.
The following might be useful (Tested on: Linux/Ubuntu 12.04):
cat /dev/ttyUSB0
Using the above, you can then do all the re-directions that you need. For example, to dump output to your console whilst saving to your file, you'd do:
cat /dev/ttyUSB0 | tee console.log
Here's a trick: wrap it in sh -c
!
screen sh -c './some-script 2>&1 | tee mylog.log'
Where 2>&1
redirects stderr to stdout so tee
can catch and log error messages.
참고URL : https://stackoverflow.com/questions/14208001/save-screen-program-output-to-a-file
'IT story' 카테고리의 다른 글
REST URI 버전을 지정하는 방법 (0) | 2020.08.09 |
---|---|
오류 : 오류 1005 : 테이블을 만들 수 없습니다 (errno : 121). (0) | 2020.08.09 |
날짜에 대한 Pandas DataFrames 필터링 (0) | 2020.08.09 |
열의 비어 있지 않은 마지막 셀 (0) | 2020.08.09 |
레코드 변경 내역을 추적하는 MySQL 옵션 / 기능이 있습니까? (0) | 2020.08.09 |