반응형
#!bin/bash
home_dir=/home/tool/
mkdir -p $home_dir
date=`date +%Y%m%d%H%M`
output_file="${home_dir}/values_${date}.csv"
#List file must in need 3 values, id, ip, hostname
####### Example List file values
# 1 192.168.10.1 Server1
# 2 192.168.10.2 Server2
# 3 192.168.10.3 Server3
file="$home_dir/****.list"
username=""
password=""
content=$(cat "$file")
IFS=$'\n'
for line in $content; do
id=$(echo "$line" | cut -d ' ' -f 1)
ip=$(echo "$line" | cut -d ' ' -f 2)
hostname=$(echo "$line" | cut -d ' ' -f 3)
echo "-----------------------------------------------------------------------------" | tee -a "$output_file"
printf "%-12s %-18s %-30s \n" $id $ip $hostname | tee -a "$output_file"
echo "-----------------------------------------------------------------------------" | tee -a "$output_file"
if [[ -z "$id" || -z "$ip" || -z "$dn" ]]; then
echo "Error: Missing value in line: $line"
exit 1
else
sshpass -p "${password}" ssh -o StrictHostKeyChecking=no -o LogLevel=quiet "${username}"@"${ip}" -p 22 "cat /etc/TEST" | tee -a "$output_file"
echo "" | tee -a "$output_file"
sleep 1
fi
done
echo "--------------complete---------------"
--------------Execution Result-------------------
-----------------------------------------------------------------------------
1 192.168.10.1 Server1
-----------------------------------------------------------------------------
!!!!!!!!!!!!!!!
-----------------------------------------------------------------------------
2 192.168.10.2 Server2
-----------------------------------------------------------------------------
!!!!!!!!!!!!!!!
-----------------------------------------------------------------------------
3 192.168.10.3 Server3
-----------------------------------------------------------------------------
!!!!!!!!!!!!!!!
--------------complete---------------
반응형
'Command & Development > Shell Script' 카테고리의 다른 글
[Shell Script] HP Server Health check Shell(Update) (0) | 2023.09.06 |
---|---|
[ShellScript] DB, NFS Backup check (0) | 2023.07.18 |
[ShellScript] Avamar Backup Check (0) | 2023.07.17 |
[Shell Script] iLO Health Check Script (0) | 2023.02.21 |
[Shell Script] Linux 설치 후 초기 설정 (0) | 2023.01.31 |