Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by ashsysad
at 2024-11-24 10:08:06
Point:500 Replies:11 POST_ID:828823USER_ID:11730
Topic:
Linux;Shell Scripting;Unix Operating Systems
This requirement could be wierd. Please excuse me.
I have a tiny monitoring script written using Bash. The script captures some server statistics and write the details in a file with the Timestamp. The timestamp is captured using the following syntax: `date +%H:%M:%S %Z`. The timezone of the server is configured as "America/Los Angeles" (PST).
[root@serverxyz]# CURR_TIME=`date +%H:%M:%S %Z`
[root@serverxyz]# echo $CURR_TIME
09:56:50 PST
[root@serverxyz]# cat /etc/sysconfig/clock
ZONE="America/Los_Angeles"
UTC=true
ARC=false
[root@serverxyz]#
My requirement is, instead of capturing the time in PST, we want to report using other Timezone (say IST) but without changing the Timezone on the server. Hence the statistics file should contain equivalent Timestamps in IST that match with PST. Is that possible ?
Please let me know some ideas or solutions to my requirement. Thanks !
I have a tiny monitoring script written using Bash. The script captures some server statistics and write the details in a file with the Timestamp. The timestamp is captured using the following syntax: `date +%H:%M:%S %Z`. The timezone of the server is configured as "America/Los Angeles" (PST).
[root@serverxyz]# CURR_TIME=`date +%H:%M:%S %Z`
[root@serverxyz]# echo $CURR_TIME
09:56:50 PST
[root@serverxyz]# cat /etc/sysconfig/clock
ZONE="America/Los_Angeles"
UTC=true
ARC=false
[root@serverxyz]#
My requirement is, instead of capturing the time in PST, we want to report using other Timezone (say IST) but without changing the Timezone on the server. Hence the statistics file should contain equivalent Timestamps in IST that match with PST. Is that possible ?
Please let me know some ideas or solutions to my requirement. Thanks !
Author: ashsysad replied at 2024-11-26 11:07:29
Please ignore my previous comment, I got it now after so much of thinking :)
Author: ashsysad replied at 2024-11-26 10:42:39
Hello Tintin, Thanks for the solution but there is a question raised from my management.
Question is "How this syntax works and there the IST timestamp get stored" ?
When I checked, I found the GMT for California is "GMT - 8:00" and for India is "GMT+5.30".
For example, let’s assume the time now in India in 12 midnight, 11/27/13 and the time in SanFrancisco is 10.30 AM PST 11/26/13. The Greenwich Mean time would be 6.30 PM GMT 11/26/13. Given this case, how GMT-5.30 would match with IST ? Please explain, I just can't understand this. Sorry to bug you :)
Question is "How this syntax works and there the IST timestamp get stored" ?
When I checked, I found the GMT for California is "GMT - 8:00" and for India is "GMT+5.30".
For example, let’s assume the time now in India in 12 midnight, 11/27/13 and the time in SanFrancisco is 10.30 AM PST 11/26/13. The Greenwich Mean time would be 6.30 PM GMT 11/26/13. Given this case, how GMT-5.30 would match with IST ? Please explain, I just can't understand this. Sorry to bug you :)
Author: ashsysad replied at 2024-11-25 06:52:40
Hello Tintin, As usual, you rocked !!
I customized the syntax like this:
TIME_IN_IST=`TZ='GMT-5:30' date +"%H:%M:%S %D IST"`
Thanks a lot !!
I customized the syntax like this:
TIME_IN_IST=`TZ='GMT-5:30' date +"%H:%M:%S %D IST"`
Thanks a lot !!
Accepted Solution
Expert: Tintin replied at 2024-11-24 21:14:42
350 points EXCELLENT
You might have to use the GMT offset, as it appears timezones that aren't in whole hour offsets from GMT might be a problem.
Author: ashsysad replied at 2024-11-24 20:46:46
I'm still struggling to get this right.
[puppetmaster ~]$ date
Sun Nov 24 20:44:22 PST 2013
[puppetmaster ~]$ echo CURR_TIME=`TZ=IST date +"%H:%M:%S %Z"`
CURR_TIME=04:44:26 IST
[puppetmaster ~]$
Please note the current time in IST suppose to be ~10.15 AM
Tried with various 'date' command option, but not getting it right.
[puppetmaster ~]$ date
Sun Nov 24 20:44:22 PST 2013
[puppetmaster ~]$ echo CURR_TIME=`TZ=IST date +"%H:%M:%S %Z"`
CURR_TIME=04:44:26 IST
[puppetmaster ~]$
Please note the current time in IST suppose to be ~10.15 AM
Tried with various 'date' command option, but not getting it right.
Assisted Solution
Expert: duncanb7 replied at 2024-11-24 13:29:21
150 points EXCELLENT
Yes, Tintin is correct his code also report it in IST that is similar to Asia/Delhi
echo CURR_TIME=`TZ=IST date +"%H:%M:%S %Z"` that is same as
echo CURR_TIME=`TZ=Asia/Delhi date +"%H:%M:%S %Z"`
but Tintin's one has IST format in output that I think author will prefer more.
ashsysad, I think you can handle easily it to find all string related to PST and then replace it by Tintin's one command in your script
I am out here and I have no more comment in this thread
and have a nice day
Duncan
echo CURR_TIME=`TZ=IST date +"%H:%M:%S %Z"` that is same as
echo CURR_TIME=`TZ=Asia/Delhi date +"%H:%M:%S %Z"`
but Tintin's one has IST format in output that I think author will prefer more.
ashsysad, I think you can handle easily it to find all string related to PST and then replace it by Tintin's one command in your script
I am out here and I have no more comment in this thread
and have a nice day
Duncan
Expert: Tintin replied at 2024-11-24 13:07:14
Author: ashsysad replied at 2024-11-24 12:46:15
Sorry, I'm not getting it clearly. Could you please explain it better ? Thanks !
Expert: duncanb7 replied at 2024-11-24 11:22:05
Command Linux example, from convert PST to IST time, where you
program or change 11:00 time constant to your script varible according
to your need
TZ=Asia/Delhi date -d "11:00 PST"
//that command will report Sun Nov 24 19:00:00 Asia 2013 (IST time)
Hope it will help
Duncan
program or change 11:00 time constant to your script varible according
to your need
TZ=Asia/Delhi date -d "11:00 PST"
//that command will report Sun Nov 24 19:00:00 Asia 2013 (IST time)
Hope it will help
Duncan
Author: ashsysad replied at 2024-11-24 11:09:52
@Duncan, Here is a sample output of the script. In this, you can see the Time-stamps are captured in PST. But I want that to be on IST instead. For doing so, I can't change the Timezone settings on the server since it will affected the Application. Anything can be done on the shell script to convert the time in PST to IST ? Basically the script should take the system time (which is in PST) and echo the time-stamp in IST.
----------------START OF ITERATION at 10:54:01 PST 11/24/13---------------------
<<<<<<<<<<<<<<<<< LDAP SEARCH RESULT >>>>>>>>>>>>>>>>>>>>>>>>>>>
Elapsed Time for Ldapsearch query is 002
<<<<<<<<<<<<<< Checking Telnet Response >>>>>>>>>>>>>>>>
VIP is responding to Port 3268
<<<<<<<<<<<<<<<<<<<<<< PING RESULT >>>>>>>>>>>>>>>>>>>>
Average Ping response is 0
<<<<<<<<<<<<<<<<<< NETSTAT OUTPUT >>>>>>>>>>>>>>>>>>>>
Total number of TCP connections to VIP is 8
----------------END OF ITERATION at 10:54:05 PST 11/24/13----------------------
----------------START OF ITERATION at 10:55:01 PST 11/24/13---------------------
<<<<<<<<<<<<<<<<< LDAP SEARCH RESULT >>>>>>>>>>>>>>>>>>>>>>>>>>>
Elapsed Time for Ldapsearch query is 002
<<<<<<<<<<<<<< Checking Telnet Response >>>>>>>>>>>>>>>>
VIP is responding to Port 3268
<<<<<<<<<<<<<<<<<<<<<< PING RESULT >>>>>>>>>>>>>>>>>>>>
Average Ping response is 0
<<<<<<<<<<<<<<<<<< NETSTAT OUTPUT >>>>>>>>>>>>>>>>>>>>
Total number of TCP connections to VIP is 8
----------------END OF ITERATION at 10:55:06 PST 11/24/13----------------------
----------------START OF ITERATION at 10:56:01 PST 11/24/13---------------------
<<<<<<<<<<<<<<<<< LDAP SEARCH RESULT >>>>>>>>>>>>>>>>>>>>>>>>>>>
Elapsed Time for Ldapsearch query is 002
<<<<<<<<<<<<<< Checking Telnet Response >>>>>>>>>>>>>>>>
VIP is responding to Port 3268
<<<<<<<<<<<<<<<<<<<<<< PING RESULT >>>>>>>>>>>>>>>>>>>>
Average Ping response is 0
<<<<<<<<<<<<<<<<<< NETSTAT OUTPUT >>>>>>>>>>>>>>>>>>>>
Total number of TCP connections to VIP is 8
----------------END OF ITERATION at 10:56:05 PST 11/24/13----------------------
----------------START OF ITERATION at 10:57:01 PST 11/24/13---------------------
<<<<<<<<<<<<<<<<< LDAP SEARCH RESULT >>>>>>>>>>>>>>>>>>>>>>>>>>>
Elapsed Time for Ldapsearch query is 002
<<<<<<<<<<<<<< Checking Telnet Response >>>>>>>>>>>>>>>>
VIP is responding to Port 3268
<<<<<<<<<<<<<<<<<<<<<< PING RESULT >>>>>>>>>>>>>>>>>>>>
Average Ping response is 0
<<<<<<<<<<<<<<<<<< NETSTAT OUTPUT >>>>>>>>>>>>>>>>>>>>
Total number of TCP connections to VIP is 8
----------------END OF ITERATION at 10:57:05 PST 11/24/13----------------------
----------------START OF ITERATION at 10:54:01 PST 11/24/13---------------------
<<<<<<<<<<<<<<<<< LDAP SEARCH RESULT >>>>>>>>>>>>>>>>>>>>>>>>>>>
Elapsed Time for Ldapsearch query is 002
<<<<<<<<<<<<<< Checking Telnet Response >>>>>>>>>>>>>>>>
VIP is responding to Port 3268
<<<<<<<<<<<<<<<<<<<<<< PING RESULT >>>>>>>>>>>>>>>>>>>>
Average Ping response is 0
<<<<<<<<<<<<<<<<<< NETSTAT OUTPUT >>>>>>>>>>>>>>>>>>>>
Total number of TCP connections to VIP is 8
----------------END OF ITERATION at 10:54:05 PST 11/24/13----------------------
----------------START OF ITERATION at 10:55:01 PST 11/24/13---------------------
<<<<<<<<<<<<<<<<< LDAP SEARCH RESULT >>>>>>>>>>>>>>>>>>>>>>>>>>>
Elapsed Time for Ldapsearch query is 002
<<<<<<<<<<<<<< Checking Telnet Response >>>>>>>>>>>>>>>>
VIP is responding to Port 3268
<<<<<<<<<<<<<<<<<<<<<< PING RESULT >>>>>>>>>>>>>>>>>>>>
Average Ping response is 0
<<<<<<<<<<<<<<<<<< NETSTAT OUTPUT >>>>>>>>>>>>>>>>>>>>
Total number of TCP connections to VIP is 8
----------------END OF ITERATION at 10:55:06 PST 11/24/13----------------------
----------------START OF ITERATION at 10:56:01 PST 11/24/13---------------------
<<<<<<<<<<<<<<<<< LDAP SEARCH RESULT >>>>>>>>>>>>>>>>>>>>>>>>>>>
Elapsed Time for Ldapsearch query is 002
<<<<<<<<<<<<<< Checking Telnet Response >>>>>>>>>>>>>>>>
VIP is responding to Port 3268
<<<<<<<<<<<<<<<<<<<<<< PING RESULT >>>>>>>>>>>>>>>>>>>>
Average Ping response is 0
<<<<<<<<<<<<<<<<<< NETSTAT OUTPUT >>>>>>>>>>>>>>>>>>>>
Total number of TCP connections to VIP is 8
----------------END OF ITERATION at 10:56:05 PST 11/24/13----------------------
----------------START OF ITERATION at 10:57:01 PST 11/24/13---------------------
<<<<<<<<<<<<<<<<< LDAP SEARCH RESULT >>>>>>>>>>>>>>>>>>>>>>>>>>>
Elapsed Time for Ldapsearch query is 002
<<<<<<<<<<<<<< Checking Telnet Response >>>>>>>>>>>>>>>>
VIP is responding to Port 3268
<<<<<<<<<<<<<<<<<<<<<< PING RESULT >>>>>>>>>>>>>>>>>>>>
Average Ping response is 0
<<<<<<<<<<<<<<<<<< NETSTAT OUTPUT >>>>>>>>>>>>>>>>>>>>
Total number of TCP connections to VIP is 8
----------------END OF ITERATION at 10:57:05 PST 11/24/13----------------------
Expert: duncanb7 replied at 2024-11-24 10:40:22
Dear ashsysad,
you want your system time in IST, right?
Could you use this setting and put it in php.ini file located at /usr/lib
if you have root access to your Linux server ?
// Delhi, India, Asia
date.timezone = "Asia/Delhi"
date.default_latitude = 28.40
date.default_longitude = 77.13
and put echo date command in your bash script
that will show you time in IST that I believe
Hope I understand your question completely, if not please point it out
Duncan
you want your system time in IST, right?
Could you use this setting and put it in php.ini file located at /usr/lib
if you have root access to your Linux server ?
// Delhi, India, Asia
date.timezone = "Asia/Delhi"
date.default_latitude = 28.40
date.default_longitude = 77.13
and put echo date command in your bash script
that will show you time in IST that I believe
Hope I understand your question completely, if not please point it out
Duncan