您的位置:首页 > 数据库 > Redis

redis脚本:查看近一小时内有哪些用户登录过redis

2016-07-20 17:27 615 查看
#! /bin/bash
declare -i now_time=$(date +%s)
declare -i an_hour_age=$(date -d '-1 hours' +%s)
port=6379
while [ $an_hour_age -lt $now_time ]
do
~/redis-3.2.1/src/redis-cli -p $port client list >> /tmp/client_list
an_hour_age=$an_hour_age+1
done


注:

在CentOS系统的虚拟机上,用sh执行脚本,发现成功运行。

将脚本拷贝到Debian系统上时,用sh执行脚本,发现报错:declare: not found。

但当用bash执行时,成功。

百度后,发现原因:用sh执行脚本*.sh文件,其中文件*.sh中包含declare的变量声明,但这样却现实not found declare,

用chmod 755 *.sh,然后./*.sh脚本运行正常,或者直接bash  *.sh也能运行,这是因为sh是链接的是dash,不是bash。

Debian/Ubuntu安装的时候使用了dash,dash比bash体积小速度快,兼容性高!

但是在bash下可以正常运行的一些sh在dash下不能使用,造成了一些麻烦。

为了解决之,键入sudo dpkg-reconfigure dash,重新配置dash,并选择“no”,即不使用dash。

总结:用bash可以保证脚本能执行。

附:查看sh的链接

$ ls -l /bin/sh 

lrwxrwxrwx  1 root root 4 Mar 21  2007 /bin/sh -> bash
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: