Personal tips on working with CentOS servers

(Added yyyy.mm.dd)


Introduction

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.

Command related

Compress / decompress with tar command

References: [tar] command-create / extract archive file

tar -zcvf xxxx.tar.gz directory to compress#compression

tar -zxvf xxxx.tar.gz #Defrost

Lowercase and uppercase conversion with the tr command

tr '[:upper:]' '[:lower:]' #Uppercase → lowercase

tr '[:lower:]' '[:upper:]' #Lowercase → uppercase

Script related

Shell script template

Requirements

--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

Shell script template

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}"

Other

Recommended Posts

Personal tips on working with CentOS servers
Set up ImpressPages 5.0 with LAMP on CentOS 7.3
Install NextCloud on CentOS 7 with Alibaba Cloud ECS
OpenVPN on CentOS 8
Create a user with an empty password on CentOS7
Maven on CentOS 7 tutorial
Docker installation on CentOS 6
Use perltidy on CentOS 8
Install Golang on CentOS 8
Try OpenLiteSpeed on CentOS8
Install Neo4j 4.1.3 on centOS
Tomcat v8 on CentOS7
Zabbix 5 installation on CentOS 8
Use mod_auth_cas on CentOS 8
Use CentOS with LXD
Install PostgreSQL 12 on Centos8
Install nginx on centOS7
Install kuromoji on CentOS7
Build Growai with Centos7
Use bat on Centos.
Jetty v8 on CentOS7
OpenJDK installation on CentOS 7
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Install jpndistrict on CentOS 7
Install Redmine 4.1.1 on CentOS 7
Smokeping Install on CentOS7
Install PostgreSQL 13 on CentOS 7.5
Note: Install nginx from official repositories with dnf on CentOS 8
Build a CentOS 8 virtual environment on your Mac with VirtualBox