我正在尝试制作这样的脚本:
#!/bin/bash
sudo -s
something...
Run Code Online (Sandbox Code Playgroud)
当我执行它时,我得到了一个新的 shell,但something
只有当我退出由sudo -s
.
有什么帮助吗?
一旦我的树莓派连接到互联网,我就需要执行一个脚本。但是我想知道是否有比每分钟左右 ping Google 更好的方法。
我的问题是我的 Internet 连接在白天断开了 1-2 次,因此我需要一种方法来记录此类事件。
这只是白天的 ADSL 掉线,我一直在寻找某种方式来记录它何时发生,即使我没有注意到。我想我会按照建议设置一个脚本。
我正在尝试设置 cron 以在夜间(从 23:00 到 8:00)关闭我的 Raspberry Pi 上的网络。
问题是这些命令都没有完成这项工作:
$ sudo service networking stop
$ sudo ifconfig eth0 down
$ sudo ifdown eth0
Run Code Online (Sandbox Code Playgroud)
从输出看来,该命令有效,但界面仍在运行(我可以,ping 8.8.8.8
并且它存在于 中ifconfig
)。
这是内容 /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet manual
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Run Code Online (Sandbox Code Playgroud)
ifconfig
(屏蔽 MAC)的输出
eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:192.168.1.102 Bcast:192.168.1.255 Mask:255.255.255.0
UP …
Run Code Online (Sandbox Code Playgroud) 我有一个这样的脚本:
#!/bin/bash
clear
echo -n "Choose an option:
1) Encrypt
2) Decrypt
3) Quit
-> "
read opzione
if [ "$opzione" == "1" ]; then
echo -n "Drag here the file to encrypt: "
read chiaro
...
fi
Run Code Online (Sandbox Code Playgroud)
我想让脚本在输入数字后自动接受该数字。是否可以?
谢谢