 |
 |
Script to "edit" a file? How difficult?
|
 |
|
 |
|
Mac Enthusiast
Join Date: Mar 1999
Location: Portland, Oregon, United States
Status:
Offline
|
|
The IT department at my work doesn't know alot about Macs and asked me to determine if this is possible. We have ARD and so have an admin account on all of the machines. Employees are always turning on Windows file sharing to connect to the PCs on the floor, but due to a setting in the smb.conf file the Macs take over as "browse master" (I really don't know what that means) and the fix is to change the line "os level = 8" to "os level = 1" in the /etc/smb.conf file.
I know how to add a line to the end of a file with the >> redirection, and I know that something like vi can probably be used to do a find/replace, but really I have no idea about how to do this and want to be as accurate as possible as the ones doing this aren't going to be able to know if the information is correct or not.
Is this a simple change or not?
Thanks!
Laurence
|
|
--Laurence
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Jun 2005
Status:
Offline
|
|
It's not too tough. Have a look at sed. 'man sed' in a terminal window should get you enough information to get the syntax. There's probably more graceful ways to do this......
sed 's/os level = 8/os level = 1/' < /tmp/foo > /tmp/foo1
The input file is /tmp/foo and the output is /tmp/foo1. The command will change the first instance of 'os level = 8' in EACH line in the file to 'os level = 1.' If there is only one instance of that string in each file then a script like...
mv /etc/smb.conf /etc/smb.conf.orig
sed 's/os level = 8/os level = 1/' < /etc/smb.conf.orig > /etc/smb.conf
should work. Otherwise the script should be more involved with respect to finding the exact line you want to change. Not that familiar with Samba start and stop scripts, but you can add the stop and start commands to the script as well.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status:
Offline
|
|
Why bother with that when there's only one instance of that line in there according to [font=Courier New]grep[/font], and the file is only 55 lines long (on my machine, anyway)? Just edit the file normally with [font=Courier New]pico[/font]:
Code:
sudo pico /etc/smb.conf
The pico commands are shown at the bottom of the Terminal window while you're using it.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Jun 2005
Status:
Offline
|
|
Originally Posted by wataru
Why bother with that when there's only one instance of that line in there according to [font=Courier New]grep[/font], and the file is only 55 lines long (on my machine, anyway)? Just edit the file normally with [font=Courier New]pico[/font]:
Code:
sudo pico /etc/smb.conf
The pico commands are shown at the bottom of the Terminal window while you're using it.
Many machines and not too familiar with ediors was what I saw. Script it up once then run the script. Less room for human error. Whatever route you take, make a copy of the config file first then make the changes. It's much easier to back out a mistake when you have a copy of the original file.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
As whgoodman said, sed is typically considered the standard way of editing files through shell scripts in Unix and OSX. One thing that you need to be careful about, though, is that sed can't directly write its changes back to the file it opened, because of the way it works. You need to write the changes out to a second file, and then copy it over the original file if you actually want to use the changes right away. You could also copy to a second file, rename the old file to keep it as a backup, and then rename the new file to replace the old one.
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Moderator 
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status:
Offline
|
|
I have to say that patch and diff look like the obvious way to go to me... Make a copy of the original file, modify it the way you want it, use diff to find the difference and then use patch to apply it to the live settings file.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status:
Offline
|
|
Yet Another Option:
sudo perl -i.bak -p -e 's/^(os level =) \d/$1 1/' /etc/smb.conf
No scripting task is complete until it's been implemented as a perl one-liner.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|