1

I'm trying to write an install script and i need to change the sendmail line in php.ini

but I want to do this automatically

at the moment I'm doing this manually:

  • sudo nano /etc/php5/apache2/php.ini
  • finding the line containing sendmail_path =
  • then editing it to be
  • sendmail_path = /usr/bin/msmtp -t

then saving the file.

Is it possible to just auto script this to make the change?

Thanks a lot

1
  • The better solution might be using something like augeas.
    – Zoredache
    Nov 9, 2013 at 19:47

1 Answer 1

2

Use sed:

sed -e '/^[^;]*sendmail_path/s/=.*$/= \/usr\/bin\/msmtp -t/' -i.bak /etc/php5/apache2/php.ini

or

sudo sed -e '/^[^;]*sendmail_path/s/=.*$/= \/usr\/bin\/msmtp -t/' -i.bak /etc/php5/apache2/php.ini

This is a work by word translation of your request to sed commands:

  • open the file /etc/php5/apache2/php.ini
  • find the line containing sendmail_path (whithout havin char ; before)
  • replace from the sign = to end of line by = /usr/bin/msmtp -t

Warning -i mean inplace modification. Using this will modify your php.ini (and create a php.ini.bak)

For trying only, don't use -i switch:

sed -e '/^[^;]*sendmail_path/s/=.*$/= \/usr\/bin\/msmtp -t/' /etc/php5/apache2/php.ini
4
  • thanks that's great, but do you know how i also uncomment the sendmail_path line in that command? the actual line i edit is ;sendmail_path= ... and i want it sendmail_path (without the ;) Nov 9, 2013 at 16:25
  • I've tried this command: sudo sed 's/;sendmail_path = /sendmail_path = \/usr\/bin\/msmtp -t/' /etc/php5/apache2/php.ini and it doesn't seem to update anything. I've also tried your command and it doesnt update. Nov 9, 2013 at 16:35
  • also, this doesn't work or seem to do anything: sudo sed -i 's/;sendmail_path/blahblah/' /etc/php5/apache2/php.ini i think something is wrong :( Nov 9, 2013 at 16:47
  • Ok this seems to work: sudo sed -i 's/;sendmail_path\s=.*/sendmail_path = \/usr\/bin\/msmtp -t/' /etc/php5/apache2/php.ini thanks for your help Nov 9, 2013 at 16:53

Not the answer you're looking for? Browse other questions tagged .