일치하는 ``''를 찾는 동안 예기치 않은 EOF가 발생했습니다. [닫기]

일치하는 ``''를 찾는 동안 예기치 않은 EOF가 발생했습니다. [닫기]

BASH 프로젝트가 있는데 이해할 수 없는 두 가지 오류가 발생합니다.

이것은 내 BASH 스크립트입니다.

#!/bin/bash

proc_name=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f1 | uniq`;
proc_freq=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f2 | uniq`;
proc_core=`cat /proc/cpuinfo | grep 'cpu cores' | cut -d':' -f2 | uniq`;
proc_hyperthreading=`cat /proc/cpuinfo | grep 'siblings' | cut -d':' -f2 | uniq`;
proc_architecture=`lscpu | grep '64-bit' | cut -d',' -f2 | cut -d'-' -f1`;
proc_cache_L1=`lscpu | grep 'Cache L1i' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_cache_L2=`lscpu | grep 'Cache L2' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_cache_L3=`lscpu | grep 'Cache L3' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_virtualisation=`lscpu | grep 'Virtualisation' | cut -d':' -f2 |sed "s/\ \ */\ /g"`;
proc_load_average=`w | head -1 | cut -d" " -f12 | cut -d"," -f1-2` | tr ',' '.'`

ip_infos_addr_ipv4=`/sbin/ifconfig eth0 | awk '/inet adr:/{print $2}' | awk -F ':' '{print $2}'`;
ip_infos_addr_ipv6=`/sbin/ifconfig eth0 | awk '/adr inet6:/{print $3}'`;
ip_publique_addr=`dig +short myip.opendns.com @resolver1.opendns.com`;
carte_reseau=`lspci |grep Ethernet | cut -d":" -f3`;


echo -e "$proc_name\n$proc_freq\n$proc_core\n$proc_hyperthreading\n$proc_architecture\n$proc_cache_L1\n$proc_cache_L2\n$proc_cache_L3\n$proc_virtualisation\n$proc_load_average\n$ip_infos_addr_ipv4\n$ip_infos_addr_ipv6\n$ip_publique_addr\n$carte_reseau" > Collecteur/collecteur_cpu_reseau.txt;

내 두 가지 오류는 다음과 같습니다.

./collecteur_cpu_reseau: line 17: unexpected EOF while looking for matching ``'
./collecteur_cpu_reseau: line 21: syntax error: unexpected end of file

답변1

실수는불필요한 인용문존재하다 line 12:

proc_load_average=`w | head -1 | cut -d" " -f12 | cut -d"," -f1-2` | tr ',' '.'`
# _______________________________________________________________^   

                                                         ^

따라서 오류가 없는 스크립트는 다음과 같습니다.

#!/bin/bash

proc_name=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f1 | uniq`;
proc_freq=`cat /proc/cpuinfo | grep 'model name' | cut -d':' -f2 |cut -d'@' -f2 | uniq`;
proc_core=`cat /proc/cpuinfo | grep 'cpu cores' | cut -d':' -f2 | uniq`;
proc_hyperthreading=`cat /proc/cpuinfo | grep 'siblings' | cut -d':' -f2 | uniq`;
proc_architecture=`lscpu | grep '64-bit' | cut -d',' -f2 | cut -d'-' -f1`;
proc_cache_L1=`lscpu | grep 'Cache L1i' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_cache_L2=`lscpu | grep 'Cache L2' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_cache_L3=`lscpu | grep 'Cache L3' | cut -d':' -f2 | sed "s/\ \ */\ /g"`;
proc_virtualisation=`lscpu | grep 'Virtualisation' | cut -d':' -f2 |sed "s/\ \ */\ /g"`;
# corrected line
proc_load_average=`w | head -1 | cut -d" " -f12 | cut -d"," -f1-2 | tr ',' '.'`

ip_infos_addr_ipv4=`/sbin/ifconfig eth0 | awk '/inet adr:/{print $2}' | awk -F ':' '{print $2}'`;
ip_infos_addr_ipv6=`/sbin/ifconfig eth0 | awk '/adr inet6:/{print $3}'`;
ip_publique_addr=`dig +short myip.opendns.com @resolver1.opendns.com`;
carte_reseau=`lspci |grep Ethernet | cut -d":" -f3`;


echo -e "$proc_name\n$proc_freq\n$proc_core\n$proc_hyperthreading\n$proc_architecture\n$proc_cache_L1\n$proc_cache_L2\n$proc_cache_L3\n$proc_virtualisation\n$proc_load_average\n$ip_infos_addr_ipv4\n$ip_infos_addr_ipv6\n$ip_publique_addr\n$carte_reseau" > Collecteur/collecteur_cpu_reseau.txt;

관련 정보