I have a large setup program that saves hours and hours when I spin up a new machine, but I cannot get one thing to work right now. I want to fill a TD driver required config file, and since it is a special protected file I'm getting a hassle. My python looks like:
#configure webapi driver
ODBC_PATH = os.path.join(HOMEPATH, '/etc/odbcinst.ini')
ODBC_SETTINGS = """\
[FreeTDS]
Description = TD Driver (MSSQL)
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
FileUsage = 1"""
call_sp('sudo echo "{}" > {}'.format(ODBC_SETTINGS, ODBC_PATH))
where call_sp
is just my way of calling a subprocess but allowing args, like Popen does. I was clueless, because it's failing silently (I don't know till I try to run server) and in the shell I don't get prompted for my pw:
cchilders:~/scripts/setup_scripts/dimensional [master]$ sudo echo "[FreeTDS]
Description = TD Driver (MSSQL)
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
FileUsage = 1" > /etc/odbcinst.ini
bash: /etc/odbcinst.ini: Permission denied
cchilders:~/scripts/setup_scripts [master]$ sudo echo "somethin" > /etc/odbcinst.ini
bash: /etc/odbcinst.ini: Permission denied
but sudoing into nano works and I can do it manually:
cchilders:~/scripts/setup_scripts [master]$ sudo nano /etc/odbcinst.ini
[sudo] password for cchilders:
Why can't I fill this ini file with text from terminal, and if it isn't possible, how can I automatically fill in python script? Ty