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
相关文章推荐
- redis数据类型SortedSet的常用命令
- Centos7.0安装redis
- Redis集群搭建详细过程整理备忘
- 超强、超详细Redis数据库入门教程
- windows系统下使用.net简单操作redis
- Redis 集群
- Linux下Redis主从复制(master-slave)配置
- CAS 4.0 Cluster / Tomcat redis Session manager / Token(TGT)存入Redis集群 / Nginx 负载
- redis的pconnect解析
- redis的pconnect
- windows 下安装redis
- redis 的用法
- CubieTruck安装Redis
- redis数据类型Set的常用命令
- redis.conf配置详细解析
- 启动redis的步骤
- redis的导入导出需要特别注意的地方
- redis的导入导出需要特别注意的地方
- Redis客户端开发包:Jedis学习-高级应用
- redis数据类型Hash的常用命令