免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1690 | 回复: 9
打印 上一主题 下一主题

[系统管理] 问大家一个关于管道的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-20 11:20 |只看该作者 |倒序浏览
我们在弄一个关于Redis的项目
然后用的时候发现一个奇怪问题
[mailcontrol@cog01o threatscope]$ redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*"                    
1) "0057b67f7d433c0e85a057e0e2c0f4f9022390a5.workload"
2) "wts_resource_status.0057b67f7d433c0e85a057e0e2c0f4f9022390a5"
[mailcontrol@cog01o threatscope]$ redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*"  | awk '{print $1}'
0057b67f7d433c0e85a057e0e2c0f4f9022390a5.workload
wts_resource_status.0057b67f7d433c0e85a057e0e2c0f4f9022390a5
[mailcontrol@cog01o threatscope]$ redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*"  | awk '{print $0}'
0057b67f7d433c0e85a057e0e2c0f4f9022390a5.workload
wts_resource_status.0057b67f7d433c0e85a057e0e2c0f4f9022390a5

我的问题是,为什么在Awk的输出 print时, redis的输出"1)  2)" 没有了。
按理说, redis的整行输出   
“1)  "0057b67f7d433c0e85a057e0e2c0f4f9022390a5.workload"” 是awk的输入。
为什么打印时 字符"1)"没有了呢?


请大侠赐教

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
2 [报告]
发表于 2013-05-20 11:38 |只看该作者
  1. redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*"   |tee output
复制代码
看看output里有什么?

论坛徽章:
0
3 [报告]
发表于 2013-05-20 11:41 |只看该作者
[mailcontrol@cog01o threatscope]$ redis-cli -n 1 keys "*6a0598c55acd4398ae72e584fea6df17cb5bfe92*" | tee output
wts_resource_status.6a0598c55acd4398ae72e584fea6df17cb5bfe92

只有一列,那 “1)” 这是什么时候加上去的呢

论坛徽章:
0
4 [报告]
发表于 2013-05-20 11:48 |只看该作者
# /bin/redis-cli -p 12345 keys "*sha*"
1) "qadmin_script_sha_list"

# strace -e trace=write /bin/redis-cli -p 12345 keys "*sha*"
write(3, "*2\r\n$4\r\nkeys\r\n$5\r\n*sha*\r\n", 25) = 25
write(1, "1) \"qadmin_script_sha_list\"\n", 281) "qadmin_script_sha_list"
) = 28

# strace -e trace=write /bin/redis-cli -p 12345 keys "*sha*" | awk '{}1'
write(3, "*2\r\n$4\r\nkeys\r\n$5\r\n*sha*\r\n", 25) = 25
write(1, "qadmin_script_sha_list\n", 23) = 23
qadmin_script_sha_list

应该是redis-cli搞的鬼,可能是在检测到输出重定向了之后就不加序号了,我猜

论坛徽章:
0
5 [报告]
发表于 2013-05-20 12:48 |只看该作者
回复 4# jichl

这个应该不成立吧,执行中的命令,怎么知道自己的输出被重定向了呢?
   

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
6 [报告]
发表于 2013-05-20 13:08 |只看该作者
这样行吗?
  1. redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*" 2>&1 | awk '{print $1}'
复制代码

论坛徽章:
0
7 [报告]
发表于 2013-05-20 13:51 |只看该作者
[mailcontrol@cog01o ~]$ redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*" 2>&1 | awk '{print $1}'
0057b67f7d433c0e85a057e0e2c0f4f9022390a5.workload
wts_resource_status.0057b67f7d433c0e85a057e0e2c0f4f9022390a5

[mailcontrol@cog01o ~]$ redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*" 2>&1                  
1) "0057b67f7d433c0e85a057e0e2c0f4f9022390a5.workload"
2) "wts_resource_status.0057b67f7d433c0e85a057e0e2c0f4f9022390a5"

论坛徽章:
0
8 [报告]
发表于 2013-05-20 13:56 |只看该作者
回复 6# Shell_HAT


   

论坛徽章:
0
9 [报告]
发表于 2013-05-20 14:44 |只看该作者
回复 6# Shell_HAT


    [mailcontrol@cog01o ~]$ redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*" 2>&1 | awk '{print $1}'
0057b67f7d433c0e85a057e0e2c0f4f9022390a5.workload
wts_resource_status.0057b67f7d433c0e85a057e0e2c0f4f9022390a5


[mailcontrol@cog01o ~]$ redis-cli -n 1 keys "*0057b67f7d433c0e85a057e0e2c0f4f9022390a5*" 2>&1                  
1) "0057b67f7d433c0e85a057e0e2c0f4f9022390a5.workload"
2) "wts_resource_status.0057b67f7d433c0e85a057e0e2c0f4f9022390a5"

论坛徽章:
0
10 [报告]
发表于 2013-05-20 16:27 |只看该作者
本帖最后由 jichl 于 2013-05-20 16:37 编辑

回复 9# h_virus


#redis-cli -h
redis-cli 2.5.9

Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
  -h <hostname>    Server hostname (default: 127.0.0.1)
  -p <port>        Server port (default: 6379)
  -s <socket>      Server socket (overrides hostname and port)
  -a <password>    Password to use when connecting to the server
  -r <repeat>      Execute specified command N times
  -i <interval>    When -r is used, waits <interval> seconds per command.
                   It is possible to specify sub-second times like -i 0.1.
  -n <db>          Database number
  -x               Read last argument from STDIN
  -d <delimiter>   Multi-bulk delimiter in for raw formatting (default: \n)
  -c               Enable cluster mode (follow -ASK and -MOVED redirections)
  --raw            Use raw formatting for replies (default when STDOUT is not a tty)
  --latency        Enter a special mode continuously sampling latency.
  --slave          Simulate a slave showing commands received from the master.
  --bigkeys        Sample Redis keys looking for big keys.
  --eval <file>    Send an EVAL command using the Lua script at <file>.
  --help           Output this help and exit
  --version        Output version and exit

Examples:
  cat /etc/passwd | redis-cli -x set mypasswd
  redis-cli get mypasswd
  redis-cli -r 100 lpush mylist x
  redis-cli -r 100 -i 1 info | grep used_memory_human:
  redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
  (Note: when using --eval the comma separates KEYS[] from ARGV[] items)

When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands.


是根据标准输出的类型判断是否要格式化输出的,加上--raw参数就按照原始数据输出了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP