我知道还有其他关于此的帖子,但我无法让它们中的任何一个工作。我的问题是我想在我的 rpi 上创建一个脚本来自动更改 wifi 网络并在静态和 dhcp 之间更改 eth0。它还没有完成我目前只在无线部分工作。但到目前为止的剧本是……
#!/bin/bash
ANS=''
ssid=''
psk=''
file='/etc/network/interfaces'
function wireless {
echo 'The wireless network '$ssid' has now been set up'
start
}
function ssid {
echo 'What is your Network SSID?'
echo -e '> \c'
read ssid
echo 'You entered '$ssid'. Is this correct? (y/n)'
echo -e '> \c'
read ANS
if [ $ANS = 'y' ]; then
psk
else
echo 'Please renter your SSID'
ssid
fi
}
function psk {
echo 'What is your Network PSK?'
echo -e '> \c'
read psk
echo 'You entered '$psk'. Is this correct? (y/n)'
echo -e '> \c'
read ANS
if [ $ANS = 'y' ]; then
wireless
else
echo 'Please renter your PSK'
psk
fi
}
function start {
echo 'What do you want to do?'
echo ''
echo 'Press w to set up wireless ssid and psk'
echo 'Press s to change eth0 to a static ip address'
echo 'Press d to change eth0 to a dhcp ip address'
echo ''
echo 'Or press ctrl+c to quit'
echo -e '> \c'
read ANS
if [ $ANS = 'w' ]; then
ssid
else
if [ $ANS = 's' ]; then
static
else
if [ $ANS = 'd' ]; then
dhcp
fi
fi
fi
}
#backup of /etc/network/interfaces
#auto lo
#iface lo inet loopback
#iface eth0 inet dhcp
#iface eth0 inet static
# address ###########
# netmask #############
# broadcast ###########
# gateway ##########
#
#allow-hotplug wlan0
#
#auto wlan0
#
#iface wlan0 inet dhcp
#wpa-ssid "Home Network"
#wpa-psk "psk"
start
exit 0
所以这一切都很好,但是在无线功能中,我想将 psk 和 ssid 发送到 /etc/network/interfaces 的第 15 行和第 16 行。请有人告诉我最好的方法来做到这一点。谢谢