For some unknown reason, Oracle considers it necessary to distribute their UNIX software in .cpio files. Since this is the only time I ever use cpio, I can never remember the command and I always end up looking it up.
Well, for future reference, here is how you extract a .cpio file to the current directory on most platforms:
cpio -idmv < filename_to_extract.cpio
Some platforms, like AIX, may give errors like this with these options:
cpio: 0511-903 Out of phase!
cpio attempting to continue...
cpio: 0511-904 skipping 732944 bytes to get back in phase!
One or more files lost and the previous file is possibly corrupt!
cpio: 0511-027 The file name length does not match the expected value.
If you run into these you need to add the
c option as the headers are stored in ASCII. The command should now look like this:
cpio -idcmv < filename_to_extract.cpio
For more information refer to the man page for cpio, but this is all I ever do with cpio. For a better UNIX archiving utility, consider tar.
Earlier today a situation came up where a UNIX timestamp (a count of the number of seconds from January 1, 1970, midnight GMT) needed to be converted into an Oracle DATE format. The Oracle TO_DATE (covered in more detail in my article Oracle, SQL, Dates and Timestamps) does not support this type of conversion.
A Google search confirmed for me that their was no easy way to make the TO_DATE function do this, but I did find this article from the Oracle + PHP Cookbook on Oracle’s site which contained this simple function to convert UNIX timestamps to Oracle dates.
[SQL]CREATE OR REPLACE
FUNCTION unixts_to_date(unixts IN PLS_INTEGER) RETURN DATE IS
* Converts a UNIX timestamp into an Oracle DATE
unix_epoch DATE := TO_DATE(‘19700101000000′,’YYYYMMDDHH24MISS’);
max_ts PLS_INTEGER := 2145916799; — 2938-12-31 23:59:59
min_ts PLS_INTEGER := -2114380800; — 1903-01-01 00:00:00
IF unixts > max_ts THEN
‘UNIX timestamp too large for 32 bit limit’
ELSIF unixts < min_ts THEN
'UNIX timestamp too small for 32 bit limit' );
oracle_date := unix_epoch + NUMTODSINTERVAL(unixts, 'SECOND');
Once compiled, you can use the function to convert numerical UNIX timestamps into Oracle dates in the same manner you would use the TO_DATE function to convert text to dates. Here is an example:
SQL> select unixts_to_date(1094165422) from dual;
oracle, sql, dba, database administration, database development, unix, unix timestamp, timestamp
If you have done much UNIX systems administration you have probably seen output like this from the â€˜findâ€™ command:
$ find / -name lifeaftercoffee.com
find: /proc/tty/driver: Permission denied
find: /proc/sys/kernel/pax: Permission denied
find: /proc/net: Permission denied
find: /proc/4680/fd: Permission denied
find: /usr/local/dh/apache/logs/basic-argon/fastcgi: Permission denied
find: /usr/local/dh/apache/logs/basic-bongo/fastcgi: Permission denied
find: /usr/local/dh/apache/logs/basic-cabo/fastcgi: Permission denied
find: /usr/local/dh/apache/logs/basic-dap/fastcgi: Permission denied
find: /usr/local/dh/apache/logs/basic-adamant/fastcgi: Permission denied
find: /usr/local/dh/apache/logs/basic-emu/fastcgi: Permission denied
find: /usr/local/dh/apache/logs/basic-fritz/fastcgi: Permission denied
find: /usr/local/dh/apache/logs/basic-grog/fastcgi: Permission denied
Annoying, to say the least, that your actual search results may be buried in pages upon pages of this.
Hereâ€™s a quick way around this. Redirect the error output to /dev/null (the black hole of data.) Itâ€™s as simple as appending â€˜2>/dev/nullâ€™ to the end of the command.
$ find ./ -name lifeaftercoffee.com 2>/dev/null
Any errors are ignored, which can complicate troubleshooting, but if things arenâ€™t doing what you want them to, just drop the redirect and run the command to see the errors again.
The command may vary depending on your shell and breed of UNIX, but this has always worked for me.
For more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.
Technorati tags: unix, solaris, system administration, sysadmin, find