html tool

显示标签为“xshell”的博文。显示所有博文
显示标签为“xshell”的博文。显示所有博文

2021年6月28日星期一

增加root權限為非root用戶

 visudo

    ## Allow root to run any commands anywhere

    root ALL=(ALL) ALL

    s ALL=(ALL) NOPASSWD:ALL        # 添加该行,增加root權限為s用戶

2019年12月4日星期三

shell脚本获得redis中全部的值


  1 #!/usr/bin/env bash
  2 connect_redis="redis-cli -h 1.1.1.1 -p 6379 -a 123456 -n 0"
  3 #redis-cli -h 1.1.1.1 -p 6379 -a 123456 -n 0 keys  '*' | 
  4 ${connect_redis} keys  'api_privilege_*' |
  5 while read key
  6 do       
  7     key_type=`${connect_redis} type ${key}`
  8     if [[ "${key_type}"=="hash" ]] 
  9     then 
 10         key_val=`${connect_redis} hgetall    ${key}`
 11         #echo "${connect_redis} hgetall    ${key}"
 12     else 
 13         key_val=`${connect_redis} get   ${key}`
 14          
 15     fi   
 16     echo ${key},${key_val}
 17 done     



参考:https://blog.csdn.net/chinabestchina/article/details/79113177
其中:
-h 代表redis安装地址
-p 代表redis端口
-a 代表redis访问密码
-n 代表redis数据库的db index
PS:查看redis中使用的db index的方式
你可以使用以下命令来了解数据库的数量:
CONFIG GET databases
1) "databases"
2) "16"
也可以使用以下命令列出定义了某些键的数据库:
INFO keyspace
# Keyspace
db0:keys=10,expires=0
db1:keys=1,expires=0
db3:keys=1,expires=0

2019年1月21日星期一

xxd-linux 直接修改二进制方式


https://zhuanlan.zhihu.com/p/24883064

读取文件,二进制显示
$ xxd file1
00000000: 736f 6d65 2063 6f6e 7465 6e74 206f 6620  some content of
00000010: 6669 6c65 310a                           file1.
xxd 可以做反向 dump ,这就很“魔法”了(手册里作者原话)。 怎么 revert dump 呢?直接上代码
$ xxd file1 file1.dump
$ cat file1.dump 
00000000: 736f 6d65 2063 6f6e 7465 6e74 206f 6620  some content of 
00000010: 6669 6c65 310a                           file1.
$ vim file1.dump 
# magic editing...
$ cat file1.dump
00000000: 736f 6d65 4d41 4749 4321 6e74 206f 6620  some content of 
00000010: 6669 6c65 310a                           file1.
$ xxd -r file1.dump 
someMAGIC!nt of file1
很简单吧?直接加 -r 参数就能做反向 dump 。所以一般步骤是先 xxd TARGET DUMP_FILE 导出,然后修改 DUMP_FILE ,最后 xxd -r DUMP_FILE NEW_FILE (没有NEW_FILE 的时候默认输出到标准输出)。[popexizhi: 这个确实好魔幻啊,赞一个]

PS:
简单说下 vim 集成:
  • 先用二进制方式打开文件 vim FILE -b
  • 在正常模式下输入魔法 :%!xxd
  • 修改
  • 退出到正常模式,继续魔法 :%!xxd -r
用 -b 选项(即二进制模式)打开文件很重要啊!!!

转:linux shell tcp测试


https://www.cnblogs.com/chengmo/archive/2010/10/22/1858302.html


linux 设备里面有个比较特殊的文件:
/dev/[tcp|upd]/host/port 只要读取或者写入这个文件,相当于系统会尝试连接:host 这台机器,对应port端口。如果主机以及端口存在,就建立一个socket 连接。将在,/proc/self/fd目录下面,有对应的文件出现。
一、测试下:/dev/tcp/host/post文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[chengmo@centos5  shell]$ cat</dev/tcp/127.0.0.1/22
SSH-2.0-OpenSSH_5.1
#我的机器shell端口是:22
#实际:/dev/tcp根本没有这个目录,这是属于特殊设备
[chengmo@centos5  shell]$ cat</dev/tcp/127.0.0.1/223
-bash: connect: 拒绝连接
-bash: /dev/tcp/127.0.0.1/223: 拒绝连接
#223接口不存在,打开失败
 
[chengmo@centos5  shell]$ exec 8<>/dev/tcp/127.0.0.1/22
[chengmo@centos5  shell]$ ls -l /proc/self/fd/
总计 0
lrwx------ 1 chengmo chengmo 64 10-21 23:05 0 -> /dev/pts/0
lrwx------ 1 chengmo chengmo 64 10-21 23:05 1 -> /dev/pts/0
lrwx------ 1 chengmo chengmo 64 10-21 23:05 2 -> /dev/pts/0
lr-x------ 1 chengmo chengmo 64 10-21 23:05 3 -> /proc/22185/fd
lrwx------ 1 chengmo chengmo 64 10-21 23:05 8 -> socket:[15067661]
 
#文件描述符8,已经打开一个socket通讯通道,这个是一个可以读写socket通道,因为用:"<>"打开
[chengmo@centos5  shell]$ exec 8>&-
#关闭通道
[chengmo@centos5  shell]$ ls -l /proc/self/fd/
总计 0
lrwx------ 1 chengmo chengmo 64 10-21 23:08 0 -> /dev/pts/0
lrwx------ 1 chengmo chengmo 64 10-21 23:08 1 -> /dev/pts/0
lrwx------ 1 chengmo chengmo 64 10-21 23:08 2 -> /dev/pts/0
lr-x------ 1 chengmo chengmo 64 10-21 23:08 3 -> /proc/22234/fd

从时间服务器读取时间:
[chengmo@centos5 html]$ cat</dev/tcp/time-b.nist.gov/13
55491 10-10-22 11:33:49 17 0 0 596.3 UTC(NIST) *
上面这条语句使用重定向输入语句就可以了。