Estou tentando descompactar um arquivo em um script bash, mas recebo o erro "Falha de segmentação (core dumped)" após uma mensagem de saída repetida "Descompactar arquivos do agente".
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Unzip agent files.
Segmentation fault (core dumped)
Veja o script abaixo:
cat /usr/local/bin/release-agent.sh
#! /bin/bash -e
source functions.sh
arg1=$1
check_arg (){
if [[ -z ${arg1} ]]; then
output "ERROR! Usage: Agent-unzip.sh [local zip file]..." red
exit 0
else
arg=${arg1}
if [[ ! -f ${arg} ]]; then
output "No local file found!" blue
exit 0
else
file=${arg}
ext=${file##*.}
if [[ ${ext} != "zip" ]]; then
output "File specified does not appear to be a zip." red
confirm "Would you like to proceed." #yes no question
if [[ $? == "1" ]]; then #if no
exit 0
fi
else
output "Local file, ${file} found." blue
fi
fi
zip="${file##*/}"
fi
}
select_version (){
prompt="Enter agent version number: "
read -p "${prompt}" version
while [ -z ${version} ]; do
output "No input entered" red
read -p "${prompt}" version
done
output "You entered: ${version}" blue
}
create_dir (){
path="Agent/agent-${version}"
output "Creating working directory ${path}" blue
mkdir -p "${path}"
}
unzip (){
output "Unzip agent files." blue
unzip -uq "$zip" -d "${path}"
}
conf_details (){
output "See details entered below:" blue
output "VERSION = ${version}" green
output "FILE PATH = ${zip}" green
confirm "Would you like to proceed? press 'Y' to initiate the release of the agent image, press 'N' to edit any details:" #yes no question
if [[ $? != "0" ]]; then #if anything but yes is returned
$0 ${arg}
exit 0
fi
}
check_arg
select_version
conf_details
create_dir
unzip
## If script has't crashed out ##
output "Success! All operations completed" green
exit 0
A função de saída é apenas algo que escrevi para facilitar a saída. Veja abaixo como referência:
output() {
#
# Useage output "string" [colour] {flash}
#
if [[ $3 == "flash" ]]; then
_blink=";5"
else
_blink=""
fi
case $2 in
grey)
echo -e "\e[30;1${_blink}m${1}\e[0m"
;;
red)
echo -e "\e[31;1${_blink}m${1}\e[0m"
;;
green)
echo -e "\e[32;1${_blink}m$1\e[0m"
;;
yellow)
echo -e "\e[33;1${_blink}m$1\e[0m"
;;
blue)
echo -e "\e[34;1${_blink}m$1\e[0m"
;;
magenta)
echo -e "\e[35;1${_blink}m$1\e[0m"
;;
lightblue)
echo -e "\e[36;1${_blink}m$1\e[0m"
;;
white)
echo -e "\e[37;1${_blink}m$1\e[0m"
;;
*)
echo -e "\e[0mNo formatting option!"
;;
esac
}
Sua
unzip
função está chamando a si mesma, o que acaba causando uma falha de segmentação (no shell, nãounzip
).Para resolver isso, ligue para
na função em vez de simples
unzip
.