小编eno*_*noy的帖子

创建一个脚本来识别过去 15 天内未登录的用户

我有疑问:

练习是:

编写一个脚本来检测过去 15 天内未登录且属于“校友”组的用户。该列表将添加到 /var/log/alumnos_sin_login。

我的做法:

    #2)
#!/bin/bash
#Scripts which detects users whose group is "alumnos" who have been not logged in,
#in the last 15 days. The users' list is added to /var/log/alumnos_sin_login
#RESULTADO holds those users who haven't entered in the last 15 days
#LISTA holds alumnos' users' list
#USUAEIO actual user being parsed
#RAIZ != "" if user has logged -15 days

#Read and check if group is not created
exec 0 </etc/gshadow
if [ $(grep …
Run Code Online (Sandbox Code Playgroud)

linux scripting

4
推荐指数
1
解决办法
1959
查看次数

在 bash 中结合 basename {} 和 string 的操作

我想编写一个脚本来查找所有.cpp.cc. 搜索将从开始路线 R 递归完成,这是脚本的参数。

如果没有写入参数,R 将是实际目录。

我写过:

#!/bin/bash

R=.
if [[ $# == 1 ]]
then
    echo "$# == 1"
    if [[ -d $1 ]]
    echo "$1 is directory"
    then
        R=$1
    else
        printf "Error $1 should be a directory"
        exit 1
    fi
find $R -name "*.cpp" -exec sh -c 'mv {} $(dirname {})${$(basename {})%.cpp}".cc" ' \;
exit 0
else
    printf "Invocation is: $0 directory"
    exit 1
fi
Run Code Online (Sandbox Code Playgroud)

但是我知道我在 find 行中遇到了麻烦,因为我不知道如何表达我想在使用 {} 时删除扩展名并附加新的扩展名

bash find shell-script filenames

2
推荐指数
1
解决办法
910
查看次数

标签 统计

bash ×1

filenames ×1

find ×1

linux ×1

scripting ×1

shell-script ×1