Curl and write custom result to file


Login or Register to Reply

 
Thread Tools Search this Thread
# 8  
That is incompatible with the output you showed in post #1. Looks like something is profoundly messed up here. Run the curlstatement for one single webapp, and post the entire session's log here.

Last edited by RudiC; 4 Weeks Ago at 07:07 AM..
# 9  
So when i add any commands to the first script example below,i get a lot more stuff, that could be the reason that i cant ge't what i need,
Code:
for i in $(cat MyWebApps); do curl -u manager:tH1s1s4f3k3p4ssw0Rd http://10.10.10.10:7529/manager/jmxproxy/"?get=Catalina:type=Manager,context=/$i,host=localhost&att=activeSessions" | grep 'context'; done

Code:
OK - Attribute get 'Catalina:type=Manager,context=/MyWebApp1,host=localhost' - activeSessions = 0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    95  100    95    0     0  26942      0 --:--:-- --:--:-- --:--:-- 47500
OK - Attribute get 'Catalina:type=Manager,context=/MyWebApp2,host=localhost' - activeSessions = 0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    96  100    96    0     0  25552      0 --:--:-- --:--:-- --:--:-- 48000

When i run the curl fo one single webapp it prints one single line
Code:
curl -u manager:tH1s1s4f3k3p4ssw0Rd http://10.10.10.10:7529/manager/jmxproxy/"?get=Catalina:type=Manager,context=/MyWebApp1,host=localhost&att=activeSessions"

Code:
OK - Attribute get 'Catalina:type=Manager,context=/MyWebApp1,host=localhost' - activeSessions = 2

# 10  
A bit difficult to believe. When you grep for "context", why should it print all those lines? What's the contents of the file MyWebApps?
# 11  
Please note RudiC that i'm curling a tomcat manager Sessions tab specific,
i'm not curling the full page, the contente of the MyWebApps are only all the names of the webapps.
Thanks for you help.
# 12  
Hello RudiC,
finally i figured it out,
the worng output was a terminal issue,


Code:
for i in $(cat MyWebApps); do curl -u manager:tH1s1s4f3k3p4ssw0Rd http://10.10.10.10:7529/manager/jmxproxy/"?get=Catalina:type=Manager,context=/$i,host=localhost&att=activeSessions" |awk '{print $5," "$9}'|  awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0 }' | awk '{gsub("Catalina:type=Manager,context=/", "");print}' | awk '{gsub(",host=localhost", "");print}' >> sessions.log; done

Let me know if you have any better ideas on this.
Thank you for the support.
This User Gave Thanks to charli1 For This Post:
# 13  
Good you found a solution on your own. How about some improvements? read the MyWebApps file in lieu of catting it in a "command substitution" (saves a process creation), write to the log file outside the loop (avoids opening / closing it over and over again), and combine five awk executions into one, like


Code:
while read i; do curl ...$i... | awk -F"[,/ ]" -vDT="$(date +"%Y-%m-%d-%H:%M")" -vOFS="," '{print DT, $7, $NF}'; done < MyWebApps > sessions.log

Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Compare 2 file and write result
Akshay Hegde
Hi friends...I have 2 files, file1.txt and reference.txt I could able to find difference using diff and following command awk 'NR == FNR { A=1; next } !A' reference.txt file1.txt above command listing data which is not in reference.txt 12.12 87 11.95 88 11.83 89 12.55 84...... Shell Programming and Scripting
12
Shell Programming and Scripting
Script to write result to a file
Shaan_Shaan
Hello, How can I run this script every 1 hour and save its result to result.txt ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' Regards Shaan... Shell Programming and Scripting
5
Shell Programming and Scripting
Write result to output file
bluejean1976
Good morning everybody, Beeing an absolute newbie in shell scripting I would like to look for some help here. I would like to read an external text file and format the data and write it to an output file. What I was trying to do was to display the result (this worked). But now I...... Shell Programming and Scripting
1
Shell Programming and Scripting
How to write result of a query to more than 1 .csv
Jassz
If the result of the query is greater than say, 50,000 then the next 50,000 should be written to the second file and so on. Is it possible?... Shell Programming and Scripting
1
Shell Programming and Scripting
script to output curl result as html
squidusr
hi, new to scripting and would like to know how can I have a script which will curl a few URLs and have the results such as the URLs being curled, dns lookup time, connection time, total time, etc save in a html format in a form of table with column and rows. thank you.... Shell Programming and Scripting
4
Shell Programming and Scripting