질문:
실험을 하다가 실수로 화면이 80개 가까이 만들어졌습니다.
우리는 그들의 ID를 사용하여 하나씩 제거할 수 있습니다. 하지만 프로세스를 자동화하고 시간을 절약하기 위해 스크립트나 명령 조합을 사용하여 이 모든 것을 끝낼 수 있는 방법이 있습니까?
There are screens on:
31408.erpnext (12/27/2019 03:13:14 PM) (Attached)
31396.erpnext (12/27/2019 03:13:14 PM) (Attached)
31384.erpnext (12/27/2019 03:13:14 PM) (Attached)
31372.erpnext (12/27/2019 03:13:14 PM) (Attached)
31360.erpnext (12/27/2019 03:13:14 PM) (Attached)
31348.erpnext (12/27/2019 03:13:14 PM) (Attached)
31336.erpnext (12/27/2019 03:13:14 PM) (Attached)
31324.erpnext (12/27/2019 03:13:14 PM) (Attached)
31312.erpnext (12/27/2019 03:13:14 PM) (Attached)
31300.erpnext (12/27/2019 03:13:14 PM) (Attached)
31288.erpnext (12/27/2019 03:13:14 PM) (Attached)
31276.erpnext (12/27/2019 03:13:13 PM) (Attached)
31264.erpnext (12/27/2019 03:13:13 PM) (Attached)
31252.erpnext (12/27/2019 03:13:13 PM) (Attached)
31240.erpnext (12/27/2019 03:13:13 PM) (Attached)
31228.erpnext (12/27/2019 03:13:13 PM) (Attached)
31216.erpnext (12/27/2019 03:13:13 PM) (Attached)
31204.erpnext (12/27/2019 03:13:13 PM) (Attached)
31192.erpnext (12/27/2019 03:13:13 PM) (Attached)
31180.erpnext (12/27/2019 03:13:13 PM) (Attached)
31168.erpnext (12/27/2019 03:13:13 PM) (Attached)
31156.erpnext (12/27/2019 03:13:13 PM) (Attached)
31144.erpnext (12/27/2019 03:13:13 PM) (Attached)
31132.erpnext (12/27/2019 03:13:13 PM) (Attached)
31120.erpnext (12/27/2019 03:13:13 PM) (Attached)
31108.erpnext (12/27/2019 03:13:13 PM) (Attached)
31096.erpnext (12/27/2019 03:13:13 PM) (Attached)
31084.erpnext (12/27/2019 03:13:13 PM) (Attached)
31072.erpnext (12/27/2019 03:13:13 PM) (Attached)
31060.erpnext (12/27/2019 03:13:13 PM) (Attached)
31048.erpnext (12/27/2019 03:13:13 PM) (Attached)
31036.erpnext (12/27/2019 03:13:12 PM) (Attached)
31024.erpnext (12/27/2019 03:13:12 PM) (Attached)
31012.erpnext (12/27/2019 03:13:12 PM) (Attached)
31000.erpnext (12/27/2019 03:13:12 PM) (Attached)
30988.erpnext (12/27/2019 03:13:12 PM) (Attached)
30976.erpnext (12/27/2019 03:13:12 PM) (Attached)
30964.erpnext (12/27/2019 03:13:12 PM) (Attached)
30952.erpnext (12/27/2019 03:13:12 PM) (Attached)
30940.erpnext (12/27/2019 03:13:12 PM) (Attached)
30928.erpnext (12/27/2019 03:13:12 PM) (Attached)
30916.erpnext (12/27/2019 03:13:12 PM) (Attached)
30904.erpnext (12/27/2019 03:13:12 PM) (Attached)
30892.erpnext (12/27/2019 03:13:12 PM) (Attached)
30880.erpnext (12/27/2019 03:13:12 PM) (Attached)
30868.erpnext (12/27/2019 03:13:12 PM) (Attached)
30856.erpnext (12/27/2019 03:13:12 PM) (Attached)
30844.erpnext (12/27/2019 03:13:12 PM) (Attached)
30832.erpnext (12/27/2019 03:13:12 PM) (Attached)
30820.erpnext (12/27/2019 03:13:12 PM) (Attached)
30808.erpnext (12/27/2019 03:13:12 PM) (Attached)
30796.erpnext (12/27/2019 03:13:12 PM) (Attached)
30784.erpnext (12/27/2019 03:13:11 PM) (Attached)
30772.erpnext (12/27/2019 03:13:11 PM) (Attached)
30760.erpnext (12/27/2019 03:13:11 PM) (Attached)
30748.erpnext (12/27/2019 03:13:11 PM) (Attached)
30736.erpnext (12/27/2019 03:13:11 PM) (Attached)
30724.erpnext (12/27/2019 03:13:11 PM) (Attached)
30712.erpnext (12/27/2019 03:13:11 PM) (Attached)
30700.erpnext (12/27/2019 03:13:11 PM) (Attached)
30688.erpnext (12/27/2019 03:13:11 PM) (Attached)
30676.erpnext (12/27/2019 03:13:11 PM) (Attached)
30664.erpnext (12/27/2019 03:13:11 PM) (Attached)
30652.erpnext (12/27/2019 03:13:11 PM) (Attached)
30640.erpnext (12/27/2019 03:13:11 PM) (Attached)
30628.erpnext (12/27/2019 03:13:11 PM) (Attached)
30616.erpnext (12/27/2019 03:13:11 PM) (Attached)
30604.erpnext (12/27/2019 03:13:11 PM) (Attached)
30592.erpnext (12/27/2019 03:13:11 PM) (Attached)
30580.erpnext (12/27/2019 03:13:11 PM) (Attached)
30568.erpnext (12/27/2019 03:13:11 PM) (Attached)
30556.erpnext (12/27/2019 03:13:11 PM) (Attached)
30544.erpnext (12/27/2019 03:13:11 PM) (Attached)
30532.erpnext (12/27/2019 03:13:11 PM) (Attached)
30520.erpnext (12/27/2019 03:13:11 PM) (Attached)
30508.erpnext (12/27/2019 03:13:11 PM) (Attached)
30496.erpnext (12/27/2019 03:13:10 PM) (Attached)
30484.erpnext (12/27/2019 03:13:10 PM) (Attached)
30471.erpnext (12/27/2019 03:13:10 PM) (Attached)
30458.erpnext (12/27/2019 03:13:10 PM) (Attached)
30446.erpnext (12/27/2019 03:13:10 PM) (Attached)
30433.erpnext (12/27/2019 03:13:10 PM) (Detached)
5061.erpnext (12/23/2019 06:03:38 PM) (Detached)
83 Sockets in /var/run/screen/S-erpnext.
우리가 하고 싶은 것:
을 제외한 모든 것을 종료합니다 5061.erpnext
.
지금까지 우리는 다음을 시도했습니다.
#!/bin/bash
running_screens=$(screen -ls | grep -v "5061.erpnext")
echo "${running_screens}"
for i in {$running_screens}
do
screens=$(${i} | grep ".")
if [[ ${screens} != "" ]]; then
echo "${i}"
fi
done
답변1
표준 쉘 구문에서:
cd /var/run/screen/S-erpnext
for screen in *
do
case $screen in
(5061.erpnext) : do nothing ;;
(*) kill "${screen%%.*}" ;;
esac
done
위의 내용은 해당 사용자의 화면 디렉터리로 변경된 다음 해당 디렉터리의 각 세션 파일을 반복합니다. 세션이 다음과 같은 경우아니요5061.erpnext를 입력한 다음 해당 PID(첫 번째 마침표 앞의 숫자)를 삭제합니다. 확장은 ${screen%%.*}
마침표가 발견될 때까지 문자열 끝에서 가능한 한 많은 문자를 제거합니다. 그런 것들을 없애는 효과가 있어요아니요PID. 내장 : do nothing
함수를 사용하면 :
인수를 무시하는 것을 포함하여 아무 작업도 수행하지 않으므로 해당 줄에 주석을 달아 이를 표시했습니다.아니요이 경우 모든 PID를 종료하십시오.