HI ALL
I am making a script,That will does the following,I am in search of ideas
1.Script will comment all existing the entries in resolve.conf
2.Add new entries like this
abc.example.com
192.168.1.x
I can use sed to add comment.
HI ALL
I am making a script,That will does the following,I am in search of ideas
1.Script will comment all existing the entries in resolve.conf
2.Add new entries like this
abc.example.com
192.168.1.x
I can use sed to add comment.
How do you make sure another process (such as the DHCP client) does not try to modify the script while you're writing it?
Wouldn't it make better sense to write a new file all-at-once?
NO dchp is not running that's my server,i have many server so i need to make a script which run and check each reslove.conf and put specfic dns enties in each server reslove.conf.the value i gave you are fectious.
HI Again
I have made the script,In its initial stage,Need to ask one question i am taking backup of reslov.conf with this name reslov.conf~ but a problem is that when next time script run it will over write the backup file with new value.see my code you will get what i m saying ,Please ans this ASAP,its urgent.THX TO ALL
#!/bin/bash
sudo sed -i~ 's?^?#?' /home/syed/shellscript/resolv.conf
echo search.example.com >> resolv.conf
echo nameserver xxx.xxx.x.x >> resolv.conf
echo nameserver xxx.xxx.x.x >> resolv.conf
cat /home/syed/shellscript/resolv.conf
I think you are going about it the wrong way.
RESOLV=/home/syed/shellscript/resolv.conf
exec <$RESOLV >$RESOLV.new
while read line ; do
echo "# $line"
done
echo search.example.com
echo nameserver xxx.xxx.xxxx.xxxx
echo nameserver yyy.yyy.yyyy.yyyy
exec >-
mv $RESOLV $RESOLV.$$.bak
mv $RESOLV.new $RESOLV
above line should be -> exec <$RESOLV >$RESOLV.new
Thanks,
bash
Not working see below
#! /bin/bash
RESOLV=/tmp/reslov.conf
exec < $RESOLV >$RESOLV.new
while read line ; do
echo "# $line"
done
echo search.example.com
echo nameserver xxx.xxx.xxxx.xxxx
echo nameserver yyy.yyy.yyyy.yyyy
exec >-
mv $RESOLV $RESOLV.$$.bak
mv $RESOLV.new $RESOLV
tmp]$ ./resolv.sh2
./resolv.sh2: line 3: /tmp/reslov.conf: No such file or directory
^C
You are blind, waste alot time on small matter.
Thanks,
bash
You have to have the original resolv.conf in place first.