- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2011 03:14 PM - edited 09-12-2011 02:57 PM
09-10-2011 03:14 PM - edited 09-12-2011 02:57 PM
Hi All,
Have a piece of code which makes a curl to a webpage and returns a list of host which are currently up/down (down hosts are derived from grep -A1 DOWN command below and saved to a tmp file)
From that file I need to generate a URL and call it to mark the hosts as up. The URL that needs to be generated is like this -
http://$HOST:$PORT/URI/$host-from-tmp-file:$port-from-tmp-file
where
$host-from-tmp-file would need to come from the tmp file (/tmp/mon_prd.tmp)
$port-from-tmp-file would need to come from the tmp file (/tmp/mon_prd.tmp)
ENV1) HOST=`command | awk -F: '{print $1}'` PORT=`command | awk -F: '{print $2}'|head -1` for i in $HOST do curl -s "http://$i:$PORT/virtual/hostlist" | grep "DOWN" curl -s "http://$i:$PORT/virtual/hostlist" | grep -A1 "DOWN" > /tmp/mon_prd.tmp if [ `echo $?` -eq 0 ] then mail -s "Subject" mail@mail.com < /tmp/mon_prd.tmp fi echo -n "" > /tmp/mon_prd.tmp done ;; *) echo "Invalid option" ;; esac
Thanks,
Allan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2011 03:30 PM
09-10-2011 03:30 PM
Re: Script help
@allanm77 wrote:From that file I need to generate a URL and call it to mark the hosts as up. The URL that needs to be generated is like this -
http://$HOST:$PORT/URI/$host-from-tmp-file:$port-from-tmp-file
where
$host-from-tmp-file would need to come from the tmp file (/tmp/mon_prd.tmp)
$port-from-tmp-file would need to come from the tmp file (/tmp/mon_prd.tmp)
Allan:
Post a sample (or two) of the *contents* of your '/tmp/mon_prd.tmp' file, As usual, showing actual data leads to better solutions than making assumptions based on vague descriptions.
Snipping out the data you need to construct your URL should be quite simple.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2011 09:45 PM - edited 09-11-2011 07:44 AM
09-10-2011 09:45 PM - edited 09-11-2011 07:44 AM
Re: Script help
>PORT=`command | awk -F: '{print $2}'|head -1`
No need for head(1):
PORT=$(command | awk -F: '{print $2; exit}')
>if [ `echo $?` -eq 0 ]
I'm not sure why you are using echo?
if [ $? -eq 0 ]; then
And better to use mailx vs mail.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2011 07:09 AM
09-11-2011 07:09 AM
Re: Script help
@Dennis Handly wrote:
No need for head(1):
PORT=$(command | awk -F: '{print $2}; exit')
Right, but you meant to write that as:
PORT=$(command | awk -F: '{print $2;exit}')
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2011 07:54 AM
09-11-2011 07:54 AM
Re: Script help
>but you meant to write that as:
Oops, history suitably retconned. ;-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2011 08:57 AM - edited 09-11-2011 09:01 AM
09-11-2011 08:57 AM - edited 09-11-2011 09:01 AM
Re: Script help
Hi JRF
Sample of /tmp/mon_prd.tmp -
<td>DOWN</td> <td>host:port <a title="debug" href="URI">[I]</a> <a title="debugger" href="http://host:1port/debug">[D]</a> <a title="browse" href="http://host/corp/java/browse.jsp/wa/viewService?serviceUrl=http%3A//host%3A8000/java/Service.jsp/ww&serviceUrl=http%3A//host%3A1port/service/lib">[TB]</a></td>
Thanks
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2011 10:19 AM
09-12-2011 10:19 AM
Re: Script help
Where host: host1.corp.foobar.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2011 01:21 PM
09-12-2011 01:21 PM
Re: Script help
Basically need to contruct the URL based on the above file.
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2011 02:27 PM
09-12-2011 02:27 PM
Re: Script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2011 02:51 PM
09-12-2011 02:51 PM
Re: Script help
@allanm77 wrote:Basically need to contruct the URL based on the above file.
Maybe I'm missing something. but showing *both* the input *and* the desired output would be more helpful than what you offered thus far.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2011 03:22 PM - edited 09-12-2011 03:24 PM
09-12-2011 03:22 PM - edited 09-12-2011 03:24 PM
Re: Script help
Ok, here's another dig, the script above makes a call to a webpage(html based), the output that we get is like this -
<td>DOWN</td>
<td>host1.corp.foobar.com:port <a title="debug" href="URI">[I]</a> <a title="debugger" href="http://host1.corp.foobar.com:1port/debug">[D]</a> <a title="browse" href="http://host1.corp.foobar.com/corp/java/browse.jsp/wa/viewService?serviceUrl=http%3A//host%3A8000/java/Service.jsp/ww&serviceUrl=http%3A//host%3A1port/service/lib">[TB]</a></td>
I need to generate a URL out of the above output which is like this -
curl http://$HOST:$PORT/URI/host1.corp.foobar.com:port
HOST is the variable defined in the script initially,
PORT is the variable defined in the script initially,
host1.corp.foobar.com is from curl's output saved to a tmp file,
port is from the curl's output saved to a tmp file.
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2011 05:20 AM
09-13-2011 05:20 AM
Re: Script help
Hi Allan:
OK, you can add this snippet to you script to capture the information you need to compose your URI. You need merely to divide the returned variable into it's two parts, as delimited by a colon.
# VARS=$(perl -nle 'm{<td>(.+?):(.+?)<} and print qq($1:$2)' file)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2011 08:48 PM
09-14-2011 08:48 PM
Re: Script help
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2011 09:58 AM
09-15-2011 09:58 AM
Solution
@allanm77 wrote:
Thanks JRF, can this be constructed through sed instead?
Allan.
HI (again) Allan:
Well, if you force me :-) then try this (given your data):
sed -ne 's/<td>\(.*:\)/\1/;s/<a.*$//p'
Regards!
...JRF...
- Tags:
- sed