下面的bash腳本在L1上每10分鐘運行一次,腳本內部是爲了生成一個隨機密碼,然後將其打印到文件中,然後將其複製到L2。Bash腳本 - Crontab完成bash腳本的一部分但不是全部
#!/bin/bash
targetFile="testfilegen2.log"
address="192.168.1.1"
netmask="255.255.255.0"
channel="1"
essid="GreRPi"
random=$(pwgen 13 -1)
sudo echo "source-directory /etc/network/interfaces.d" > "$targetFile"
sudo echo "auto lo" >> "$targetFile"
sudo echo "auto wlan0" >> "$targetFile"
sudo echo "allow-hotplug wlan0" >> "$targetFile"
sudo echo "iface wlan0 inet static" >> "$targetFile"
sudo echo "address $address" >> "$targetFile"
sudo echo "netmask $netmask" >> "$targetFile"
sudo echo "wireless-channel $channel" >> "$targetFile"
sudo echo "wireless-essid $essid" >> "$targetFile"
sudo echo "wireless-mode ad-hoc" >> "$targetFile"
sudo echo "wireless-key s:$random" >> "$targetFile"
sleep 1
scp "$targetFile" [email protected]:~/.ssh/
sudo service networking restart
Unfornaltey L1似乎並沒有收到新的密碼,但L2一樣。
L1輸出
[email protected]:/etc/greenwich $ cat testfilegen2.log
source-directory /etc/network/interfaces.d
auto lo
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
wireless-channel 1
wireless-essid GreRPi
wireless-mode ad-hoc
wireless-key s:she5Bie1ojoon
L2輸出
[email protected]:~/.ssh $ cat testfilegen2.log
source-directory /etc/network/interfaces.d
auto lo
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.1
netmask 255.255.255.0
wireless-channel 1
wireless-essid GreRPi
wireless-mode ad-hoc
wireless-key s:ez2eeCeich0oc
任何建議?
謝謝
你檢查腳本的日誌,它說:「訪問被拒絕」? –