Sign up ×
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 am creating a bash script that installed VSFTPD / FTP. After the installation some configuration is required in the "/etc/vsftpd/vsftpd.conf" file.

This includes making sure the following lines are set to this:

anonymous_enable=NO
local_enable=YES
chroot_local_user=YES

What would be the best approach for scripting a way for these edits to be made post installation?

share|improve this question
    
I would go with sed –  Arkadiusz Drabczyk Nov 24 '14 at 16:04
    
Are those lines (with the same or different values) already in the default conf? That is, what are you changing from and to? –  jasonwryan Nov 24 '14 at 16:26
    
It can vary but that is the end result I need to get to. –  user3024130 Nov 24 '14 at 16:31
    
Note that not all versions of sed support sed -c, with gnu sed 4.2.2 I'm getting sed: invalid option -- 'c'. Also, if those keys are commented in the original file (or missing) the sed solution below will not give you the end result that you actually need. –  don_crissti Nov 24 '14 at 23:31

1 Answer 1

up vote 1 down vote accepted

I would use sed it's really powerfull, this bash file would change the values:

  #!/bin/bash

  path_to_conf="/path/to/vsftpd.conf"
  anonymous_=NEIN
  local_=JA
  chroot_=IDK

  sed -c -i "s/\("anonymous_enable" *= *\).*/\1$anonymous_/" $path_to_conf
  sed -c -i "s/\("local_enable" *= *\).*/\1$local_/" $path_to_conf
  sed -c -i "s/\("chroot_local_user" *= *\).*/\1$chroot_/" $path_to_conf

You could use a loop to get this done, if you have to change a lot of variables, but with only three keys it's nicer like this (in my opinion).

share|improve this answer

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.