linux - Edit a configuration file w/o temp files -
i'm trying write simple script add configuration @ top of of file, , that's how this:
#! /bin/bash sudo apt-get install monit # below code i'm interesting change echo ' set eventqueue basedir /etc/monit/eventqueue/ slots 1000 set mmonit http://monit:monit@xxx.xxx.xxx.xxx:8080/collector set httpd port 2812 , use address ec2-xxx.xxx.xx.xx.com allow localhost allow 0.0.0.0/0.0.0.0 allow admin:swordfish ' | sudo tee -a /etc/monit/monitrc_tmp sudo cat /etc/monit/monitrc >> /etc/monit/monitrc_tmp sudo rm /etc/monit/monitrc sudo mv /etc/monit/monitrc_tmp /etc/monit/monitrc # point sudo sed -i 's/set daemon 120/set daemon 20/' /etc/monit/monitrc exit 0
as can see 'm trying add configuration @ top of file. , want know there flag
or command
me without creating tmp
file.
looks case sed -i
since you're on linux. also, since system administration work, preserve backup.
sudo sed -i.bak -e '1i\ set eventqueue basedir /etc/monit/eventqueue/ slots 1000\ set mmonit http://monit:monit@xxx.xxx.xxx.xxx:8080/collector\ set httpd port 2812 , use address ec2-xxx.xxx.xx.xx.com\ allow localhost\ allow 0.0.0.0/0.0.0.0\ allow admin:swordfish ' /etc/monit/monitrc
this says 'insert following lines before line 1'...and lines continue , including 1 without backslash @ end.
you can edit of set daemon
line too, though said out-of-scope:
sudo sed -i.bak -e '1i\ set eventqueue basedir /etc/monit/eventqueue/ slots 1000\ set mmonit http://monit:monit@xxx.xxx.xxx.xxx:8080/collector\ set httpd port 2812 , use address ec2-xxx.xxx.xx.xx.com\ allow localhost\ allow 0.0.0.0/0.0.0.0\ allow admin:swordfish s/set daemon 120/set daemon 20/ ' /etc/monit/monitrc
Comments
Post a Comment