- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: help with output format
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
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
07-20-2015 02:13 PM
07-20-2015 02:13 PM
help with output format
Hello experts..
I am not too familiar with scripts, but trying to do my best..
That's the scenario:
I am trying to build a script to collect some data (cluster information) from a list of servers, and then create an output with a table format.
- There is a list with some servers
- The script must collect these Cluster information
Cluster Name
Packages Names
Packages State
Last failover
Outuput in a table format:
(Server “where the script is running” ; Server “where the package is running” ; Package State ; Package Name ; Cluster Name ; Last failover “###### Package start completed for $package ######”)
Example:
server1 ; server1 ; running ; pck1 ; Cluster_Name ; Mar 14 12:15:23
server1 ; server1 ; running ; pck2 ; Cluster_Name ; Mar 14 12:16:13
server1 ; server2 ; running ; pck3 ; Cluster_Name ; Mar 14 12:14:06
server1 ; server3 ; running ; pck4 ; Cluster_Name ; Mar 14 12:14:59
server2 ; server1 ; running ; pck1 ; Cluster_Name ; Mar 14 12:15:23
server2 ; server1 ; running ; pck2 ; Cluster_Name ; Mar 14 12:16:13
server2 ; server2 ; running ; pck3 ; Cluster_Name ; Mar 14 12:14:06
server2 ; server3 ; running ; pck4 ; Cluster_Name ; Mar 14 12:14:59
server3 ; server1 ; running ; pck1 ; Cluster_Name ; Mar 14 12:15:23
server3 ; server1 ; running ; pck2 ; Cluster_Name ; Mar 14 12:16:13
server3 ; server2 ; running ; pck3 ; Cluster_Name ; Mar 14 12:14:06
server3 ; server3 ; running ; pck4 ; Cluster_Name ; Mar 14 12:14:59
server4 ; server1 ; running ; pck1 ; Cluster_Name ; Mar 14 12:15:23
server4 ; server1 ; running ; pck2 ; Cluster_Name ; Mar 14 12:16:13
server4 ; server2 ; running ; pck3 ; Cluster_Name ; Mar 14 12:14:06
server4 ; server3 ; running ; pck4 ; Cluster_Name ; Mar 14 12:14:59
sounds duplicated information due the script running on all servers.. but the output must be following this format..
idk if it's possible, but also add if the server is in standy mode (server4 in this example)
script:
#!/bin/bash > /tmp/cluster.orig for i in `cat /tmp/servers.list` do echo $i > /tmp/hostname CMD=`ssh -o BatchMode=yes -o ConnectTimeout=1 $i "whereis cmviewcl" 2>/dev/null | awk '{print $2}'` if [ -n "$CMD" ]; then CLUSTER=`ssh -o BatchMode=yes -o ConnectTimeout=1 $i "$CMD" 2>/dev/null | grep -i up | head -1 | awk '{print $1}'` ssh -o BatchMode=yes -o ConnectTimeout=1 $i "$CMD" 2>/dev/null | grep enabled | grep -v unowned | grep -v enqor > /tmp/cluster.tmp while read -r a b c d e ; do ssh -o BatchMode=yes -o ConnectTimeout=1 $i "cat /opt/cmcluster/run/log/$a*.log" 2>/dev/null | grep "######" | grep start | tail -1 | cut -c 1-15 > /tmp/last.tmp LOG=`cat /tmp/last.tmp | awk '{print $1}'` if [ -z $LOG ];then ssh -o BatchMode=yes -o ConnectTimeout=1 $i "cat /etc/cmcluster/$a/*$a.log" 2>/dev/null | grep "######" | grep start | tail -1 | cut -c 1-15 > /tmp/last.tmp fi LOG2=`cat /var/admin/mahi/last.tmp | awk '{print $1}'` if [ -z $LOG2 ];then ssh -o BatchMode=yes -o ConnectTimeout=1 $i "cat /opt/cmcluster/conf/$a/*$a.log" 2>/dev/null | grep "######" | grep start | tail -1 | cut -c 1-15 > /tmp/last.tmp fi echo "`cat /tmp/hostname` ; $e ; $c ; $a ; $CLUSTER ; `cat /tmp/last.tmp`" >> /tmp/cluster.orig; done < /tmp/cluster.tmp fi done fi cp /tmp/cluster.orig /tmp/cluster.csv chmod 400 /tmp/cluster.orig chmod 644 /tmp/cluster.csv rm -f /tmp/last.tmp rm -f /tmp/cluster.tmp rm -f /tmp/hostname
well, it's not working as expected.. Could you guys help me to figure out what is wrong?
thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2015 02:24 PM
07-20-2015 02:24 PM
Re: help with output format
>>well, it's not working as expected..
What's it doing, or not doing, that you expect it to? Examples of the output and or errors would be helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2015 04:51 PM
07-20-2015 04:51 PM
Re: help with output format
Some style and other points:
for server in $(< /tmp/servers.list); do
Remove evil cat and `` and replace by $(< file). $i is probably not the best name with several loops.
CMD=$(ssh -o BatchMode=yes -o ConnectTimeout=1 $server "whereis cmviewcl" 2>/dev/null | awk '{print $2}')
Remove grep/head from awk pipeline
CLUSTER=$(ssh -o BatchMode=yes -o ConnectTimeout=1 $server "$CMD" 2>/dev/null | awk '/[Uu][Pp]/ {print $1; exit}')
Remove multiple grep -v:
ssh -o BatchMode=yes -o ConnectTimeout=1 $server "$CMD" 2>/dev/null | grep enabled | grep -v -e unowned -e enqor > /tmp/cluster.tmp
Is this loop terminating early? (Better names would also help.)
while read -r a b c d e; do
Since in a while read loop, may have to add -n:
ssh -n -o BatchMode=yes -o ConnectTimeout=1 $server "cat /opt/cmcluster/run/log/$a*.log" 2>/dev/null | grep "######" | grep start | tail -1 | cut -c 1-15 > /tmp/last.tmp
The two greps can be combined if you know the order: grep "######.*start"
No need for cat awk pipeline:
LOG=$(awk '{print $1}' /tmp/last.tmp)
Again -n:
ssh -n -o BatchMode=yes -o ConnectTimeout=1 $server "cat /etc/cmcluster/$a/*$a.log" 2>/dev/null | grep "######" | grep start | tail -1 | cut -c 1-15 > /tmp/last.tmp
Combine two greps.
Again and do you really want /var/admin/mahi/ vs /tmp?
LOG2=$(awk '{print $1}' /var/admin/mahi/last.tmp)
Again, -n and two greps:
ssh -n -o BatchMode=yes -o ConnectTimeout=1 $server "cat /opt/cmcluster/conf/$a/*$a.log" 2>/dev/null | grep "######" | grep start | tail -1 | cut -c 1-15 > /tmp/last.tmp
Indent, remove evil cat and split into two, so you can see the "done":
echo "$(< /tmp/hostname) ; $e ; $c ; $a ; $CLUSTER ; $(< /tmp/last.tmp)" >> /tmp/cluster.orig
done < /tmp/cluster.tmp