【问题标题】:Writing a shell script that run another shell script owned by other user编写一个运行其他用户拥有的另一个 shell 脚本的 shell 脚本
【发布时间】:2013-12-16 06:34:13
【问题描述】:

我已经在 /opt/tomcat6 中安装了 tomcat,并在 ~/tomcatHost 目录中创建了它的一个实例。/opt/tomcat6 由用户 tomcat 和组 tomcat 拥有。 Unix "ls -l" 产生以下 -

drwxr-xr-x 9 tomcat tomcat 4096 Dec 15 03:37 tomcat6

在这种情况下,要在 ~/tomcatHost 中运行 tomcat 实例,我需要执行以下步骤 -

  • 将 conf、webapps、日志从 /opt/tomcat6 复制到 ~/tomcatHost。在 ~tomcatHost/conf 中对 server.xml 进行一些更改(例如,更改“连接器”元素中的端口号)
  • 通过 chmod 为所有用户授予 ~/tocatHost 执行权限 -

$ chmod -R 777 tomcatHost

  • 并运行以下命令 -

$ export CATALINA_BASE=/home/guestUser/tomcatHost
$ su tomcat
$ cd /opt/tomcat6/bin
$ sh startup.sh

现在 tomcat 在 server.xml 中配置的端口启动。我正在尝试编写一个执行上述任务的 shell 脚本。我是 shell 脚本的新手,无法解决这个问题。我认为存在所有权问题,谁能告诉我如何处理 shell 脚本中的所有权问题?或者,我如何编写脚本来从其他用户运行“startup.sh”(由 tomcat 用户拥有)。你能推荐任何好的教程吗?

【问题讨论】:

  • 你可以使用sudo
  • 你可以试试 su 或 setuid 命令。
  • 每次执行 chmod 777 时,世界上的某个地方都会死掉一只小猫。
  • 这是为所有用户授予执行权限的方式:chmod a+x file
  • 我猜,java标签在这里无关紧要。

标签: linux bash shell tomcat ubuntu


【解决方案1】:

我有办法解决这个问题。可能这不是最好的解决方案,但效果很好。我在名为“start.sh”的文件上编写了以下代码(基于this.) -

export CATALINA_BASE=/home/razib/tomcat_host  
echo "CATALINA_BASE is set..."  
echo "Password for 'tomcat' - "  
su -c "sh /opt/tomcat6/bin/startup.sh" -s /bin/sh tomcat

然后我从终端运行“start.sh”脚本

【讨论】:

    猜你喜欢
    • 2013-04-18
    • 2012-01-11
    • 2020-11-04
    • 2015-07-22
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    • 2021-06-03
    • 2019-02-10
    相关资源
    最近更新 更多