[英]Writing a shell script that run another shell script owned by other user
I have installed tomcat in /opt/tomcat6 and made one of it's instance in ~/tomcatHost directory.The /opt/tomcat6 is owned by user tomcat and group tomcat. 我已经在/ opt / tomcat6中安装了tomcat,并在〜/ tomcatHost目录中创建了其中的一个实例./opt/tomcat6由tomcat用户和tomcat组拥有。 Unix "ls -l" produce following - Unix“ ls -l”产生以下内容-
drwxr-xr-x 9 tomcat tomcat 4096 Dec 15 03:37 tomcat6
In this case, to run tomcat instance in ~/tomcatHost I need to do the following steps - 在这种情况下,要在〜/ tomcatHost中运行tomcat实例,我需要执行以下步骤-
$ chmod -R 777 tomcatHost
$ export CATALINA_BASE=/home/guestUser/tomcatHost
$ su tomcat
$ cd /opt/tomcat6/bin
$ sh startup.sh
Now the tomcat is start at the port configured in server.xml. 现在,tomcat从server.xml中配置的端口启动。 I'm trying to write a shell script which do the task performed above. 我正在尝试编写执行上述任务的shell脚本。 I'm new in shell scripting and can not able to solve this problem. 我是Shell脚本的新手,无法解决此问题。 I think there is an ownership issue, can anyone tell me how can I handle the ownership issue in shell script? 我认为存在所有权问题,谁能告诉我如何在Shell脚本中处理所有权问题? Or, how can I write a script to run "startup.sh" (owned by tomcat user) from other user. 或者,如何编写一个脚本来从其他用户运行“ startup.sh”(由tomcat用户拥有)。 Can you suggest any good tutorial for this? 您可以为此建议任何好的教程吗?
I have get a solution to this. 我对此有解决方案。 Probably it is not the best solution but it works pretty good. 可能不是最佳解决方案,但效果很好。 I have write the following code (based on this. ) on a file named 'start.sh' - 我在名为“ start.sh”的文件上写了以下代码(基于此 )。
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
Then from terminal I just run the 'start.sh' scrip 然后从终端我只运行'start.sh'脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.