-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassive_configure.sh
More file actions
executable file
·49 lines (41 loc) · 1.77 KB
/
passive_configure.sh
File metadata and controls
executable file
·49 lines (41 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# SSH into the target machine(s) and update the configuration files to enable passive
# NOTE: not very secure, only for testing/QA purposes
IP_LIST=( "192.168.141.136") # CentOS
IP_LIST+=("192.168.141.137") # RHEL
# IP_LIST+=("192.168.1.12" "192.168.1.14") # Oracle Linux
IP_LIST+=("192.168.43.138" "192.168.43.137" "192.168.43.130") # Ubuntu
# IP_LIST+=("192.168.0.251" "192.168.0.236") # Debian
SSH_USER="root"
SSH_PASS="welcome"
declare -A FILE_MODIFICATIONS=(
["/usr/local/ncpa/etc/ncpa.cfg"]="s/^handlers = .*/handlers = nrdp/"
["/usr/local/ncpa/etc/ncpa.cfg.d/example.cfg_1"]="s/#\[passive checks\].*/[passive checks]/"
["/usr/local/ncpa/etc/ncpa.cfg.d/example.cfg_2"]="s/^#%HOSTNAME%\(.*\)/%HOSTNAME%\1/"
)
for IP in "${IP_LIST[@]}"
do
echo "Connecting to $IP"
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 "${SSH_USER}@${IP}" "exit"
if [ $? -ne 0 ]; then
echo "Failed to connect to $IP. Skipping..."
continue
fi
for FILE in "${!FILE_MODIFICATIONS[@]}"
do
FILE_PATH="${FILE%_*}"
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "${SSH_USER}@${IP}" "sudo sed -i '${FILE_MODIFICATIONS[$FILE]}' $FILE_PATH"
if [ $? -eq 0 ]; then
echo "Successfully updated $FILE_PATH on $IP"
else
echo "Failed to update $FILE_PATH on $IP"
fi
done
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "${SSH_USER}@${IP}" "sudo systemctl restart ncpa"
if [ $? -eq 0 ]; then
echo "Successfully restarted NCPA service on $IP"
else
echo "Failed to restart NCPA service on $IP"
fi
echo ""
done