構成ファイルのIPアドレスを更新するためのスクリプト

構成ファイルのIPアドレスを更新するためのスクリプト

ユーザーに元のIPと新しいIPを要求するスクリプトを作成しています。 CLIでsedを機能させることはできますが、ユーザーがWebサーバーでアクセス用にパブリックIPを更新できるようにスクリプトを作成したいと思います。

次のエラーが発生しますが、EOFを見つける理由はわかりません。

./UpdateIP.sh: line 24: unexpected EOF while looking for matching `''
 ./UpdateIP.sh: line 25: syntax error: unexpected end of file

これは私のスクリプトです。

#!/bin/bash

# This script will change the IP address from x.x.x.x TO y.y.y.y

configs=/root/test.conf

echo "Please enter the IP Address to change:"

# Ask user to input for IP address
read origip

echo "Please enter the NEW IP Address to be changed to:"
read newip


echo "The original IP in the lines below will be changed FROM:
sed 's/$(origip)/$(newip)/' $(configs) | grep $(origip)
echo "TO:"
sed 's/$(origip)/$(newip)/' $(configs) | grep $(newip)

read -p "Press [Enter] key to start updating IP's..."

ベストアンサー1

次のスクリプトを使用して新しいIPアドレスを更新できます。

テストされていて、うまく動作します。

script

#!/bin/bash
echo "enter the old ip adress which need to change"
read oldip
echo "enter the new ip adress"
read newip

sed -i "s/$oldip/$newip/g" configfilename

おすすめ記事