Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to get vsftpd version into shell variable. I can get it to console with ease:

# vsftpd -version
vsftpd: version 2.2.2

Also I can get a lot of other info into variable:

# i=`bash --version 2>&1 | head -n1`; echo "=$i=";
=GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)=

(please note output is between "=" signs). This simple way does not work with vsftpd:

# i=`vsftpd -version 2>&1`; echo "=$i=";
vsftpd: version 2.2.2
==

Please note $i is "" here.

What am I doing wrong?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Interestingly enough, my vsftpd writes the versino string to stdin. So you probably need to do a rather unusual redirection of stdin to stdout:

i=`/usr/sbin/vsftpd -version 0>&1`

How to find this out: run it in strace (you'll need to do it as root) and check for the string. In my case the log ends like this:

$ strace /usr/sbin/vsftpd -version
...
brk(0)                                  = 0x7f835332d000
brk(0x7f835334e000)                     = 0x7f835334e000
write(0, "vsftpd: version 3.0.2\n", 22) = 22
exit_group(0)                           = ?
+++ exited with 0 +++

The first argument to write() is the file descriptor (0/1/2 stand for stdin/stdout/stderr respectively).

share|improve this answer
add comment

The command vsftpd -v uses stdin so you can't grab the output in the normal way.

I usually just grab the response from the FTP port. I only allow FTP locally anyway.

echo "bye" | nc localhost 21

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.