1
0
This commit is contained in:
2024-11-01 14:13:11 +08:00
parent 904a13fd56
commit e11f0235f1
997 changed files with 0 additions and 63805 deletions

View File

@@ -1,54 +0,0 @@
#!/bin/bash
filename="$1"
neType="$2"
duration=180
expectBin=/usr/bin/expect
omcBin=/usr/local/omc/bin
logFile=/tmp/actpkg`date +%Y%m%d`.log
extension=$(basename "${1}" | awk -F . '{print $NF}')
if [ ! -f ${expectBin} ]; then
echo "Please install software expect first"
exit 99
fi
case "${extension}" in
deb)
if [ ${neType} == "OMC" ]; then
systemctl stop restagent.service
fi
expect <<EOF > ${logFile}
spawn dpkg -i --force-all "$filename"
set timeout ${duration}
expect {
"y/n" { send "y\n"; exp_continue }
}
EOF
if [ ${neType} == "OMC" ]; then
${omcBin}/setomc.sh -m upgrade >> ${logFile}
${omcBin}/omcsvc.sh restart >> ${logFile}
fi
;;
rpm)
if [ ${neType} == "OMC" ]; then
systemctl stop restagent.service
fi
expect <<EOF > ${logFile}
spawn rpm -Uvh "$filename"
set timeout ${duration}
expect {
"y/n" { send "y\n"; exp_continue }
}
EOF
if [ ${neType} == "OMC" ]; then
${omcBin}/setomc.sh -m upgrade >> ${logFile}
${omcBin}/omcsvc.sh restart >> ${logFile}
fi
;;
*)
echo "The file does not have a .deb or .rpm extension"
exit 100
;;
esac

View File

@@ -1,10 +0,0 @@
#!/bin/bash
threshold=99 # 设置硬盘使用率的阈值
disk_usage=$(df -h | awk '$NF=="/"{print $(NF-1)}' | sed 's/%//') # 获取根目录的硬盘使用率
if [ $disk_usage -gt $threshold ]; then
echo "Disk usage is above $threshold%. Taking action..."
systemctl restart keepalived
fi

View File

@@ -1,8 +0,0 @@
#!/bin/bash
process_name="restagent"
if ! pgrep -x "$process_name" >/dev/null; then
echo "$process_name is not running. Restarting..."
systemctl restart keepalived
fi

View File

@@ -1,38 +0,0 @@
#!/bin/bash
tooldir=/usr/local/bin
toollist="zip unzip"
# distribute to hosts in file nehosts
while read line
do
if [[ "$line" =~ ^[^[:space:]]*# || -z "$line" ]]; then
continue
fi
user=`echo $line | cut -d " " -f 2`
ip=`echo $line | cut -d " " -f 1`
passwd=`echo $line | cut -d " " -f 3`
for toolname in $toollist;do
expect <<EOF
set timeout 10
spawn scp $tooldir/$toolname $user@$ip:/tmp
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$passwd\n" }
}
expect "password" { send "$passwd\n" }
EOF
done
for toolname in $toollist;do
expect <<EOF
set timeout 10
spawn ssh $user@$ip sudo mv /tmp/$toolname $tooldir
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$passwd\n" }
}
expect "password" { send "$passwd\n" }
EOF
done
done < nehosts

View File

