[20180608]asmcmd显示文件的日期时间问题

本文讨论了在使用Oracle的ASMCMD工具时遇到的日期时间格式问题。默认情况下,对于超过6个月的文件,ASMCMD仅显示月份、日期和年份,而时间显示为00:00:00。通过分析asmcmdshare.pm和asmcmdbase.pm文件,了解到日期时间的打印逻辑,并提供了一个解决方案,即通过设置环境变量NLS_DATE_FORMAT_XX并修改源代码,使ASMCMD显示'YYYY/MM/DD HH24:MI:SS'格式的时间。通过修改和测试,成功实现了期望的时间格式显示,但发现可能会导致输出对齐问题,通过进一步调整代码解决了这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[20180608]asmcmd显示文件的日期时间问题.txt

http://blog.iarsov.com/oracle/date-and-time-format-in-asmcmd-for-file-listing/

--//如果你使用asmcmd查看asm文件,你可以发现日期时间的显示格式:
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production


ASMCMD [+data/fyhis/PARAMETERFILE] > ls -l
Type           Redund  Striped  Time             Sys  Name
PARAMETERFILE  UNPROT  COARSE   JUN 08 00:00:00  Y    spfile.272.931438543

--//仅仅显示日期,而时分秒都是0.

ASMCMD [+data/fyhis/ARCHIVELOG/2017_02_09] > ls -ls thread_1_seq_3773.3605.935537807
Type        Redund  Striped  Time             Sys  Block_Size  Blocks   Bytes    Space  Name
ARCHIVELOG  UNPROT  COARSE   FEB 09     2017  Y           512     937  479744  1048576  thread_1_seq_3773.3605.935537807

--//而实际上asmcmd是shell 脚本,最后运行的是perl脚本.
$ file $(which asmcmd)
/u01/app/11.2.0/grid/bin/asmcmd: POSIX shell script text executable

--//链接:http://blog.iarsov.com/oracle/date-and-time-format-in-asmcmd-for-file-listing/
ASMCMD utility base module is asmcmdbase.pm

The subroutine for listing files located in the base module is asmcmdbase_ls_process_file. You can see the logic how
file dates are printed. We can notice that if the file is older than 6 months the format used is "MON DD YYYY". If the
file is newer, the format used is "MON DD HH24:MI:SS". This subroutine is called (executed) for each file that needs to
be printed in ASMCMD.

List entries $entry_info_ref->{'mod_date'} and $entry_info_ref->{'mod_time'} contain the data for both hardcoded
formats. MOD_DATE if the files is older than 6 months and MOD_TIME if the file is newer.

sub asmcmdbase_ls_process_file
{
my ($dbh, $entry_info_ref, $args_ref, $cur_date, $file_info) = @_;

my ($related_alias); # The user or system alias for its corresponding #
# system or user alias, respectively. #

# Calculate dates only if we have file info from v$asm_file.
if ($file_info)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
# Use separate date format if date older than half a year.
if (($cur_date - $entry_info_ref->{'julian_date'}) >= $ASMCMDBASE_SIXMONTH)
{ # If older than six months, use 'MON DD YYYY' format. #
$entry_info_ref->{'date_print'} = $entry_info_ref->{'mod_date'};
}
else
{ # Otherwise, use 'MON DD HH24:MI:SS' format. #
$entry_info_ref->{'date_print'} = $entry_info_ref->{'mod_time'};
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   
}

--//说明:如果旧于6个月,显示日期.use 'MON DD YYYY' format.其他使用use '

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值