1
0

feat: 添加OMC服务控制脚本并移除过时的脚本文件

This commit is contained in:
TsMask
2025-04-21 16:09:21 +08:00
parent fb021f4605
commit 38f6652301
11 changed files with 262 additions and 488 deletions

44
linux/usr/local/bin/omcd Normal file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
ServiceList="omc sshsvc"
case "$1" in
start)
for v in $ServiceList;do
systemctl start $v
if [ $? = 0 ]; then
echo "starting $v process done"
fi
sleep 1
done
;;
status)
for v in $ServiceList;do
systemctl status $v
done
;;
stop)
for v in $ServiceList;do
systemctl stop $procName
if [ $? = 0 ]; then
echo "Stopping $v process done"
fi
done
;;
restart)
$0 stop
sleep 1
$0 start
;;
version)
local BinDir=/usr/local/bin
for v in $ServiceList;do
$BinDir/$v --version
done
;;
*)
echo "OMC Service Control"
echo "Usage: $0 start|status|stop|restart|version"
echo ""
;;
esac

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,161 +0,0 @@
#!/bin/bash
USER="root"
PASSWORD="1000omc@kp!"
HOST="127.0.0.1"
PORT="33066"
DBNAME="omc_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} DROP INDEX IF EXISTS \`idx_uid_at\`;"
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_${ne_type}_uid_at\`(\`rm_uid\`, \`created_at\`) 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
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
SQL="ALTER TABLE ${TABLE_NAME} DROP INDEX IF EXISTS \`idx_c_uid_at\`;"
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_c_${ne_type}_uid_at\`(\`rm_uid\`, \`created_at\`) 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
done

View File

@@ -0,0 +1,177 @@
#!/bin/bash
# Defining a list of network elements
# ne_type,ne_ip,ne_port
NE_LIST=(
"OMC,172.16.5.100,33030"
"IMS,172.16.5.110,33030"
"AMF,172.16.5.120,33030"
"AUSF,172.16.5.130,33030"
"UDM,172.16.5.140,33030"
"SMF,172.16.5.150,33030"
"PCF,172.16.5.160,33030"
"UPF,172.16.5.190,33030"
)
# Default SSH info
DEFAULT_SSH_USER="manager"
# If you already have a password-free authorization, please set the password to ""
# DEFAULT_SSH_PWD=""
# password=admin123
DEFAULT_SSH_PWD="bSQ21KY7cjn58JNkZ0UZM64EbSIPMQwfCTmzk3MTBvQ="
DEFAULT_SSH_PORT=22
# Default ne_host info
DEFAULT_TELNET_PORT=4100
DEFAULT_TELNET_PORT2=5002
DEFAULT_REDIS_PORT=6379
# Default network element number ne_id
DEFAULT_NE_ID="001"
# Path to the output file
output_file="output.sql"
# Empty the contents of the file (if the file already exists)
> "$output_file"
# ======================= generate sql
# ne_info
# generate_ne_info 1 OMC 001 127.0.0.1 33030 1,2
generate_ne_info() {
local row_id=$1
local ne_type=$2
local ne_id=$3
local ip=$4
local port=$5
local ne_host=$6
local ne_name="${ne_type}_${ne_id}"
local ne_rmuid="4400HX${ne_type}${ne_id}"
echo "INSERT INTO ne_info VALUES (${row_id}, '${ne_type}', '${ne_id}', '${ne_rmuid}', '${ne_name}', '${ip}', ${port}, 'PNF', '-', '-', '-', '-', '${ne_host}', 1, '', '', 0, 'script', $(date +%s%3N));"
}
# ne_host
# generate_ne_host 1 OMC 001 127.0.0.1
generate_ne_host() {
local row_id=$1
local ne_type=$2
local ne_id=$3
local ip=$4
local ne_name="${ne_type}_${ne_id}"
local start_id=$row_id
local ssh_type="2"
local ssh_password=""
if [ -n "$DEFAULT_SSH_PORT" ]; then
ssh_type="0"
ssh_password="$DEFAULT_SSH_PWD"
fi
# SSH连接
echo "INSERT INTO ne_host VALUES (${start_id}, 'ssh', '1', '${ne_name}_${DEFAULT_SSH_PORT}', '${ip}', ${DEFAULT_SSH_PORT}, '${DEFAULT_SSH_USER}', '${ssh_type}', '${ssh_password}', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));"
((start_id++))
# Telnet连接
echo "INSERT INTO ne_host VALUES (${start_id}, 'telnet', '1', '${ne_name}_${DEFAULT_TELNET_PORT}', '${ip}', ${DEFAULT_TELNET_PORT}, 'admin', '0', 'okzArqkFYlnVVdQYkNiqmiW+CGQrxg1AFmroR1bw1Kg=', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));"
((start_id++))
# 特殊网元类型处理
case "$ne_type" in
"UDM")
echo "INSERT INTO ne_host VALUES (${start_id}, 'redis', '1', '${ne_name}_${DEFAULT_REDIS_PORT}', '${ip}', ${DEFAULT_REDIS_PORT}, 'udmdb', '0', 'jW965gWZK0mw6EtYfihMV9QqHjqa03vJ8VlVii9non8=', '', '', '0', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));"
;;
"UPF")
echo "INSERT INTO ne_host VALUES (${start_id}, 'telnet', '1', '${ne_name}_${DEFAULT_TELNET_PORT2}', '${ip}', ${DEFAULT_TELNET_PORT2}, 'admin', '0', '', '', '', '', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));"
;;
esac
}
# generate_ne_host_ids OMC 1
generate_ne_host_ids() {
local ne_type=$1
local start_id=$2
local ids="${start_id},$((start_id+1))"
case "$ne_type" in
"UDM")
ids="${ids},$((start_id+2))"
;;
"UPF")
ids="${ids},$((start_id+2))"
;;
esac
echo "$ids"
}
# ne_version
# generate_ne_version 1 OMC 001
generate_ne_version() {
local row_id=$1
local ne_type=$2
local ne_id=$3
echo "INSERT INTO ne_version VALUES (${row_id}, '${ne_type}', '${ne_id}', '-', '-', '-', '', '', '', '', '', '', '0', 'script', $(date +%s%3N), 'script', $(date +%s%3N));"
}
# ne_license
# generate_ne_license 1 OMC 001
generate_ne_license() {
local row_id=$1
local ne_type=$2
local ne_id=$3
echo "INSERT INTO ne_license VALUES (${row_id}, '${ne_type}', '${ne_id}', '', '', '', '', '1', '', 'script', $(date +%s%3N), 'script', $(date +%s%3N));"
}
# =======================
# Execute output sql to file
execute_output() {
local row_id=1
local host_id=1
# empty the table
echo "DELETE FROM ne_host;" >> "$output_file"
echo "DELETE FROM ne_info;" >> "$output_file"
echo "DELETE FROM ne_version;" >> "$output_file"
echo "DELETE FROM ne_license;" >> "$output_file"
echo "" >> "$output_file"
for v in "${NE_LIST[@]}"; do
IFS=',' read -r ne_type ne_ip ne_port <<< "$v"
echo "===> ${ne_type} ${ne_ip} ${ne_port}"
generate_ne_host "$host_id" "$ne_type" "$DEFAULT_NE_ID" "$ne_ip" >> "$output_file"
local host_ids=$(generate_ne_host_ids $ne_type $host_id)
generate_ne_info "$row_id" "$ne_type" "$DEFAULT_NE_ID" "$ne_ip" "$ne_port" "$host_ids" >> "$output_file"
generate_ne_version "$row_id" "$ne_type" "$DEFAULT_NE_ID" >> "$output_file"
generate_ne_license "$row_id" "$ne_type" "$DEFAULT_NE_ID" >> "$output_file"
echo "" >> "$output_file"
((row_id++))
case "$ne_type" in
"UDM"|"UPF")
host_id=$((host_id+3))
;;
*)
host_id=$((host_id+2))
;;
esac
done
}
execute_output
# Execute import sql to omc
execute_import() {
local OMCBinFile=/usr/local/bin/omc
local OMCEtcDir=/usr/local/etc/omc
local confFile=$OMCEtcDir/omc.yaml
source $OMCEtcDir/omc.conf
$OMCBinFile -c $confFile --sqlPath $output_file --sqlSource $MODE
}
execute_import
# Remove the output file
rm -rf $output_file

View File

@@ -1,100 +0,0 @@
#!/bin/bash
set -x
OMCBinFile=/usr/local/bin/omc
OMCEtcDir=/usr/local/etc/omc
confFile=$OMCEtcDir/omc.yaml
VariableFile=$OMCEtcDir/omc.conf
# Read the value of the variable from file
source $VariableFile
# ========================= ne_host
ne_host_id=0
# 调用函数生成并输出SQL语句
# ne_host "$ne_type" "$ne_ip" "$ne_port" "$ssh_ip" "$ssh_port"
ne_host() {
local ne_type=$1
local ne_ip=$2
local ne_port=$3
local ssh_ip=$4
local ssh_port=$5
local ssh_user="omcuser"
local ssh_type="2" # 0passwd 1sshkey 2notpwd
local ssh_passwd=""
local telnet_port=4100
local telnet_user="admin"
local telnet_password='NUBonCin4GZgl7o12YjeClE8ToQmYp9KWdhMjSNxc2M='
local timestamp=$(date +%s%3N)
# 根据ne_type生成对应的ne_name
case $ne_type in
"UDM")
let ne_host_id++
echo "INSERT INTO "ne_host" VALUES ($ne_host_id, 'ssh', '1', '$ne_type_S_$timestamp', '$ssh_ip', $ssh_port, '$ssh_user', '$ssh_type', '$ssh_passwd', '', '', '', '', 'system', $timestamp, '', 0);" >> "$output_file"
local host_ids="${ne_host_id}"
let ne_host_id++
echo "INSERT INTO "ne_host" VALUES ($ne_host_id, 'telnet', '1', '$ne_type_T_$timestamp', '$ne_ip', $telnet_port, '$telnet_user', '0', '$telnet_password', '', '', '', '', 'system', $timestamp, '', 0);" >> "$output_file"
local host_ids="${host_ids},${ne_host_id}"
let ne_host_id++
echo "INSERT INTO "ne_host" VALUES ($ne_host_id, 'redis', '1', '$ne_type_R_$timestamp', '$ne_ip', 6379, 'udmdb', '0', 'nO3fEhtuKuBkQE5ozsUhNfzn02vhnyxYTEiPn2CIlr4=', '', '', '0', '', 'system', $timestamp, '', 0);" >> "$output_file"
local host_ids="${host_ids},${ne_host_id}"
echo "${host_ids}"
;;
"UPF")
let ne_host_id++
echo "INSERT INTO "ne_host" VALUES ($ne_host_id, 'ssh', '1', '$ne_type_S_$timestamp', '$ssh_ip', $ssh_port, '$ssh_user', '$ssh_type', '$ssh_passwd', '', '', '', '', 'system', $timestamp, '', 0);" >> "$output_file"
local host_ids="${ne_host_id}"
ne_host_id=$((ne_host_id + 1))
echo "INSERT INTO "ne_host" VALUES ($ne_host_id, 'telnet', '1', '$ne_type_T_$timestamp', '$ne_ip', $telnet_port, '$telnet_user', '0', '$telnet_password', '', '', '', '', 'system', $timestamp, '', 0);" >> "$output_file"
local host_ids="${host_ids},${ne_host_id}"
let ne_host_id++
echo "INSERT INTO "ne_host" VALUES ($ne_host_id, 'telnet', '1', '$ne_type_TT_$timestamp', '$ne_ip', 5002, 'admin', '0', '', '', '', '0', '', 'system', $timestamp, '', 0);" >> "$output_file"
local host_ids="${host_ids},${ne_host_id}"
echo "${host_ids}"
;;
*)
let ne_host_id++
echo "INSERT INTO "ne_host" VALUES ($ne_host_id, 'ssh', '1', '${ne_type}_S_${timestamp}', '$ssh_ip', $ssh_port, '$ssh_user', '$ssh_type', '$ssh_passwd', '', '', '', '', 'system', $timestamp, '', 0);" >> "$output_file"
local host_ids="${ne_host_id}"
let ne_host_id++
echo "INSERT INTO "ne_host" VALUES ($ne_host_id, 'telnet', '1', '${ne_type}_S_${timestamp}', '$ne_ip', $telnet_port, '$telnet_user', '0', '$telnet_password', '', '', '', '', 'system', $timestamp, '', 0);" >> "$output_file"
local host_ids="${host_ids},${ne_host_id}"
echo "${host_ids}"
;;
esac
}
# =========================
# 输出的文件路径
output_file="output.sql"
# 清空文件内容(如果文件已存在)
> "$output_file"
# 定义ne_types数组
# ne_type ne_ip ne_port ssh_ip ssh_port
ne_types=(
"OMC,172.16.5.110,33030,127.0.0.1,22"
"IMS,172.16.5.110,33030,127.0.0.1,22"
"AMF,172.16.5.110,33030,127.0.0.1,22"
)
# 循环处理ne_types数组
for v in "${ne_types[@]}"; do
# 解析每一项
IFS=',' read -r ne_type ne_ip ne_port ssh_ip ssh_port <<< "$v"
host_ids=$(ne_host "$ne_type" "$ne_ip" "$ne_port" "$ssh_ip" "$ssh_port")
ne_host_id=$(echo "$host_ids" | awk -F',' '{print $NF}') # 提取最后一个值并赋值给ne_host_id
echo "===> ${host_ids}"
done
echo "SQL语句已写入 $output_file"
# =========================
#$OMCBinFile -c $confFile --sqlPath $OMCEtcDir/database/$MODE/$T_PARAM --sqlSource $MODE
# bash link_ne.sh

View File

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

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,112 +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
elif [ "${C_ARG_LOWER}" == "agt" ]; then
C_ARG_UPPER="AGT"
sed -i 's/VENDORS=.*/VENDORS=AGT/' /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="omc_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
if [ "${C_ARG_LOWER}" == "ba" ]; then
rm -rf ${OMCStaticDir}/logo/zh_*
rm -rf ${OMCStaticDir}/helpDoc/zh_*
fi
#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 [ "${C_ARG_LOWER}" == "ba" ]; then
rm -rf ${OMCStaticDir}/logo/zh_*
rm -rf ${OMCStaticDir}/helpDoc/zh_*
fi
if [ $? = 0 ]; then
echo "done"
fi
fi
;;
*)
${OMCBinDir}/importdb.sh
;;
esac
exit 0

View File

@@ -0,0 +1,41 @@
#!/bin/bash
# Defining a list of SSH
# ssh_user,ssh_ip
# ssh_user,ssh_ip,ssh_port
SSH_LIST=(
"manager,172.16.5.100"
"manager,172.16.5.110"
"manager,172.16.5.120"
"manager,172.16.5.130"
"manager,172.16.5.140"
"manager,172.16.5.150"
"manager,172.16.5.160"
"manager,172.16.5.190"
)
DEFAULT_SSH_PORT=22
# Create .ssh directory if it doesn't exist
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Check if the SSH key already exists
if [ ! -f ~/.ssh/id_rsa ]; then
# Generate SSH key
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
fi
for v in "${SSH_LIST[@]}"; do
IFS=',' read -r ssh_user ssh_ip ssh_port <<< "$v"
if [ -z "$ssh_port" ]; then
ssh_port=$DEFAULT_SSH_PORT
fi
echo "===> ${ssh_user} ${ssh_ip} ${ssh_port}"
# Copy public key content
cat ~/.ssh/id_rsa.pub | ssh -p ${ssh_port} ${ssh_user}@${ssh_ip} "\
mkdir -p ~/.ssh && chmod 700 ~/.ssh && \
touch ~/.ssh/authorized_keys && chmod 775 ~/.ssh/authorized_keys && \
cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
done

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