[英]How to check if linux user has .sh file?
I have to write script in bash that will check if logged users have any.sh files.我必须在 bash 中编写脚本来检查登录的用户是否有任何 .sh 文件。
Checking who is logged in is simple just using:检查谁登录很简单,只需使用:
w| awk '{print $1}'
But i have no idea how to check if they havy any.sh files但我不知道如何检查他们是否有 any.sh 文件
You need to read the output of the who
command and use that in your find
command.您需要阅读who
命令的 output 并在您的find
命令中使用它。
Since the same user can be logged in multiple times, it's a good idea to remove duplicates before looping.由于同一用户可以多次登录,因此最好在循环之前删除重复项。
#!/bin/bash
who| awk '{print $1}' | sort -u | while read -r username; do
find /home/"$username" -name "*.sh"
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.