According to the condition of the script, it should not add to each line \n, but when it is executed, all the text is in spaces and parted
import sys
import fileinput
nameuser = "users1"
psuser = "pass1"
file_name = '/usr/local/etc/3proxy.cfg'
for line in fileinput.FileInput(file_name,inplace=1):
if 'auth strong' in line:
line = line.replace(line, line+'########################################################################## '+ nameuser +' ##########################################################################'+'\r' + 'users '+ nameuser +':CL:'+ psuser +'\r'+ 'allow login,'+ nameuser +'\r''flush')
print (line)
unformatted file:
daemon
nserver 11111
nserver 22222
nscache 65536
timeouts 1 5 30 60 180 1800 15 60
log /var/log/3proxy/log D
logformat "- +_L%t.%. %N.%p %E %U %C:%c %R:%r %O %I %h %T"
logformat "L%t.%. %N.%p %E %U %C:%c %R:%r %Q:%q %O %I %h %T %n "
rotate 360
#external 0.0.0.0
#internal 0.0.0.0
auth strong
deny *
maxconn 254
setgid 65534
setuid 65534
Each script run adds "\n" to all lines. file format after script
daemon
nserver 11111
nserver 22222
nscache 65536
timeouts 1 5 30 60 180 1800 15 60
log /var/log/3proxy/log D
logformat "- +_L%t.%. %N.%p %E %U %C:%c %R:%r %O %I %h %T"
logformat "L%t.%. %N.%p %E %U %C:%c %R:%r %Q:%q %O %I %h %T %n "
rotate 360
#external 0.0.0.0
#internal 0.0.0.0
auth strong
deny *
maxconn 254
setgid 6553
setuid 65534
I added different fragments "\r", "\n", "\r\n" , but nothing happened