8月 152017
 

我们见过比较专业一些的软件会包含多个rpm包,如:

phpor.1.0.0.el7.x86_64

phpor-docs.1.0.0.el7.x86_64

phpor-devel.1.0.0.el7.x86_64

phpor-debuginfo.1.0.0.el7.x86_64

那么,一个spec文件如何build出来多个rpm包呢?

首先,我们以devel为例,参考: https://stackoverflow.com/questions/2913130/building-both-devel-and-normal-version-of-a-rpm-package

可见,devel是以子包的形式出现的

示例:

http://kmymoney2.sourceforge.net/phb/rpm-example.html

rpmbuild 安装到BUILDROOT 下面的文件和目录都要打包的rpm包中,否则会报错(rpmbuild会认为你遗忘了),如果不想打包,就提前删掉

 Posted by at 下午 5:42
8月 152017
 

rpm打包之前会执行: /usr/lib/rpm/check-buildroot, 其逻辑为,检查将要打包的文件中是否包含buildroot,因为这只是build时候的临时目录,如果出现在打包文件中,就可能会出现问题,起检查方法简单粗暴:

如果包含,就会报类似如下的错误信息,然后退出

关于check-buildroot脚本:

其一:

通过mktemp来创建临时文件,根本不需要自己制造随机文件名

其二:

保证在脚本退出后删除临时文件

其三:

注意,这里 ” || : ” 的用法,保证test为假时脚本退出码为零

 Posted by at 下午 5:06
8月 152017
 

 

 

 Posted by at 下午 2:52
8月 142017
 

4294967295 is just (unsigned long) -1. -1 means that loginuid was not set. This is normal behavior for processes that were not spawned by any login process (e.g. for daemons). loginuid is -1 by default; pam_loginuid module changes it to your user id whenever you login (in a tty/in DM/via ssh), and this value is preserved by child processes.

可惜的是proc.txt并未对此文件有过说明

用途:

追踪进程发起者

 Posted by at 上午 10:20

rsyslog on RHEL7

 Linux & Unix  rsyslog on RHEL7已关闭评论
7月 062017
 

默认情况下rsyslog载centos7上并不listen /dev/log ,解决办法:

在  /etc/rsyslog.conf 中添加:

 Posted by at 下午 3:36

SysVinit vs Systemd

 Linux & Unix  SysVinit vs Systemd已关闭评论
6月 232017
 

sysvinit 管理服务使用的是service命令,执行的是 /etc/init.d/{$script} 的逻辑;而systemd 使用的是systemctl来管理服务的。

我们如果在systemd系统上使用service命令(甚至直接执行 /etc/init.d/ 下的脚本)时,会提示自动重定向到systemctl来处理,其逻辑为:

service 为 initscripts 包中的命令,该包还包含了 /etc/rc.d/init.d/functions  ,该functions提供了一些基础的函数,经常会被init.d 下的脚本包含; 在centos7上,initscripts 被做了手脚,service命令和functions里面都拦截命令的执行而重定向到systemctl,不过也可以通过环境变量SYSTEMCTL_SKIP_REDIRECT 来禁止重定向,脚本逻辑并不复杂;有时候,我们习惯使用 service 命令,还有时候,我们在docker容器里面使用systemctl总是没有权限,于是,借助环境变量SYSTEMCTL_SKIP_REDIRECT,依然执行 /etc/init.d 下的脚本而不去执行systemctl还是不错的

 Posted by at 下午 12:12

od 输出字符对照表

 Linux & Unix  od 输出字符对照表已关闭评论
6月 162017
 

 

 Posted by at 下午 12:49

bash vs sh

 Linux & Unix  bash vs sh已关闭评论
6月 092017
 

一般来讲,/bin/sh 都是软连接到bash的,所以,你基本上会认为 /bin/sh 和 /bin/bash 是一样的; 但事实是:不尽然

bash中有判断当前文件名的逻辑,如果是sh 就 xxx, 如果是bash 就 ***,如:

使用bash执行脚本时,函数名允许含有中划线(如: hello-world),sh执行时不允许

使用bash执行脚本时,支持Process Substitution , sh 执行时不支持

 

是不是感觉有些不爽?

还有呢,有些版本的 /bin/test 和 /bin/[ 就是同一个程序,根据文件名的不同执行不同的逻辑

 

参考: https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash

当通过sh的方式使用bash时,基本等同于:

虽然显得很posix,但是很多好用的东西不支持:(其中删除线部分,似乎说的不太对,也或者是我理解的不对,所以删除了)

This question has frequently been nominated as a canonical for people who try to use sh and are surprised that it’s not behaving the same as bash. Here’s a quick rundown of common misunderstandings and pitfalls.

  • If you run your script with sh scriptname, or run it with scriptname and have #!/bin/shin the shebang line, you should expect POSIX sh behavior.
  • If you run your script with bash scriptname, or run it with scriptname and have #!/bin/bash (or the local equivalent) in the shebang line, you should expect Bash behavior.

Having a correct shebang and running the script by typing just the script name (possibly with a relative or full path) is generally the preferred solution. In addition to a correct shebang, this requires the script file to have execute permission (chmod a+x scriptname).

The Bash Reference manual has a section which attempts to enumerate the differences but some common sources of confusion include

  • [[ is not available in sh (only [ which is more clunky and limited). 
  • sh does not have arrays.
  • Bash has process substitution with <(cmd) and >(cmd).
  • Some Bash keywords like local, function, and select are not portable to sh.
  • ~ refers to $HOME only in Bash (and more generally ~username to the home directory of username).
  • Bash has many C-style syntax extensions like $'string\nwith\tC\aescapes' and the three-argument for((i=0;i<=3;i++)) loop, += increment assignment, etc.
  • Bash has *.{png,jpg} and {0..9} brace expansion.
  • Bash supports coprocesses with <> redirection.
  • Bash supports <<<'here strings'.
  • Bash has significantly extended facilities for shell arithmetic (though still no floating-point support) and variable substring manipulation.
  • Many, many Bash-only extensions to enable or disable optional behavior and expose internal state of the shell.

Remember, this is an abridged listing. Refer to the reference manual for the full scoop, and http://mywiki.wooledge.org/Bashism for many good workarounds; and/or try http://shellcheck.net/ which warns for many Bash-only features.

Unfortunately, Bash will not warn when you try to use these constructs when it is invoked as sh.

 

总结:

知道bash和sh有差异就行了,记住所有的差异没有意义

 Posted by at 下午 2:34

shell 之 return

 Linux & Unix  shell 之 return已关闭评论
6月 072017
 

不惑: shell函数中可以使用return语句提前返回

疑惑:有些shell脚本中,函数外也会出现return;有些shell脚本中在函数外写return就执行失败

参考:

解惑:

  1. 函数中可以使用return语句
  2. 被引用的脚本(就是source 或 dot 方式执行的脚本)中函数外也可以使用return; 使用 sh script.sh 方式执行的script.sh 中不能出现函数外的return语句; 即: 如果在函数外使用return语句,你要清楚你的脚本是用来被source的,而不是被 sh 的;
  3. 其他情况下的return语句将返回失败
 Posted by at 下午 3:24