I would like to use TCL/TK to create a GUI that I can use to change the Hostname, IP Address, and MAC address of a Linux based system. Does anyone have any code to share that would help me do this?
Are you asking me how to accomplish this in BASH or are you being sarcastic?
While it is possible to use BASH to do this, and I do have a script that calls SED and makes the change, I need this to run in a TK widget. I need the output directed into the widget after an .entry box is used to get the new address.
No, I wasn't being sarcastic (maybe assuming Bash was wrong). I don't know how to do the UNIX function you want (which files to change, what changes to make in them), if you told me that, I'm sure I could tell you a way to do it in Tcl.
Thanks for the reply. I have a BASH script that will use SED to change the IP address of a host system by editing the /etc/sysconfig/networking/devices/ifcfg-eth0 file. The script merely removes the IPADDR='xx.xx.xx.xx' line and replaces it with whatever the user has input.
So really, I guess I am looking for a method in TCL/TK of substituting one line in a text file for another. I read a little on regexp and regsub, but I am unsure how to approach this. A small coding sample would go a long way in this instance.
Okay. I think I can suggest something that might help. I would read in the whole file make a change, then write it out again, as follows.
Let's say the file name is "/a/b/c/abc.log"
set fid [open /a/b/c/abc.log r]
set linelist [split [read $fid] \n]
close $fid
#each line is an element of the list
#now search through the list for the trigger text
#and make the change
foreach line $linelist {
if {[string range $line 0 5]=="IPADDR"} {
set newstring "IPADDR=aaa.bbb.ccc.ddd"
} elseif {<more cases as needed>} {
} else {
set newstring $line
}
lappend newlist $line
}
set fid [open /a/b/c/abc.log w];# write it out new
foreach line $newlist {puts $fid $line}
close $fid
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.