- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Colored timestamp
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
06-16-2012 10:17 PM
06-16-2012 10:17 PM
Hi I have the following script snippet which is used to ssh to a host and tail the logs , I need the timestamps to be colored (for the entries which are from today if possible) -
while read HST SERVER ENV PORT do [ $(echo ${SERVER}) != ${WHATSERVER} ] && continue ssh -n ${HST} "tail -500 /Logs/${SERVER}_${HST%%.foobar.com}_${PORT}" ssh -n ${HST} "ls -ltr /Logs/${SERVER}_${HST%%.foobar.com}_${PORT}" done < ${HSTFILE}
Logs are of following format-
>>>>> | dtm=2012-05-03 15:00:00.295 PDT |
Thanks,
Allan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2012 03:29 PM - edited 06-18-2012 04:32 PM
06-17-2012 03:29 PM - edited 06-18-2012 04:32 PM
Re: Colored timestamp
You might want to combine the two ssh commands into one:
ssh -n ${HST} "tail -500 /Logs/${SERVER}_${HST%%.foobar.com}_${PORT} ; \
ls -ltr /Logs/${SERVER}_${HST%%.foobar.com}_${PORT}"
>Logs are of following format: >>>>> | dtm=2012-05-03 15:00:00.295 PDT |
You could use sed to insert the escape sequences:
done < ${HSTFILE} | sed -e 's/\(.*dtm=\)\('$(date +"%Y-%m-%d")'\)\(.*$\)/\1ESC-start\2ESC-stop\3/'
Where ESC-start & ESC-stop are the appropriate escape sequences for your color. You may want to use tput(1) to generate them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2012 02:34 PM
06-18-2012 02:34 PM
Re: Colored timestamp
Hi Dennis,
For the sed statement I am getting -
sed -e '\(.*dtm=\)\('$(date +"%Y-%m-%d")'\)\(.*$\)/\1`tput smso`\2`tput rmso`\3/'
sed: 1: "\(.*dtm=\)\(2012-06-18\ ...": unterminated regular expression
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2012 05:09 PM
06-18-2012 05:09 PM
Solution>For the sed statement I am getting
Oops, I forgot the "s" command. See my post above.
Trying to use tput(1) directly doesn't work if it contains a "&", a sed special.
This is what I had to do:
# Need to use echo to add a newline since sed won't work on non-text files. Then remove the newline.
# Need to quote each "&" since special to sed.
SMSO=$(echo $(tput smso) | sed -e 's/\&/\\\&/g' -e 's/\\n//')
RMSO=$(echo $(tput rmso) | sed -e 's/\&/\\\&/g' -e 's/\\n//')
# while loop here
... sed -e 's/\(.*dtm=\)\('"$(date +"%Y-%m-%d")"'\)\(.*$\)/\1'"$SMSO"'\2'"$RMSO"'\3/'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2012 11:16 AM
08-19-2012 11:16 AM
Re: Colored timestamp
Reopening the thread.
Thanks to Dennis, I do get the date in colored , was wondering if we can get ERROR (all caps) also colored if it occurs in the logs.
Sample output which has ERROR.
>>>>> | dtm=2012-08-19 09:27:28.344 PDT | level=ERROR
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2012 12:48 PM
08-19-2012 12:48 PM
Re: Colored timestamp
>if we can get ERROR (all caps) also colored if it occurs in the logs.
If you don't care which date has the "ERROR" string:
sed -e ... -e "s/ERROR/${SMSO}ERROR${RMSO}/g"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2012 01:34 PM
08-19-2012 01:34 PM