analytic

Tuesday, 23 October 2012

sort: open failed: +1: No such file or directory


Newer versions of POSIX are not fully compatible with older version of POSIX as a result, there are some changes in the parameters/switches for some commands like sort.
For Example, if the POSIX Version is 200112 or above, “sort +2″ command would through an error message “sort: open failed: +1: No such file or directory” as the newer version 200112 (1003.1-2001) is not fully compatible with POSIX older versions like 199209 (1003.2-1992).
[root@vcsnode1 ~]# ps -ef | sort +2
sort: open failed: +2: No such file or directory
[root@vcsnode1 ~]#
As a result, the sort command needs to be executed as below to sort the output based on column three which is equivalent to sort +2
[root@vcsnode1 ~]# ps -ef | sort -k 3 | head
root 1 0 0 May18 ? 00:00:00 init [5]
root 2670 1 0 May18 ? 00:00:00 auditd
root 2929 1 0 May18 ? 00:00:00 automount
avahi 3400 1 0 May18 ? 00:00:00 avahi-daemon: running [vcsnode1.local]
root 3835 1 0 May18 ? 00:00:00 /bin/dbus-daemon –fork –print-pid 4 –print-address 6 –session
root 1990 1 0 May18 ? 00:00:00 /bin/sh – /usr/lib/vxvm/bin/vxconfigbackupd
root 1988 1 0 May18 ? 00:00:00 /bin/sh – /usr/lib/vxvm/bin/vxrelocd root
root 3281 1 0 May18 ? 00:00:00 crond
root 3034 1 0 May18 ? 00:00:00 cupsd
dbus 2812 1 0 May18 ? 00:00:00 dbus-daemon –system
[root@vcsnode1 ~]#
The current version of POSIX can be checked by executing the following command
[root@vcsnode1 ~]# getconf -a | grep ^POSIX2_VERSION
POSIX2_VERSION 200112
[root@vcsnode1 ~]#
For any reason, if you still want to use the old syntax of sort command, there is a work around available.
If you set the “_POSIX2_VERSION:” environment variable to older POSIX Version value, you can still execute the sort command by providing switch as +2.
[root@vcsnode1 ~]# ps -ef | sort +2
sort: open failed: +2: No such file or directory
[root@vcsnode1 ~]# export _POSIX2_VERSION=199209
[root@vcsnode1 ~]# ps -ef | sort +2 | head
root 1 0 0 May18 ? 00:00:00 init [5]
root 2670 1 0 May18 ? 00:00:00 auditd
root 2929 1 0 May18 ? 00:00:00 automount
avahi 3400 1 0 May18 ? 00:00:00 avahi-daemon: running [vcsnode1.local]
root 3835 1 0 May18 ? 00:00:00 /bin/dbus-daemon –fork –print-pid 4 –print-address 6 –session
root 1990 1 0 May18 ? 00:00:00 /bin/sh – /usr/lib/vxvm/bin/vxconfigbackupd
root 1988 1 0 May18 ? 00:00:00 /bin/sh – /usr/lib/vxvm/bin/vxrelocd root
root 3281 1 0 May18 ? 00:00:00 crond
root 3034 1 0 May18 ? 00:00:00 cupsd
dbus 2812 1 0 May18 ? 00:00:00 dbus-daemon –system
[root@vcsnode1 ~]#

0 comments:

Post a Comment