280篇 Default中的文章

ssl自签名证书

查看证书

openssl x509 -in cert.pem -noout -text

生成证书

openssl genrsa -out server.key 1024
3650 -key server.key -out server.crt -subj "/C=CN/ST=mykey/L=mykey/O=mykey/OU=mykey/CN=domain1/CN=domain2/CN=domain3"

按向导生成证书

openssl genrsa -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl x509 -req -in server.csr -out server.crt -signkey server.key -days 3650
More ~

yarn 更新依赖

通过 yarn outdated 可以看到一些待更新的,但是满足最低要求,执行yarn upgrade时并未更新。

可以执行yarn upgrade --latest来更新依赖到最新版本。

More ~

shell脚本中的if 参数-a至-z

[-a file] 如果file存在则为真 

不过貌似有时候-a表示为and:条件与

[-b file] 如果file存在且是一个块特殊文件则为真 
[-c file] 如果file存在且是一个字特殊文件则为真 
[-d file] 如果file文件存在且是一个目录则为真 
-d前的!是逻辑非 
例如: 
if [ ! -d $lcd_path/$par_date ] 
表示后面的那个目录不存在,则执行后面的then操作 
[-e file] 如果file文件存在则为真 
[-f file] 如果file存在且是一个普通文件则为真 
[-g file] 如果file存在且已经设置了SGID则为真(SUID 是 Set User ID, SGID 是 Set Group ID的意思) 
[-h file] 如果file存在且是一个符号连接则为真 
[-k file] 如果file存在且已经设置粘制位则为真 
当一个目录被设置为"粘制位"(用chmod a+t),则该目录下的文件只能由 
一、超级管理员删除 
二、该目录的所有者删除 
三、该文件的所有者删除 
也就是说,即便该目录是任何人都可以写,但也只有文件的属主才可以删除文件。 
具体例子如下: 
#ls -dl /tmp 
drwxrwxrwt 4 root    root  ......... 
注意other位置的t,这便是粘连位。 
[-p file] 如果file存在且是一个名字管道(F如果O)则为真 
管道是linux里面进程间通信的一种方式,其他的还有像信号(signal)、信号量、消息队列、共享内存、套接字(socket)等。 
[-r file] 如果file存在且是可读的则为真 
[-s file] 如果file存在且大小不为0则为真 
[-t FD] 如果文件描述符FD打开且指向一个终端则为真 
[-u file] 如果file存在且设置了SUID(set userID)则为真 
[-w file] 如果file存在且是可写的则为真 
[-x file] 如果file存在且是可执行的则为真 
[-O file] 如果file存在且属有效用户ID则为真 
[-G file] 如果file存在且属有效用户组则为真 
[-L file] 如果file存在且是一个符号连接则为真 
[-N file] 如果file存在and has been mod如果ied since it was last read则为真 
[-S file] 如果file存在且是一个套接字则为真 
[file1 –nt file2] 如果file1 has been changed more recently than file2或者file1 exists and file2 does not则为真 
[file1 –ot file2] 如果file1比file2要老,或者file2存在且file1不存在则为真 
[file1 –ef file2] 如果file1和file2指向相同的设备和节点号则为真 
[-o optionname] 如果shell选项“optionname”开启则为真 
[-z string] “string”的长度为零则为真 
[-n string] or [string] “string”的长度为非零non-zero则为真 
[sting1==string2] 如果2个字符串相同。“=”may be used instead of “==”for strict posix compliance则为真 
[string1!=string2] 如果字符串不相等则为真 
[string1<string2] 如果“string1”sorts before“string2”lexicographically in the current locale则为真 
[arg1 OP arg2] “OP”is one of –eq,-ne,-lt,-le,-gt or –ge.These arithmetic binary oprators return true if “arg1”is equal to,not equal to,less than,less than or equal to,greater than,or greater than or equal to“agr2”,respectively.“arg1”and “agr2”are integers. 
More ~

shell date 格式化

date  --date="STRING"
date  --date="next Friday"
date  --date="2 days ago"
date  --date="yesterday"
date  --date="yesterday" +"%format"
# Get yesterday's date in dd-mm-yy format
date  --date="yesterday" +"%d-%m-%y"
date  --date="yesterday" +"%m-%d-%y" # US date format
date  --date="yesterday" +"%Y-%m-%d" # YYYY-mm-dd format
## store y'day date in a shell variable called yday and display it ##
yday=$(date  --date="yesterday" +"%Y-%m-%d")
echo "$yday"
  • You can use fortnight for 14 day.
  • week for 7 days.
  • hour for 60 minutes
  • minute for 60 seconds
  • second for one second
  • You can also use this / now / today keywords to stress the meaning.
date --date='fortnight'
date --date='5 fortnight'
date --date='fortnight ago'
date --date='5 fortnight ago'
date --date='2 hour'
date --date='2 hour ago'
date --date='20 minute'
date --date='20 minute ago'
date --date='this Friday'
## OR ##
date --date='next Friday'

Set System Date & Time?

date --set='+30 minutes'
date --set='1 day ago'
More ~

Go语言fmt包Printf方法详解

Go语言的标准输出流在打印到屏幕时有些参数跟别的语言(比如C#和Java)不同,下面是我整理的一些常用的格式化输入操作。

General

  • %v 以默认的方式打印变量的值
  • %T 打印变量的类型

Integer

  • %+d 带符号的整型,fmt.Printf("%+d", 255)输出+255
  • %q 打印单引号
  • %o 不带零的八进制
  • %#o 带零的八进制
  • %x 小写的十六进制
  • %X 大写的十六进制
  • %#x 带0x的十六进制
  • %U 打印Unicode字符
  • %#U 打印带字符的Unicode
  • %b 打印整型的二进制
More ~

RPM 中的 %config 和 %config(noreplace)

打开一个 rpm spec 文件,在 %files 段有一个指令很常见:%config(noreplace),这个指定到底是干什么用的呢?
答案是,该指令决定如果一个文件被管理员修改过后,下次更新该文件所在的rpm包时,该文件的存在状态。例如,一般升级软件时,配置文件是不会变化的,而主程序则一般需要被升级(替换)。
对于 spec 文件中在 %files 段的某一个文件,我们要讨论三种情况:

  1. 没有带 %config 指令。例如:%{_sbindir}/redis-server
  2. 带了 %congfig 指令。例如:%config %{_sysconfdir}/redis/redis.conf
  3. 带了 %config(noreplace) 指令。例如:%config(noreplace) %{_sysconfdir}/redis/redis.conf
More ~

使用python的pdb命令调试

python的pdb可以进行断点调试,这个在没有IDE工具时会很方便。
启用pdb调试:python3 -m pdb myscript.py

加入断点b myscript.py:130,即在mysript.py的130行加入断点。
常用的pdb命令:
n即运行到下一行
c继续运行到下一个断点
cl myscript.py:130 清除这行断点
p var打印var变量值

更多可以参考 https://docs.python.org/zh-cn/3/library/pdb.html#pdbcommand-list

More ~

podman之docker-compose

podman 3.0开始支持docker-compose,使用docker-compose up
需要先启用podman的api服务 systemctl enable --now podman.socket

20210811152857.png

注意那行Listen,可以执行 export DOCKER_HOST=unix:///run/podman/podman.sock
避免docker-compose运行时报出无法连接的错误:
20210811153045.png

More ~