Commit f21f534c by liyapeng

初步编写完成,测试阶段

1 parent 5b027a11
Showing with 143 additions and 14 deletions
#!/bin/bash
# 定义变量
# export COS_TMP_SECRET_ID=''
# export COS_TMP_SECRET_KEY=''
# export COS_TMP_SESSION_TOKEN=''
TMP_SECRET_ID=${COS_TMP_SECRET_ID}
TMP_SECRET_KEY=${COS_TMP_SECRET_KEY}
TMP_SESSION_TOKEN=${COS_TMP_SESSION_TOKEN}
BUCKET_NAME='log-collection-1310972338'
ENDPOINT='cos.ap-beijing.myqcloud.com'
export PATH="$PATH:./"
LOG_COLLECT_FILE_URL="http://mirrors.tencentyun.com/install/cts/linux/adl_log_collect.zip"
operation() {
echo "[2]Unzip Tool..."
unzip -o adl_log_collect.zip >>/dev/null
echo "[3]Runing Tool..."
cd adl_log_collect
./log_collect.sh
cd ..
echo "[4]Clearing Env..."
rm -rf adl_log_collect.zip
rm -rf adl_log_collect
echo "[5]done"
}
# 检测变量值
echo "debug vars"
echo 变量TMP_SECRET_ID 的值:${TMP_SECRET_ID}
echo 变量TMP_SECRET_KEY 的值:${TMP_SECRET_KEY}
echo 变量TMP_SESSION_TOKEN 的值:${TMP_SESSION_TOKEN}
main() {
if [ $(whoami) != "root" ]; then
echo " only root can run me"
exit 1
else
#判断是否存在wget、curl
check_wget=$(which wget)
if [ $? -ne 0 ]; then
echo -e "\e[33mwget command not found!\e[0m"
echo -e "\e[33mPlease install wget to run this script.\e[0m"
echo -e "\e[33mInstall wget to run command: apt-get update -y && apt-get install wget -y\e[0m"
exit 1
else
wget -q ${LOG_COLLECT_FILE_URL} >>/dev/null
operation
fi
fi
}
#!/bin/bash
# 定义变量
export PATH="$PATH:./"
TMP_SECRET_ID=${COS_TMP_SECRET_ID}
TMP_SECRET_KEY=${COS_TMP_SECRET_KEY}
TMP_SESSION_TOKEN=${COS_TMP_SESSION_TOKEN}
BUCKET_NAME='log-collection-1310972338'
ENDPOINT='cos.ap-beijing.myqcloud.com'
CURRENT_DATE=$(date +%Y%m%d)
LOG_DIR="$(hostname)-${CURRENT_DATE}-log"
LOG_FILE_PATH="/tmp/${LOG_DIR}"
mkdir -p ${LOG_FILE_PATH}
if [ $(whoami) != "root" ]; then
echo " only root can run me"
exit 1
fi
space=$(df -hm / | tail -n 1 | awk '{print $(NF-2) }')
[ $space -gt 100 ] || (echo "no enough space at /" && exit 1)
echo -e "\033[41;33m This script is used as a daily troubleshooting and does not involve collecting relevant privacy data \033[0m"
systemlog() {
#收集操作系统产生的日志
mkdir -p ${LOG_FILE_PATH}/systemlog
cp /var/log/syslog* ${LOG_FILE_PATH}/systemlog/
cp /var/log/dmesg* ${LOG_FILE_PATH}/systemlog/
cp /var/log/cron* ${LOG_FILE_PATH}/systemlog/
cp /var/log/auth* ${LOG_FILE_PATH}/systemlog/
cp /var/log/kern* ${LOG_FILE_PATH}/systemlog/
}
hardware_info() {
mkdir -p ${LOG_FILE_PATH}/hardware_info
cp /proc/cpuinfo ${LOG_FILE_PATH}/hardware_info/
cp /proc/meminfo ${LOG_FILE_PATH}/hardware_info/
echo '----------lsblk info' >>${LOG_FILE_PATH}/hardware_info/disk_info
lsblk >>${LOG_FILE_PATH}/hardware_info/disk_info
echo '------------------------------fdisk -l info' >>${LOG_FILE_PATH}/hardware_info/disk_info
fsidk -l >>${LOG_FILE_PATH}/hardware_info/disk_info
echo '------------------------------blkid info' >>${LOG_FILE_PATH}/hardware_info/disk_info
blkid -l >>${LOG_FILE_PATH}/hardware_info/disk_info
echo '------------------------------df -h info' >>${LOG_FILE_PATH}/hardware_info/disk_info
df -h >>${LOG_FILE_PATH}/hardware_info/disk_info
lspci >>${LOG_FILE_PATH}/hardware_info/lspci_info
dmidecode >>${LOG_FILE_PATH}/hardware_info/dmidecode_info
mdadm -Dsvvv >>${LOG_FILE_PATH}/hardware_info/mdadm_info
mdadm -Esvvv >>${LOG_FILE_PATH}/hardware_info/mdadm_info
}
sysconfig_info() {
mkdir -p ${LOG_FILE_PATH}/sysconfig_info
cat /etc/sysctl.conf | grep -v ^# | grep -v ^$ >>${LOG_FILE_PATH}/sysconfig_info/sysctl_info
ip addr >>${LOG_FILE_PATH}/sysconfig_info/ip_info
cat /etc/netplan/* >>${LOG_FILE_PATH}/sysconfig_info/network_info
cat /etc/rc.local >>${LOG_FILE_PATH}/sysconfig_info/rc.local_info
iptables -nvL >>${LOG_FILE_PATH}/sysconfig_info/iptables_info
lsb_release -a >>${LOG_FILE_PATH}/sysconfig_info/os_version_info
cat /etc/passwd | cut -f 1 -d : | xargs -I {} crontab -l -u {} >>${LOG_FILE_PATH}/sysconfig_info/cron_info
}
GPULogCollect() {
gpuInstanceState=$(lspci -d 10de: | wc -l)
if [ -f /usr/bin/nvidia-bug-report.sh ] && [ $gpuInstanceState -gt 0 ]; then
mkdir -p ${LOG_FILE_PATH}/GPULogCollect
echo "Start to collect gpu log for instance $(hostname) by nvidia-bug-report.sh"
nvidia-bug-report.sh --output-file ${LOG_FILE_PATH}/GPULogCollect/nvidia-bug-report.log.gz.gz
timeout 30 nvidia-smi >${LOG_FILE_PATH}/GPULogCollect/nvidia-smi.log
nvidia-smi topo -m >>${LOG_FILE_PATH}/GPULogCollect/nvidia-smi.log
lspci -d 10de: | egrep "VGA|3D" >${LOG_FILE_PATH}/GPULogCollect/lspci-nvidia.log
lspci -vvv -t >>${LOG_FILE_PATH}/GPULogCollect/lspci-nvidia.log
lspci -vvv >>${LOG_FILE_PATH}/GPULogCollect/lspci-nvidia.log
dmesg -T >${LOG_FILE_PATH}/GPULogCollect/dmesg-gpu.log
fi
}
sosreportLOG() {
if command -v sosreport &>/dev/null; then
echo "sosreport 已经安装"
sosreport --batch
else
echo "安装 sosreport..."
sudo apt-get update
sudo apt-get install -y sosreport
sosreport --batch
fi
cp /tmp/sosreport* ${LOG_FILE_PATH}/
}
Bundlinglogfiles() {
tar cvf /tmp/${LOG_DIR}.tar ${LOG_FILE_PATH} >>/dev/null
}
uploadlogfile() {
echo "upload log file"
./coscli -e ${ENDPOINT} -i ${TMP_SECRET_ID} -k ${TMP_SECRET_KEY} --token ${TMP_SESSION_TOKEN} cp /tmp/${LOG_DIR}.tar cos://${BUCKET_NAME}/${LOG_DIR}.tar
}
main() {
systemlog
hardware_info
sysconfig_info
GPULogCollect
sosreportLOG
Bundlinglogfiles
uploadlogfile
rm -r ${LOG_FILE_PATH}
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!