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

closed as off-topic by Dennis Kaarsemaker, mdpc, colealtdelete, Nathan C, kce Nov 14 '13 at 17:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance." – Dennis Kaarsemaker, mdpc, colealtdelete, kce
If this question can be reworded to fit the rules in the help center, please edit the question.

  • The better solution might be using something like augeas. – Zoredache Nov 9 '13 at 19:47
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
  • 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 ;) – TheStoneFox Nov 9 '13 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. – TheStoneFox Nov 9 '13 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 :( – TheStoneFox Nov 9 '13 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 – TheStoneFox Nov 9 '13 at 16:53

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