- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- uptime check
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
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
- 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
- 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
- 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
- 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
- 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