[20180608]asmcmd顯示檔案的日期時間問題
[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 'MON DD HH24:MI:SS' format. #.
--//實際上這種模式與os的ls命令一樣,我個人非常不習慣這種風格,我喜歡格式'YYYY/MM/DD HH24:MI:SS',這樣國人的顯示風格一直.
$ locate asmcmdbase.pm
/u01/app/11.2.0/grid/lib/asmcmdbase.pm
/u01/app/oracle/product/11.2.0/dbhome_1/lib/asmcmdbase.pm
--//檢索sub asmcmdbase_ls_process_file,就可以定位以上資訊.
--//按照連結的提示修改,注意修改前一定要做好備份.
# cp asmcmdbase.pm asmcmdbase.pm.ORG
# cp asmcmdshare.pm asmcmdshare.pm.ORG
--//修改asmcmdshare.pm檔案:
# diff -Nur asmcmdshare.pm.ORG asmcmdshare.pm
--- asmcmdshare.pm.ORG 2018-06-08 09:00:56.566081223 +0800
+++ asmcmdshare.pm 2018-06-08 09:05:26.920081038 +0800
@@ -1916,11 +1916,14 @@
my ($sth, $qry, $row, $cmpd_ind);
$cmpd_ind = $gnum * (1 << 24) + $fnum;
+
+ if(!$ENV{'NLS_DATE_FORMAT_XX'}){ $ENV{'NLS_DATE_FORMAT_XX'} = "yyyy/mm/dd hh24:mi:ss"; }
$qry = 'select group_number, file_number, incarnation, block_size, ' .
'blocks, bytes, space, type, redundancy, striped, creation_date, ' .
'user_number, usergroup_number, permissions, ' .
'to_char(modification_date, \'MON DD HH24:MI:SS\') "MOD_TIME", ' .
+ 'to_char(modification_date, \''.$ENV{'NLS_DATE_FORMAT_XX'}.'\') "MOD_TIME_XX", ' .
'to_char(modification_date, \'MON DD YYYY\') "MOD_DATE", ' .
'to_char(modification_date, \'J HH24 MI SS\') "JULIAN_TIME", ' .
'to_char(modification_date, \'J\') "JULIAN_DATE" ' .
@@ -1945,6 +1948,7 @@
$file_info_ref->{'creation_date'} = $row->{'CREATION_DATE'};
$file_info_ref->{'mod_time'} = $row->{'MOD_TIME'};
$file_info_ref->{'mod_date'} = $row->{'MOD_DATE'};
+ $file_info_ref->{'mod_time_xx'} = $row->{'MOD_TIME_XX'};
$file_info_ref->{'julian_time'} = $row->{'JULIAN_TIME'};
$file_info_ref->{'julian_date'} = $row->{'JULIAN_DATE'};
$file_info_ref->{'user_number'} = $row->{'USER_NUMBER'};
--//修改asmcmdbase.pm檔案:
# diff -Nur asmcmdbase.pm.ORG asmcmdbase.pm
--- asmcmdbase.pm.ORG 2018-06-08 08:59:26.442748126 +0800
+++ asmcmdbase.pm 2018-06-08 09:08:48.659080899 +0800
@@ -2044,6 +2044,8 @@
{ # Otherwise, use 'MON DD HH24:MI:SS' format. #
$entry_info_ref->{'date_print'} = $entry_info_ref->{'mod_time'};
}
+ # Overwrite date_print
+ $entry_info_ref->{'date_print'} = $entry_info_ref->{'mod_time_xx'};
}
# Find system alias only if we have info from v$asm_file, i.e., if we're
--//定義環境變數:
$ export NLS_DATE_FORMAT_XX="yyyy/mm/dd hh24:mi:ss"
ASMCMD [+Data/Fyhis/PARAMETERFILE] > ls -l
Type Redund Striped Time Sys Name
Use of uninitialized value $print_args[5] in printf at /u01/app/11.2.0/grid/lib/asmcmdbase.pm line 2369, <STDIN> line 7.
PARAMETERFILE UNPROT COARSE 2018/06/08 00:00:00 Y spfile.272.931438543
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
Use of uninitialized value $print_args[5] in printf at /u01/app/11.2.0/grid/lib/asmcmdbase.pm line 2369, <STDIN> line 14.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ARCHIVELOG UNPROT COARSE 2017/02/09 23:00:00 Y 512 937 479744 1048576 thread_1_seq_3773.3605.935537807
--//有錯.
--//我仔細看了一下指令碼:
# vim asmcmdbase.pm
..
..
2306 if ($entry_ref->{'alias_directory'} eq 'Y')
2307 { # Directries have the suffix '/'. #
2308 $entry_ref->{'name_print'} .= '/';
2309 }
2310 elsif (defined ($args_ref->{'l'}))
2311 { # Date values exists for files only. #
2312 ($mon, $day, $time) = split (/\s+/, $entry_ref->{'date_print'});
~~~~~~~~//這裡要拆分3個引數,必須修改如下,這樣就存在3個引數:
+ if(!$ENV{'NLS_DATE_FORMAT_XX'}){ $ENV{'NLS_DATE_FORMAT_XX'} = "yyyy/mm/dd hh24:mi:ss "; }
~~~~~~~~~//注意我在ss後面加入1個空格,當然對應的不是月,日,時間.
2313 }
2314
2315
2316
2317 if (($entry_ref->{'alias_directory'} eq 'Y') ||
2318 (($entry_ref->{'system_created'} eq 'N') &&
2319 (!defined ($args_ref->{'L'}))))
2320 {
2321 $entry_ref->{'type'} = $ASMCMDBASE_SPACE;
2322 $entry_ref->{'redundancy'} = $ASMCMDBASE_SPACE;
2323 $entry_ref->{'striped'} = $ASMCMDBASE_SPACE;
2324 $mon = $ASMCMDBASE_SPACE;
2325 $day = $ASMCMDBASE_SPACE;
2326 $time = $ASMCMDBASE_SPACE;
2327 $entry_ref->{'space'} = $ASMCMDBASE_SPACE;
2328
2329 $entry_ref->{'block_size'} = $ASMCMDBASE_SPACE;
2330 $entry_ref->{'blocks'} = $ASMCMDBASE_SPACE;
2331 $entry_ref->{'bytes'} = $ASMCMDBASE_SPACE;
2332
2333 $entry_ref->{'user'} = $ASMCMDBASE_SPACE;
2334 $entry_ref->{'group'} = $ASMCMDBASE_SPACE;
2335 $entry_ref->{'perm'} = $ASMCMDBASE_SPACE;
2336 }
2337
2338 @print_args = ();
2339
2340 if (defined($args_ref->{'l'})) # ls -l. #
2341 {
2342 push (@print_args, $entry_ref->{'type'});
2343 push (@print_args, $entry_ref->{'redundancy'});
2344 push (@print_args, $entry_ref->{'striped'});
2345 push (@print_args, $mon);
2346 push (@print_args, $day);
2347 push (@print_args, $time);
2348 push (@print_args, $ASMCMDBASE_SPACE);
2349 push (@print_args, $entry_ref->{'system_created'});
2350 }
2351
2352 if (defined($args_ref->{'s'})) # ls -s. #
2353 {
2354 push (@print_args, $entry_ref->{'block_size'});
2355 push (@print_args, $entry_ref->{'blocks'});
2356 push (@print_args, $entry_ref->{'bytes'});
2357 push (@print_args, $entry_ref->{'space'});
2358 }
2359
2360 if (defined($args_ref->{'permission'})) # ls --permission -l. #
2361 {
2362 push (@print_args, $entry_ref->{'user'});
2363 push (@print_args, $entry_ref->{'group'});
2364 push (@print_args, $entry_ref->{'perm'});
2365 }
2366
2367 push(@print_args, $entry_ref->{'name_print'});
2368
2369 printf ($row, @print_args);
2370
2371 return;
2372 }
--//修改後在執行OK.不再報錯.也許作者修改的版本與我的不同.
ASMCMD [+] > ls +DATA/FYHIS/PARAMETERFILE -ls
Type Redund Striped Time Sys Block_Size Blocks Bytes Space Name
PARAMETERFILE UNPROT COARSE 2018/06/08 00:00:00 Y 512 13 6656 1048576 spfile.272.931438543
ASMCMD [+] > ls +DATA/FYHIS/PARAMETERFILE -l
Type Redund Striped Time Sys Name
PARAMETERFILE UNPROT COARSE 2018/06/08 00:00:00 Y spfile.272.931438543
--//還有1個缺點就是sys,name列出現偏移.
--//當然也一些變通的方法,比如定義環境變數:
export NLS_DATE_FORMAT_XX="YY/MM/DD HH24 "
--//注意引號後有1個空格,這樣就認為有3個欄位.
ASMCMD [+] > ls +DATA/FYHIS/PARAMETERFILE -l
Type Redund Striped Time Sys Name
PARAMETERFILE UNPROT COARSE 18/06/08 00 Y spfile.272.931438543
--//但是最後2列還是存在偏移.
--//有點亂,最後修改如下:
# diff -Nur asmcmdshare.pm.ORG asmcmdshare.pm
--- asmcmdshare.pm.ORG 2018-06-08 09:00:56.566081223 +0800
+++ asmcmdshare.pm 2018-06-08 10:14:21.633059695 +0800
@@ -1916,11 +1916,14 @@
my ($sth, $qry, $row, $cmpd_ind);
$cmpd_ind = $gnum * (1 << 24) + $fnum;
+
+ if(!$ENV{'NLS_DATE_FORMAT_XX'}){ $ENV{'NLS_DATE_FORMAT_XX'} = "YYYY/MM/DD HH24:MI:SS "; }
$qry = 'select group_number, file_number, incarnation, block_size, ' .
'blocks, bytes, space, type, redundancy, striped, creation_date, ' .
'user_number, usergroup_number, permissions, ' .
'to_char(modification_date, \'MON DD HH24:MI:SS\') "MOD_TIME", ' .
+ 'to_char(modification_date, \''.$ENV{'NLS_DATE_FORMAT_XX'}.'\') "MOD_TIME_XX", ' .
'to_char(modification_date, \'MON DD YYYY\') "MOD_DATE", ' .
'to_char(modification_date, \'J HH24 MI SS\') "JULIAN_TIME", ' .
'to_char(modification_date, \'J\') "JULIAN_DATE" ' .
@@ -1945,6 +1948,7 @@
$file_info_ref->{'creation_date'} = $row->{'CREATION_DATE'};
$file_info_ref->{'mod_time'} = $row->{'MOD_TIME'};
$file_info_ref->{'mod_date'} = $row->{'MOD_DATE'};
+ $file_info_ref->{'mod_time_xx'} = $row->{'MOD_TIME_XX'};
$file_info_ref->{'julian_time'} = $row->{'JULIAN_TIME'};
$file_info_ref->{'julian_date'} = $row->{'JULIAN_DATE'};
$file_info_ref->{'user_number'} = $row->{'USER_NUMBER'};
# diff -Nur asmcmdbase.pm.ORG asmcmdbase.pm
--- asmcmdbase.pm.ORG 2018-06-08 08:59:26.442748126 +0800
+++ asmcmdbase.pm 2018-06-08 10:12:15.591059782 +0800
@@ -2044,6 +2044,8 @@
{ # Otherwise, use 'MON DD HH24:MI:SS' format. #
$entry_info_ref->{'date_print'} = $entry_info_ref->{'mod_time'};
}
+ # Overwrite date_print
+ $entry_info_ref->{'date_print'} = $entry_info_ref->{'mod_time_xx'};
}
# Find system alias only if we have info from v$asm_file, i.e., if we're
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2155826/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- QT顯示當前日期時間QT
- 讓history命令顯示日期和時間
- win10 在桌面上顯示日期時間的方法_win10怎麼把時間日期顯示在桌面Win10
- win10時間不顯示日期怎麼辦_win10電腦只顯示時間沒有日期如何處理Win10
- 若依解決VUE前端時間顯示問題Vue前端
- 在終端裡按你的方式顯示日期和時間
- Qt:通過QLabel控制元件來顯示實時日期時間QT控制元件
- QQ 群檔案下載後過期時間顯示 undefinedUndefined
- Java 8 的日期與時間問題解決方案Java
- Qt中利用定時器QTimer實時顯示當前日期和時間QT定時器
- win10系統如何設定時間日期顯示農曆Win10
- mac顯示隱藏檔案,取消顯示隱藏檔案Mac
- win10調時間找不到檔案怎麼辦_win10調整時間顯示找不到檔案的解決方法Win10
- c++ 獲取檔案建立時間、修改時間、訪問時間、檔案內容長度C++
- 2個例項幫你弄清Python的時間和日期問題Python
- vue使用iview Timeline 時間軸不顯示渲染的效果問題解決辦法VueView
- Oracle的SCN顯示問題Oracle
- Mac顯示/不顯示隱藏檔案教程!Mac
- js時間顯示設定JS
- 關於vue打包後scss檔案中背景圖片不顯示問題VueCSS
- QT學習 實時顯示時間QT
- win10電腦桌面顯示時間和天氣日期怎麼設定Win10
- ASP.NET MVC下使用AngularJs語言(九):日期時間處理與顯示ASP.NETMVCAngularJS
- Acrobat Mac使用技巧:如何解決開啟PDF檔案時顯示已損壞無法修復的問題!BATMac
- qt 使用qmake pro檔案新增 ico圖示,程式執行時顯示圖示,exe也顯示圖示QT
- Layui表格日期格式顯示UI
- win10系統開機鎖屏介面只顯示一張圖片不顯示日期時間如何解決Win10
- [linux] fuser程式顯示檔案Linux
- 【JAVA8新的時間與日期 API】- 傳統時間格式化的執行緒安全問題JavaAPI執行緒
- wordpress文章的顯示時間期限或過期時間的標誌
- Qt設計:時間顯示(QTimer)QT
- iOS日期時間iOS
- 日期和時間
- 日期時間類
- vue 專案引入字型圖示報錯、不顯示等問題Vue
- idea springboot專案主配置檔案(啟動檔案)顯示問號加紅叉,執行時: Unknown run configuration type SpringBootApplicationConf。。。IdeaSpring BootAPP
- Python 獲取檔案建立、訪問、修改時間Python
- win10系統長日期格式顯示怎麼設定 win10系統設定長時間格式顯示的步驟Win10