(Added yyyy.mm.dd)
I will leave a personal memorandum that I often search in CentOS server construction. I will add things that I thought "I searched before ..." one by one.
References: [tar] command-create / extract archive file
tar -zcvf xxxx.tar.gz directory to compress#compression
tar -zxvf xxxx.tar.gz #Defrost
tr '[:upper:]' '[:lower:]' #Uppercase → lowercase
tr '[:lower:]' '[:upper:]' #Lowercase → uppercase
--Repeat processing for files in a specific input directory --Output is a specific directory ――I want to be able to run it anywhere --I want to write to the log so that I can see the start and end --Initialize output directory and log
template
#!/bin/bash
##Outline of processing####################################################################
#Roughly write what kind of processing
##variable########################################################################
#Get current directory
SCRIPT_DIR=$(cd $(dirname $0); pwd)
#Output log
LOG="${SCRIPT_DIR}/$(basename $0 ".sh")_$(date +%Y%m%d).log"
#Appropriate directory
INPUT_DIR="${SCRIPT_DIR}/xxx"
#Output directory
OUTPUT_DIR="${SCRIPT_DIR}/xxx"
#Number of suitable directories
LIST_NUM=$(ls ${INPUT_DIR} | wc -l)
##This process######################################################################
#Log generation(Initialization)
cat /dev/null > ${LOG}
#Check the existence of the output directory
#Create a directory if it does not exist, and initialize it in the directory if it exists.
if [ -e ${OUTPUT_DIR} ]; then
rm -rf ${OUTPUT_DIR}/*
else
mkdir ${OUTPUT_DIR}
fi
echo "$(date +%T)Start processing(Target:${LIST_NUM}Case)" >> ${LOG}
echo >> ${LOG}
#Get input file
INPUT_ARRAY=$(find ${INPUT_DIR} -maxdepth 1 -type f)
#Export for INPUT files
for file in ${INPUT_ARRAY}
do
#Trimming as needed
# INPUT_NAME=$(basename ${file})
#Good processing
COMMAND -i ${file} -o ${OUTPUT_DIR}/${INPUT_NAME} >> ${LOG} 2>&1
echo "$(date +%T)Processing completed:${INPUT_NAME}" >> ${LOG}
done
echo >> ${LOG}
echo "$(date +%T)Processing Exit(Total number:$(ls ${OUTPUT_DIR} | wc -l)Case)" >> ${LOG}
echo "Normal termination LOG: ${LOG}"
Recommended Posts