묻고 답해요
141만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결리눅스 쉘 스크립트 마스터
select in case문 질문
#!/bin/bash ##v.2.0 export IP1="0" export IP2="0" export IP3="0" export DATE=$(date +"%F") PS3="Select the option " select char in "1, Check IP" "2, IP List" "3, Exit" #"4"# do case $char in 1*) read -p "Enter IP xxx.xxx.xxx. > " -t 20 IP1 read -p "Enter start IP xxx > " -t 20 IP2 read -p "Enter last IP xxx > " -t 20 IP3 echo -e "\033[32;1m"IP Checking!"\033[0m" while [[ $IP2 -lt $IP3 ]]; do ping -c 1 -w 1 $IP1$IP2 > /dev/null if [[ $? == 0 ]]; then echo $IP1$IP2 is In-use. >> /tmp/ip_list_$DATE ; else echo $IP1$IP2 is Dead or Available. >> /tmp/ip_list_$DATE ; fi IP2=$(($IP2+1)) done echo -e "\033[31;1m"IP Check well done! please verify IP"\033[0m" ;; 2*) grep -q Avail* 2> /dev/null < /tmp/ip_list_$DATE if [[ $? == 0 ]]; then grep -r --color=always Available /tmp/ip_list_$DATE | sort -u else echo -e "\033[31;3m"There is no available IP"\033[0m" fi ;; 3*) echo "Good bye"; exit 0 ;; #4*) echo "You choose not yet menu it will be add section coming soon asap" ;; *) echo "!!Error select correctly number!!" esac done 위와 같이 실행시 결과 값 [root@hlldvc ddrec]# ./ipcheck.sh 1) 1, Check IP 2) 2, IP List 3) 3, Exit Select the option 이와 같이 1)1, 숫자가 중복이 되는 현상이 발생합니다. 미관상 좋지 않아보여 중복 제거를 위해 여러 방법을 시도해 보는중이지만 잘 되지 않습니다. 혹시 다른 방법이 있을까요..?
-
미해결시스템엔지니어가 알려주는 리눅스 실전편 Bash Shell Script
DB 백업 쉘 스크립트 오류 문의
아래와 같이 오류 발생합니다. [00] FATAL ERROR: 2021-12-03 01:56:26 Can't open backup-my.cnf for reading 해결 방법 좀 알려 주세요~ [root@cent2 BACKUP]# ./db_backup.sh 백업 디렉토리가 있어요. 문제없음. [00] 2021-12-03 01:56:26 Connecting to MySQL server host: localhost, user: not set, password: not set, port: not set, socket: not set [00] 2021-12-03 01:56:26 Failed to connect to MySQL server: Access denied for user ''@'localhost' (using password: NO). /usr/bin/mariabackup based on MariaDB server 10.3.28-MariaDB Linux (x86_64) [00] 2021-12-03 01:56:26 cd to /root/SHELL/BACKUP/xtrabackup_backupfiles/ [00] 2021-12-03 01:56:26 open files limit requested 0, set to 1024 [00] FATAL ERROR: 2021-12-03 01:56:26 Can't open backup-my.cnf for reading /usr/bin/tar: Cowardly refusing to create an empty archive Try '/usr/bin/tar --help' or '/usr/bin/tar --usage' for more information. /usr/bin/ls: cannot access '/mnt/BACKUP/cent2/2021.12.03_cent2_DB.tgz': No such file or directory /usr/bin/ls: cannot access '/mnt/BACKUP/cent2/2021.12.03_cent2_DB.tgz': No such file or directory