[英]OpenWRT ASH script
I am trying to write an ASH script to run on my OpenWRT router. 我正在尝试编写ASH脚本以在我的OpenWRT路由器上运行。
I have installed onto it nodogsplash, which displays a login page when you first try to authenticate with the router. 我已经在其上安装了nodogsplash,当您首次尝试通过路由器进行身份验证时,它将显示一个登录页面。
nodogsplash comes with a command line utility which allows you to change the password: nodogsplash带有一个命令行实用程序,可让您更改密码:
ndsctl password newpassword
So I am trying to write a script which I can setup as a cron job to run once a day to change the password to something new, however I am struggling to get it to output correctly. 因此,我试图编写一个脚本,该脚本可以设置为cron作业,每天运行一次,以将密码更改为新密码,但是我正在努力使其正确输出。 My script atm:
我的脚本atm:
#!/bin/ash
local randompassLength
local pass
randompassLength=8
pass=</dev/urandom tr -dc A-Za-z0-9 | head -c $randompassLength
ndsctl password "$pass"
When I run this I get the output: 当我运行它时,我得到输出:
miqM2Ah6Password set to .
Which seems to chuck the password at the start of the echo and set the password to blank. 这似乎在回显开始时就忘记了密码,并将密码设置为空白。
Any ideas what I am doing wrong here? 有什么想法我在这里做错了吗?
You're missing command substitution: 您缺少命令替换:
pass=$(</dev/urandom tr -dc A-Za-z0-9 | head -c $randompassLength)
or using backquotes: 或使用反引号:
pass=`</dev/urandom tr -dc A-Za-z0-9 | head -c $randompassLength`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.