LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-27-2015, 01:45 AM   #1
maro55
LQ Newbie
 
Registered: Aug 2015
Posts: 8

Rep: Reputation: Disabled
Cron reload wepapp Tomcat


hi

how i used curl for reload single application tomcat?

1)i add user of the script only
Code:
<role rolename="manager-gui"/>
<user username="admin" password="pwdadmin" roles="manager-gui"/>
 
<role rolename="manager-script"/>
<user username="script" password="pwdscript" roles="manager-script"/>
 
</tomcat-users>
2)
Code:
30 6 * * * curl --user script:pwdscript http://@ip:8181/manager/html/reload?path=/name_application
but it not working

when i reload form borwser and with user admin the url is like this:
Code:
http://@ip:8181/manager/html/reload?path=/name_application&&org.apache.catalina.filters.CSRF_NONCE=.....
thanks

(tomcat8 ,centos6)
 
Old 09-27-2015, 09:08 AM   #2
bonnydeal
Member
 
Registered: Feb 2006
Posts: 47

Rep: Reputation: 29
There are probably 2 things wrong here:

1. Tomcat manager uses a cookie to store a session, so you need to use 2 curl commands with a cookie jar - one to login and get the session cookie and one to do the reload (using the cookie you got in the first call).
2. You should use the exact same url in your curl as is used in the browser.
 
Old 09-27-2015, 02:39 PM   #3
maro55
LQ Newbie
 
Registered: Aug 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
hi,

thanks... so the

Code:
http://@ip:8181/manager/html/reload?path=/name_application&org.apache.catalina.filters.CSRF_NONCE=ID_Session
???!

Code:
30 6 * * * curl --user script:pwdscript --cookie-jar ./idmanager.txt http://@ip:8181/manager
30 6 * * * curl --cookie ./idmanager.txt http://@ip:8181/manager/html/reload?path=/name_application&org.apache.catalina.filters.CSRF_NONCE=....
it is fine like that ? the save of id session?
what i but after org.apache.catalina.filters.CSRF_NONCE?!

Last edited by maro55; 09-27-2015 at 02:56 PM.
 
Old 09-27-2015, 03:01 PM   #4
bonnydeal
Member
 
Registered: Feb 2006
Posts: 47

Rep: Reputation: 29
yes, but you need to do the 2 curl commands in sequence, either one of the cron jobs could fire first. If the reload fires first - it wont have the session cookie, or it will be an old one if the file still hanging around.
So i would put them in a shell script and call that from the crontab file.

Code:
#!/bin/bash
curl --user script:pwdscript --cookie-jar ./idmanager.txt  http://@ip:8181/manager/html
curl --user script:pwdscript --cookie-jar ./idmanager.txt  http://@ip:8181/manager/html/reload?path=/name_application
I think you can leave off the '&org.apache...'

Last edited by bonnydeal; 09-27-2015 at 03:23 PM.
 
Old 09-28-2015, 01:04 AM   #5
maro55
LQ Newbie
 
Registered: Aug 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hi,

Exemple script shell
With vi :
Code:
#!/bin/bash
clear
echo "Good morning, world."
chmod 755 morning
and i run it :
Code:
./morning
==> it works
So,i have edit the script with
Code:
#!/bin/bash
curl --user script:pwdscript --cookie-jar ./idmanager.txt  http://@ip:8181/manager/html
curl --user script:pwdscript --cookie-jar ./idmanager.txt  http://@ip:8181/manager/html/reload?path=/name_application
then with crontab -e
Code:
30 6 * * * ./morning
it is fine like this?!
 
Old 09-28-2015, 02:38 PM   #6
bonnydeal
Member
 
Registered: Feb 2006
Posts: 47

Rep: Reputation: 29
Should be.

There's also nothing stopping you running the script from the command line and viewing the output, and checking tomcat ...
 
Old 09-29-2015, 12:23 AM   #7
maro55
LQ Newbie
 
Registered: Aug 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
thanks,

I have to empty the contents of this file idmanager.txt to have the right prefermence?
or to secure my server?
 
Old 09-29-2015, 03:53 AM   #8
bonnydeal
Member
 
Registered: Feb 2006
Posts: 47

Rep: Reputation: 29
Yes.
You can delete it at the end of the shell script.
 
Old 09-30-2015, 12:42 AM   #9
maro55
LQ Newbie
 
Registered: Aug 2015
Posts: 8

Original Poster
Rep: Reputation: Disabled
hi,
when i run the shell
Code:
./morning
they retrun html reponse

Code:
 <body>
   <h1>403 Access Denied</h1>
   <p>
    You are not authorized to view this page.
   </p>
   <p>
    If you have already configured the Manager application to allow access and
    you have used your browsers back button, used a saved book-mark or similar
    then you may have triggered the cross-site request forgery (CSRF) protection
    that has been enabled for the HTML interface of the Manager application. You
    will need to reset this protection by returning to the
    <a href="/manager/html">main Manager page</a>. Once you
    return to this page, you will be able to continue using the Manager
    appliction's HTML interface normally. If you continue to see this access
    denied message, check that you have the necessary permissions to access this
    application.
   </p>
 
Old 09-30-2015, 04:54 AM   #10
bonnydeal
Member
 
Registered: Feb 2006
Posts: 47

Rep: Reputation: 29
It says CSRF protection has been triggered.
So you need the complete url -
http://@ip:8181/manager/html/reload?...rs.CSRF_NONCE=....

You will have to look at the network traffic when yopu successfully complete the operation in the browser to see what to use for the id.
You can use developer tools in chrome or firebug in firefox to look at what gets sent back and forth to tomcat server.
 
  


Reply

Tags
apache, centos6, cron, tomcat



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] compare file cron reload ggalan Linux - Newbie 10 01-05-2012 06:28 PM
Strange Cron directories: /var/spool/cron/cron.GfqqGO Woodsman Slackware 4 05-11-2011 02:37 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Tomcat reload servlet is very slow, but reload jsp is fast and good? gsbarry Programming 2 04-28-2006 09:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration