- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - HP-UX
- >
- Languages and Scripting
- >
- Re: uptime check, awk sub function
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- Report Inappropriate Content
01-21-2014 10:41 AM
01-21-2014 10:41 AM
uptime check
Hi ,
>>uptime
7:40pm up 121 days, 14:47, 1 user, load average: 0.37, 0.30, 0.30
>>uptime | awk -F, '{sub(".*up ",x,$1);print $1,$2}'
121 days 14:47
Can you please tell me,How the awk command is working for above uptime.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-21-2014 12:05 PM - edited 01-21-2014 12:06 PM
01-21-2014 12:05 PM - edited 01-21-2014 12:06 PM
Re: uptime check, awk sub function
>How the awk command is working?
>awk -F, '{sub(".*up ", x, $1); print $1, $2}'
This says split fields based on comma: $1="7:40pm up 121 days" $2=" 14:47" $3=" 1 user" ...
Then is uses the sub function on $1 to replace an ERE with the first part of the string, up to "up ".
It replaces it by the variable "x" which is initialized to an empty string.
A better command would be to use a string constant: sub(".*up ", "", $1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-21-2014 01:23 PM
01-21-2014 01:23 PM
Re: uptime check, awk sub function
Hi Dennis,
Thanks for suggestion.
for HOST in $(< /tmp/hostdetails.txt); do
echo
ssh -q $HOST uptime | awk -F, '{sub(".*up", "", $1);print $1,$2}'
done
I am writing a script which checks the uptime of server.
I am running the script from a centralized server.
I need all uptime logs from other server to be availble in centralized server.
How can I do it ?
above script displays only uptime of all server,but I have to collect all uptime logs in centralized server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-21-2014 08:41 PM
01-21-2014 08:41 PM
Re: uptime check, awk sub function
>I need all uptime logs from other server to be available in centralized server.
If you run the script on your central server, you can simply redirect stdout:
echo $HOST
...
done >> uptime.log
This will append any stdout output in the loop to uptime.log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-27-2014 11:37 PM
01-27-2014 11:37 PM
Re: uptime check, awk sub function
Hi ,
I have two points to be clarified.
First Point
I am running the script from solaris server to check uptime status of hp-ux server.
>>for HOST in $(< /tmp/hostdetails.txt); do
when I use above format,I am getting error : syntax error $ unexpected.
but it is running fine with `cat /tmp/hostdetails.txt`
I need to know why i am getting syntax error for above cmd.
Second Point :
for example if a server is down or decommissioned,so when i run uptime script ,it gets waiting to get server status,but actually server is down.
I need to know how can i avoid this problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-28-2014 09:14 PM
01-28-2014 09:14 PM
Re: uptime check, awk sub function
>I am running the script from solaris server to check uptime status of HP-UX server.
Then your question doesn't belong in an HP-UX forum.
>when I use above format, I am getting error: syntax error $ unexpected.
I assume that Solaris has some real shells, ksh/Posix? And not scummy csh/tcsh nor Bourne sh.
>for example if a server is down or decommissioned
See your other topic for setting ssh timeouts:
http://h30499.www3.hp.com/t5/Languages-and-Scripting/setting-timeout-value/m-p/6346969#M46743
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP