欢迎登陆真网站,您的到来是我们的荣幸。 登陆 注册 忘记密码? ☆设为首页 △加入收藏
欢迎加入真幸福QQ群
电脑知识: 基础知识 网络技术 操作系统 办公软件 电脑维修 电脑安全 windows7 windows8 windows10 服务器教程 平板电脑 视频播放教程 网络应用 互联网 工具软件 浏览器教程 QQ技巧 输入法教程 影视制作 YY教程 wps教程 word教程 Excel教程 PowerPoint
云南西双版纳特产小花糯玉米真空包装


PPTV聚力网络电视“播放器”和“节目库”界面切换
如何卸载PPTV聚力网络电视
ubuntu强制清空回收站 创建、删除文件及文件夹的方法
win10系统输入法图标消失了的解决方法
PPS我已是VIP为什么看片还是卡
PPS为什么我看不到VIP专属内容
linux如何调节和维护内核详细介绍
Linux防火墙iptables简明教程
预装Windows8系统的电脑如何划分更多的磁盘分区
在暴风影音中如何进行快捷键的设置?
linux如何判断指定用户对指定目录具有的权限具体介绍
【 来源:网络 】【 点击:2 】 【 发布时间:2017_03_03 08:59:59 】

   脚本名:power.sh

  脚本内容:

  代码如下:

  #!/bin/sh

  username3=$1

  dir_name2=$2

  # get existing directory

  file_path=$dir_name2

  while true

  do

  if [ -d $file_path ];then

  break;

  fi

  file_path=${file_path%/*}

  done

  dir_name2=$file_path

  # Judge whether the user exists

  grep "^$username3:" /etc/passwd >/dev/null

  if [ $? -ne 0 ];then

  echo "This user "$username3" does not exist."

  exit 4

  fi

  #echo "username : $username3"

  group4=` grep "^$username3:" /etc/passwd |awk -F : {'print $4'}|xargs -i grep {} /etc/group|cut -d":" -f1`

  #echo "group : $group4"

  su -l $username3 -c "test -r $dir_name2"

  is_read=$?

  su -l $username3 -c "test -x $dir_name2"

  is_exe=$?

  su -l $username3 -c "test -w $dir_name2"

  is_write=$?

  $is_read_str

  $is_exe_str

  $is_write_str

  if [ $is_read -eq 0 ];then

  is_read_str="r"

  else

  is_read_str="-"

  fi

  if [ $is_exe -eq 0 ];then

  is_exe_str="x"

  else

  is_exe_str="-"

  fi

  if [ $is_write -eq 0 ];then

  is_write_str="w"

  else

  is_write_str="-"

  fi

  echo "${is_read_str}${is_write_str}${is_exe_str}"

  -------------------------------------------

  注意:必须以root 身份执行该脚本。

  脚本power.sh 需要两个参数,第一个表示指定的用户,第二个表示指定的目录

  测试:

  [root@ppc40 study]# sh power.sh whuanga4 /tmp/abc/dd

  This user "whuanga4" does not exist.

  [root@ppc40 study]# sh power.sh whuang4 /tmp/abc/dd

  rw-

  (说明:表示用户whuang4 对目录/tmp/abc/dd 具有读和写权限,没有执行权限)。

本网站由川南居提供技术支持,fkzxf版权所有 浙ICP备12031891号
淳安分站 淳安分站