fix: ...
This commit is contained in:
@@ -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}/psapsvc.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}/psapsvc.sh restart >> ${logFile}
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
|
|
||||||
echo "The file does not have a .deb or .rpm extension"
|
|
||||||
exit 100
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# host user password
|
|
||||||
# Example: 172.16.5.100 omcuser password
|
|
||||||
@@ -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}/psapsvc.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}/psapsvc.sh restart >> ${logFile}
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
|
|
||||||
echo "The file does not have a .deb or .rpm extension"
|
|
||||||
exit 100
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
# function:update 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
|
|
||||||
Reference in New Issue
Block a user