@@ -1,36 +0,0 @@
#!/bin/bash
# if exist id_rsa
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
else
echo "id_rsa has created ..."
fi
# distribute to hosts in file nehosts
while read line
do
# ignore comment or null line
if [[ "$line" =~ ^[^[:space:]]*# || -z "$line" ]]; then
continue
fi
ip=`echo $line | cut -d " " -f 1`
user=`echo $line | cut -d " " -f 2`
passwd=`echo $line | cut -d " " -f 3`
# !!! to remove ~/.ssh, all old authorized key will be lost
expect <<EOF
set timeout 10
spawn ssh $user@$ip "sudo rm -r ~/.ssh"
expect {
"yes/no" { send "yes\n";exp_continue }
"password:" { send "$passwd\n" }
}
spawn ssh-copy-id -f $user@$ip
expect {
"password:" { send "$passwd\n" }
}
expect eof
EOF
done < nehosts

View File

@@ -1,154 +0,0 @@
#!/bin/bash
USER="root"
PASSWORD="1000omc@kp!"
HOST="127.0.0.1"
PORT="33066"
DBNAME="tenants_db"
UpgradeSQLDir=/usr/local/omc/etc/db/upgrade
Upgvue3SQLDir=/usr/local/omc/etc/db/upgvue3
InstallSQLDir=/usr/local/omc/etc/db/install
drop_db_sql="drop database IF EXISTS ${DBNAME}"
create_db_sql="create database IF NOT EXISTS ${DBNAME}"
case "$1" in
upgrade)
echo "Upgrade database ${DBNAME}"
for SQL in ${UpgradeSQLDir}/*.sql; do
echo -n "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} < ${SQL};
if [ $? = 0 ]; then
echo "done"
fi
done
;;
upgvue3)
echo "Upgrade to vue3 database ${DBNAME}"
for SQL in ${Upgvue3SQLDir}/*.sql; do
echo -n "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} < ${SQL};
if [ $? = 0 ]; then
echo "done"
fi
done
;;
install)
echo "Drop database ${DBNAME} ...!!!"
mysql -u${USER} -p${PASSWORD} -P $PORT -h ${HOST} --protocol tcp -e "${drop_db_sql}"
echo "Create database ${DBNAME} if not exist"
mysql -u${USER} -p${PASSWORD} -P $PORT -h ${HOST} --protocol tcp -e "${create_db_sql}"
for SQL in ${InstallSQLDir}/*.sql; do
echo -n "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} < ${SQL};
if [ $? = 0 ]; then
echo "done"
fi
done
;;
*)
while true
do
read -r -p "Do you upgrade or upgrade from layui to vue3 or fresh install database ${DBNAME}? [Upgrade/upgVue3/Install/Quit] " input
case $input in
[uU][pP][gG][rR][aA][dD][eE]|[uU])
echo "Skip to drop database ${DBNAME}"
echo "Upgrade database ${DBNAME}"
for SQL in ${UpgradeSQLDir}/*.sql; do
echo -n "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} < ${SQL};
if [ $? = 0 ]; then
echo "done"
fi
done
break
;;
[uU][pP][gG][vV][uU][eE][3]|[vV]])
echo "Skip to drop database ${DBNAME}"
echo "Upgrade to vue3 database ${DBNAME}"
for SQL in ${Upgvue3SQLDir}/*.sql; do
echo -n "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} < ${SQL};
if [ $? = 0 ]; then
echo "done"
fi
done
break
;;
[iI][nN][sS][tT][aA][lL][lL]|[iI])
echo "Drop database ${DBNAME} ...!!!"
mysql -u${USER} -p${PASSWORD} -P $PORT -h ${HOST} --protocol tcp -e "${drop_db_sql}"
echo "Create database ${DBNAME} if not exist"
mysql -u${USER} -p${PASSWORD} -P $PORT -h ${HOST} --protocol tcp -e "${create_db_sql}"
for SQL in ${InstallSQLDir}/*.sql; do
echo -n "Execute SQL script: ${SQL} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} < ${SQL};
if [ $? = 0 ]; then
echo "done"
fi
done
break
;;
[qQ][uU][iI][tT]|[qQ])
echo "Nothing to be done! GOOD BYE"
exit 1;
;;
*)
echo "Invalid input..."
;;
esac
done
;;
esac
# create kpi_report table with ne_type, exp: kpi_report_amf
ne_types=$(mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} -se "SELECT DISTINCT LOWER(ne_type) FROM kpi_title")
for ne_type in ${ne_types}; do
TABLE_NAME="kpi_report_${ne_type}"
SQL="CREATE TABLE IF NOT EXISTS ${TABLE_NAME} LIKE \`kpi_report\`;"
echo -n "Create table: ${TABLE_NAME} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} -e "${SQL}"
if [ $? = 0 ]; then
echo "done"
fi
SQL="ALTER TABLE ${TABLE_NAME} ADD INDEX IF NOT EXISTS \`idx_timestamp\`(\`created_at\`) USING BTREE, ADD INDEX IF NOT EXISTS \`idx_uid_datetime\`(\`rm_uid\`, \`date\`, \`start_time\`) USING BTREE;"
echo -n "Create index of ${TABLE_NAME} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} -e "${SQL}"
if [ $? = 0 ]; then
echo "done"
fi
SQL="ALTER TABLE ${TABLE_NAME} ADD INDEX IF NOT EXISTS \`idx_timestamp\`(\`created_at\`) USING BTREE,ADD INDEX IF NOT EXISTS \`idx_uid_datetime\`(\`rm_uid\`, \`date\`, \`start_time\`) USING BTREE;"
echo -n "Create index of ${TABLE_NAME} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} -e "${SQL}"
if [ $? = 0 ]; then
echo "done"
fi
SQL="ALTER TABLE ${TABLE_NAME} ADD COLUMN IF NOT EXISTS \`tenant_id\` varchar(32) NULL DEFAULT NULL AFTER \`created_at\`;"
echo -n "Alter table ${TABLE_NAME} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} -e "${SQL}"
if [ $? = 0 ]; then
echo "done"
fi
TABLE_NAME="kpi_c_report_${ne_type}"
SQL="CREATE TABLE IF NOT EXISTS ${TABLE_NAME} LIKE \`kpi_c_report\`;"
echo -n "Create table: ${TABLE_NAME} ..."
mysql -u${USER} -p${PASSWORD} -P ${PORT} -h ${HOST} --protocol tcp -D ${DBNAME} -e "${SQL}"
if [ $? = 0 ]; then
echo "done"
fi
done

View File

@@ -1,2 +0,0 @@
# host user password
# Example: 172.16.5.100 omcuser password

View File

@@ -1,48 +0,0 @@
#!/bin/bash
ProcList="restagent crontask sshsvc captrace"
ProcListDesc="crontask sshsvc captrace restagent"
BinDir=/usr/local/omc/bin
case "$1" in
start)
for procName in $ProcListDesc;do
echo -n "Starting $procName process ... "
systemctl start $procName
if [ $? = 0 ]; then
echo "done"
fi
sleep 1
done
;;
status)
for procName in $ProcList;do
systemctl status $procName
done
;;
stop)
for procName in $ProcList;do
echo -n "Stopping $procName process ... "
systemctl stop $procName
if [ $? = 0 ]; then
echo "done"
fi
done
;;
restart)
$0 stop
sleep 1
$0 start
;;
version)
for procName in $ProcList;do
$BinDir/$procName --version
done
;;
*)
echo "OMC service"
echo "Usage: $0 start|status|stop|restart|version"
;;
esac

View File

@@ -1,55 +0,0 @@
#!/bin/bash
filename="$1"
neType="$2"
duration=180
expectBin=/usr/bin/expect
omcBin=/usr/local/omc/bin
logFile=/tmp/actpkg`date +%Y%m%d`.log
extension=$(basename "${1}" | awk -F . '{print $NF}')
if [ ! -f ${expectBin} ]; then
echo "Please install software expect first"
exit 99
fi
case "${extension}" in
deb)
if [ ${neType} == "OMC" ]; then
systemctl stop restagent.service
fi
expect <<EOF > ${logFile}
spawn dpkg -i --force-all "$filename"
set timeout ${duration}
expect {
"y/n" { send "y\n"; exp_continue }
}
EOF
if [ ${neType} == "OMC" ]; then
${omcBin}/setomc.sh -m upgrade >> ${logFile}
${omcBin}/omcsvc.sh restart >> ${logFile}
fi
;;
rpm)
if [ ${neType} == "OMC" ]; then
systemctl stop restagent.service
fi
expect <<EOF > ${logFile}
spawn rpm -Uvh "$filename"
set timeout ${duration}
expect {
"y/n" { send "y\n"; exp_continue }
}
EOF
if [ ${neType} == "OMC" ]; then
${omcBin}/setomc.sh -m upgrade >> ${logFile}
${omcBin}/omcsvc.sh restart >> ${logFile}
fi
;;
*)
echo "The file does not have a .deb or .rpm extension"
exit 100
;;
esac

View File

@@ -1,16 +0,0 @@
#!/bin/bash
# rm expired file with filename like *20231028111213.zip"
filepath=$1
duration=$2
find $filepath -maxdepth 1 -type f -name "*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*" -printf "%f\n" | while read filename; do
datestr=$(echo "$filename" | grep -oE '[0-9]{8}')
filedate=$(date -d "$datestr" +%s)
sevendaysago=$(date -d "$duration days ago" +%s)
if [ "$filedate" -lt "$sevendaysago" ]; then
rm -f "$filepath/$filename"
echo "rm file: $filename"
fi
done

View File

@@ -1,101 +0,0 @@
#!/bin/bash
# Read the value of the variable from file
source /usr/local/omc/etc/omc.conf
C_ARG_LOWER="omc"
C_ARG_UPPER="OMC"
M_ARG_LOWER="*"
check_args() {
while getopts "c:m:" option; do
case $option in
c)
C_ARG_LOWER=$(echo $OPTARG | tr '[:upper:]' '[:lower:]')
C_ARG_UPPER=$(echo $OPTARG | tr '[:lower:]' '[:upper:]')
# Modifying Script Variables
if [ "${C_ARG_LOWER}" == "ba" ]; then
C_ARG_UPPER="BA"
sed -i 's/VENDORS=.*/VENDORS=BA/' /usr/local/omc/etc/omc.conf
elif [ "${C_ARG_LOWER}" == "omc" ]; then
C_ARG_UPPER="OMC"
sed -i 's/VENDORS=.*/VENDORS=OMC/' /usr/local/omc/etc/omc.conf
fi
;;
m)
M_ARG=$(echo $OPTARG | tr '[:upper:]' '[:lower:]')
if [ "${VENDORS}" == "BA" ]; then
C_ARG_LOWER="ba"
C_ARG_UPPER="BA"
fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
}
USER="root"
PASSWORD="1000omc@kp!"
PORT="33066"
DBNAME="tenants_db"
OMCRootDir=/usr/local/omc
OMCBinDir=${OMCRootDir}/bin
UpgradeSQLDir=${OMCRootDir}/etc/db/upgrade
Upgvue3SQLDir=${OMCRootDir}/etc/db/upgvue3
InstallSQLDir=${OMCRootDir}/etc/db/install
OMCStaticDir=${OMCRootDir}/static
check_args "$@"
case "${M_ARG}" in
install)
${OMCBinDir}/importdb.sh ${M_ARG}
if [ "${C_ARG_LOWER}" != "" ]; then
CustomizedDir=${OMCStaticDir}/${C_ARG_LOWER}.d
if [ ! -d "${CustomizedDir}" ]; then
echo "Not found ${C_ARG_UPPER} customized directory, nothing to be done"
exit 1
fi
echo -n "Setting ${C_ARG_UPPER} customized OMC ..."
for SQL in ${CustomizedDir}/db/*.sql; do
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
cp -rf ${CustomizedDir}/logo/* ${OMCStaticDir}/logo
cp -rf ${CustomizedDir}/doc/* ${OMCStaticDir}/helpDoc
#perl -0777 -i -pe 's/omcuser/bluearcus/g' ${OMCRootDir}/etc/default/restconf.yaml
#perl -0777 -i -pe 's/omcuser/bluearcus/g' ${OMCBinDir}/nehosts
if [ $? = 0 ]; then
echo "done"
fi
fi
;;
upgrade | upgvue3)
${OMCBinDir}/importdb.sh ${M_ARG}
;;
skip)
if [ "${C_ARG_LOWER}" != "" ]; then
CustomizedDir=${OMCStaticDir}/${C_ARG_LOWER}.d
if [ ! -d "${CustomizedDir}" ]; then
echo "Not found ${C_ARG_UPPER} customized directory, nothing to be done"
exit 1
fi
echo -n "Setting ${C_ARG_UPPER} customized OMC ..."
for SQL in ${CustomizedDir}/db/*.sql; do
mysql -u${USER} -p${PASSWORD} -P ${PORT} --protocol tcp -D ${DBNAME} < ${SQL};
done
cp -rf ${CustomizedDir}/logo/* ${OMCStaticDir}/logo
cp -rf ${CustomizedDir}/doc/* ${OMCStaticDir}/helpDoc
if [ $? = 0 ]; then
echo "done"
fi
fi
;;
*)
${OMCBinDir}/importdb.sh
;;
esac
exit 0

View File

@@ -1,23 +0,0 @@
#!/bin/bash
# 判断id_rsa密钥文件是否存在
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
else
echo "id_rsa has created ..."
fi
ip=$1
user=$2
passwd=$3
#分发到$ip主机.
expect <<EOF
set timeout 10
spawn ssh-copy-id -f $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$passwd\n" }
}
expect "password" { send "$passwd\n" }
EOF

View File

@@ -1,62 +0,0 @@
#!/bin/bash
config_file="/usr/local/omc/etc/restconf.yaml"
temp_file="/tmp/temp.yaml"
declare -A insert_lines=(
[156]=" dataCoding: 0"
[157]=" serviceNumber: \"OMC\""
)
declare -A update_lines=(
["deadLine: 10"]="deadLine: 600"
)
# check if exist file
if [[ ! -f $config_file ]]; then
echo "NOT FOUND config file: $config_file"
exit 1
fi
insert_if_missing() {
local line_number="$1"
local line_content="$2"
local current_content=$(sed -n "${line_number}p" "$config_file")
if [[ "$current_content" != "$line_content" ]]; then
# insert line to config file
echo -n "Inserting '$line_content' into line ${line_number} ... "
awk -v n="$line_number" -v line="$line_content" 'NR==n {print line} {print}' "$config_file" >"$temp_file" && mv "$temp_file" "$config_file"
if [ $? = 0 ]; then
echo "done"
fi
else
echo "Exist '$line_content' at line ${line_number}"
fi
}
# functionupdate line content
update_lines_content() {
local old_line="$1"
local new_line="$2"
echo -n "Updating '$old_line' to line '$new_line' ..."
sed -i "s/$old_line/$new_line/" "$config_file"
if [ $? = 0 ]; then
echo "done"
fi
}
#line_numbers=(156 157)
line_numbers=$(for key in "${!insert_lines[@]}"; do echo "$key"; done | sort -n)
# insert process
#for line_number in "${line_numbers[@]}"; do
#for line_number in "${!insert_lines[@]}"; do
for line_number in $line_numbers; do
insert_if_missing "$line_number" "${insert_lines[$line_number]}"
done
# update process
for old_line in "${!update_lines[@]}"; do
update_lines_content "$old_line" "${update_lines[$old_line]}"
done