2012-11-01 37 views
1

我想写一个ASH脚本在我的OpenWRT路由器上运行。OpenWRT ASH脚本

我已经安装到它nodogsplash,当您第一次尝试使用路由器进行身份验证时,它会显示一个登录页面。

nodogsplash带有一个命令行工具,它允许您更改密码:

ndsctl password newpassword 

所以我想写一个剧本,我可以设置为一个cron作业运行的每天一次改变密码到新的东西,但我很努力让它输出正确。我的脚本大气压:

#!/bin/ash 
local randompassLength 
local pass 
randompassLength=8 
pass=</dev/urandom tr -dc A-Za-z0-9 | head -c $randompassLength 
ndsctl password "$pass" 

当我运行此我得到的输出:

miqM2Ah6Password set to . 

这似乎扔在回波开始时的密码,密码设置为空。

任何想法,我做错了什么?

回答

1

你缺少命令替换:

pass=$(</dev/urandom tr -dc A-Za-z0-9 | head -c $randompassLength) 

或使用反引号:

pass=`</dev/urandom tr -dc A-Za-z0-9 | head -c $randompassLength`