避免 UNIX 和 Linux 中的常见错误
避免 UNIX 和 Linux 中的常见错误
您是否遇到过 Execute permission denied
或 The parameter list is too long
这样的错误消息?您想知道错误的原因吗?这些是 UNIX 和 Linux 新手经常遇到的错误,他们可能不知道如何避免这些问题。本文解释这些错误并提供解决方法。
./foo: 0403-006 Execute permission denied.
您编写或下载了一个新的 shell 脚本,很想试试它。这听起来不错,但是在试图执行这个命令时,收到了错误消息 ./foo: 0403-006 Execute permission denied
。怎么回事儿?这个消息可能源于两个问题:
- 您不具有执行这个命令的足够权限。
- 对于脚本中定义的 shell,您不具有足够的权限,无法告诉 shell 应该如何解释脚本和其中的命令。
您不具有执行这个命令的足够权限
检查权限最简便的方法是,查看您是作为哪个用户登录服务器的,然后查看 ls –l
的输出:
# id uid=5008(cormany) gid=330(atc) groups=110(sales),201(sshd) # ls -l foo -rwxrw-r-- 1 cormany atc 75 Jun 10 18:46 foo |
根据这个示例,您是作为用户 cormany 登录的,而 shell 脚本的所有者是 cormany,他具有 rwx 权限(即读、写和执行)。这没问题,所以我们考虑下一个可能的原因。
对于脚本中定义的 shell,您不具有足够的权限,无法告诉 shell 应该如何解释脚本和其中的命令
我们来看看脚本的内部:
# cat foo #!/bin/ksh.new echo "This is a just a test" exit 0 |
根据第一行,这个脚本看起来应该作为 Korn shell 脚本进行解释。通过检查所用的 shell 的权限,可以确认实际上是否可以使用它:
# ls –l /bin/ksh.new -r-xr-x--- 5 bin bin 289072 May 27 19:03 /bin/ksh.new |
作为 root 用户,修改要使用的 shell 的文件权限,然后再试一次:
- 切换为 root 用户:
# su - root's Password:
- 确认您现在是 root 用户而不是原来的用户:
# id uid=0(root) gid=0(system) groups=2(bin),3(sys),7(security),8(cron),10(audit),11(lp)
- 修改文件的权限:
# chmod 555 /bin/ksh.new
- 确认文件权限已经改变了:
# ls -l /bin/ksh.new -r-xr-xr-x 1 bin bin 289072 Jun 10 18:45 /bin/ksh.new
- 退出
su
,恢复为原来的用户:# exit # id uid=5008(cormany) gid=330(atc) groups=110(sales),201(sshd)
- 再次尝试执行脚本:
# ./foo This is a just a test
好了,问题解决了!
|
评论暂时关闭