跳转至

GIT_hook

对提交日志进行检查

文件必须保存为 commit-msg
#!/bin/bash
exec < /dev/tty 
# 最前面加一个,就能交互了, 不等待超时的原因   是打开的这个shell不是交互式的 exec < /dev/tty 
commit_msg=`cat $1`

msg_re="(缺陷.*缺陷原因分析.*缺陷修复方案.*自测结果.*修复影响范围.*|任务.*功能说明.*自测结果.*受影响模块.*|任务.*tag.*|任务.*文档.*)"

# 检查提交信息是否匹配新的格式要
if [[ ! $commit_msg =~ $msg_re ]]
then
    echo "***************************************"
    echo "不合法的 commit 消息提交格式 git commit"
    echo "提交规范:https://inone.intra.nsfocus.com/confluence/pages/viewpage.action?pageId=117960854"
    read -t 3 -p "格式不合规,错误日志被记录会影响绩效,是否要继续提交:  y继续提交,其他任意键退出 " input
    if [ "$input" == "y" ]; then
        exit 0
    else
        echo "提交终止!!"
        exit 1
    fi

fi

获取所有的用户,并以用户的身份执行命令

获取所有的用户,并以用户的身份执行命令
#!/bin/bash

# 获取系统中的所有用户列表
users=$(cut -d: -f1 /etc/passwd)

# 遍历每个用户并执行命令
for user in $users; do
    # 获取用户的 home 目录
    home_dir=$(getent passwd "$user" | cut -d: -f6)

    # 检查 home 目录是否存在
    if [ -d "$home_dir" ]; then
        # 使用 su -c 来以用户身份执行命令
        su - "$user" -c "git config --global core.hooksPath /opt/githook/"
        echo "Command executed for user: $user"
    else
        echo "Home directory for user $user does not exist, skipping."
    fi
done