1

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. Unix "ls -l" produce following -

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 -

  • Copy conf, webapps, logs from /opt/tomcat6 to ~/tomcatHost. Make some changes server.xml in ~tomcatHost/conf (eg- changing the port number in "Connector" element)
  • give execute permission to ~/tocatHost for all user by chmod -

$ chmod -R 777 tomcatHost

  • and run the following commands -

$ 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. I'm trying to write a shell script which do the task performed above. I'm new in shell scripting and can not able to solve this problem. I think there is an ownership issue, can anyone tell me how can I handle the ownership issue in shell script? Or, how can I write a script to run "startup.sh" (owned by tomcat user) from other user. Can you suggest any good tutorial for this?

7
  • You could use sudo. Commented Dec 16, 2013 at 6:36
  • you can try su or setuid commands. Commented Dec 16, 2013 at 7:04
  • 2
    Every time you do chmod 777, somewhere in the world a kitten dies. Commented Dec 16, 2013 at 7:22
  • This is how you give execution permission for all users: chmod a+x file Commented Dec 16, 2013 at 7:25
  • 1
    I guess, java tag is irrelevant here. Commented Dec 16, 2013 at 8:39

1 Answer 1

1

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' -

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.