0

我想以递归方式更改 AIX 中目录的所有权。我用

<osexec commandbase="su" dir="/bin" mode="osexec">
<args>
<arg line="chown -R ${broker_admin_name}:${broker_admin_name} ${broker_installation_directory}/dcx"/>
</osexec>

这段代码正确吗?我想更改 dcx 下所有目录和文件的所有权,包括 dcx,但我无法通过这样做来更改所有权。我也尝试:

<chown owner="${broker_admin_name}">
<fileset dir="${broker_installation_directory}/dcx" includes="**/*">
</fileset>
<dirset dir="${broker_installation_directory}/dcx" includes="**/*">
</dirset>
</chown>

但是通过这种方式,只有 dcx 下的目录的所有权发生了变化,而不是文件。另外,我可以通过 build.xml 中的普通 shell 命令执行此操作吗?即chown -R abc:abc xyz,我怎样才能直接在 build.xml 中执行此操作?

4

1 回答 1

1

您是否收到“不允许操作”错误消息?

例子

在 Ubuntu 上,chown 任务受操作系统限制:

$ ant

build:
    [chown] chown: changing ownership of `/home/mark/tmp/build/one/test.txt': Operation not permitted
    [chown] chown: changing ownership of `/home/mark/tmp/build/three/test.txt': Operation not permitted
    [chown] chown: changing ownership of `/home/mark/tmp/build/two/test.txt': Operation not permitted
    [chown] chown: changing ownership of `/home/mark/tmp/build': Operation not permitted
    [chown] chown: changing ownership of `/home/mark/tmp/build/one': Operation not permitted
    [chown] chown: changing ownership of `/home/mark/tmp/build/three': Operation not permitted
    [chown] chown: changing ownership of `/home/mark/tmp/build/two': Operation not permitted
    [chown] Result: 1
    [chown] Applied chown to 3 files and 4 directories.

运行“chown”命令演示了相同的限制

$ chown -R an_other_user build
chown: changing ownership of `build/one/test.txt': Operation not permitted
chown: changing ownership of `build/one': Operation not permitted
chown: changing ownership of `build/two/test.txt': Operation not permitted
chown: changing ownership of `build/two': Operation not permitted
chown: changing ownership of `build': Operation not permitted

最好的解决方案是以 root 用户身份运行 ANT:

$ sudo ant

构建.xml

<project name="demo" default="build">

    <target name="init">
        <mkdir dir="build/one"/>
        <mkdir dir="build/two"/>

        <echo file="build/one/test.txt" message="helloworld"/>
        <echo file="build/two/test.txt" message="helloworld"/>
    </target>

    <target name="build" depends="init">
        <chown owner="an_other_user" verbose="true">
            <fileset dir="build"/>
            <dirset dir="build"/>
        </chown>
    </target>

    <target name="clean">
        <delete dir="build"/>
    </target>

</project>
于 2012-12-19T19:47:57.180 回答