Answer the question
In order to leave comments, you need to log in
How to make sh work?
Good day!
I wrote a code for connecting to remote workstations and executing commands on it, but not everything works so smoothly, I don’t know how to make it read ip from a file and how to make it execute " grep DOMAIN=..."
on a remote host
#!/bin/bash
clear
echo "Подключаемся к хосту"
ssh [email protected] << EOF
yum -y screen
grep 'DOMAIN=' /etc/sysconfig/network-scripts/ifcfg-eth0 &> /dev/null; if [ $? -eq 0 ]; then export DOMAIN=locl.dom && sed -i '' -e "s|DOMAIN=.*$|DOMAIN=$DOMAIN|" /etc/sysconfig/network-scripts/ifcfg-eth0; else echo "DOMAIN=locl.dom" >> /etc/sysconfig/network-scripts/ifcfg-eth0; fi
service network restart
Answer the question
In order to leave comments, you need to log in
If I correctly understood all your wishes for this crutch, then this is what happened:
The script itself:
#!/usr/bin/env bash
FILE="/path/to/file_with_ip/ip"
USER="root"
while read -r ip_addr; do
ssh "$USER"@"$ip_addr" << "EOF"
interface=$(/usr/sbin/ifconfig -a | grep "UP" | grep -v "lo" | awk -F ": " '{ print $1 }')
if grep 'DOMAIN' /etc/sysconfig/network-scripts/ifcfg-$interface &>/dev/null; then export DOMAIN=SIZ37.LAN && sed -i -e "s|DOMAIN=.*$|DOMAIN=$DOMAIN|" /etc/sysconfig/network-scripts/ifcfg-$interface; else echo "DOMAIN=locl.dom" >> /etc/sysconfig/network-scripts/ifcfg-$interface; fi
service network restart
EOF
done < <(cat $FILE)
$cat /path/to/file_with_ip/ip
172.16.0.1
172.16.0.2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question