1
0

sql: 新增脚本link_ne.sh,初始网元信息SQL语句

This commit is contained in:
TsMask
2025-04-01 18:20:44 +08:00
parent 79b1eb8364
commit 6fdc7738db

View File

@@ -0,0 +1,100 @@
#!/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