What you seem to be trying to do is version control and maintain a history. In general system administration staff don't want to be prompted and want the script to take care of everything. In this case, it could figure out a reference number like
date +%j%m%d%s
. Your method of putting comments in from of changed stanzas will make the file grow. I would simply have a script that would make a backup of the file with a predetermined reference, number, then call of the vi editor to edit the file. The script could be smart enough to recognize if the file actually changed.
ok.. Thanks for your swift responce.. Let me tell you what i am trying to do here..
i am trying to edit "sysctl.conf" file.. if this file has got below variables with below values or morethan that then it should leave that value...
If variable value is less than that then it should alter the value to below given value
For example:
sysctl.conf file has below values
kernel.shmall = 5194304 (more than 4194304 so it should leave it as it is)
kernel.shmmax = 2147483648 (it is equal to 2147483648 so it should leave it as it is)
kernel.msgmni = 124 (it is less than 1024 so it should alter the value to 1024)
I have tried below code and it is working but it is failing where there is no "kernel.shmall" parameter in file /etc/sysctl.conf
if grep -o "kernel.shmall" /etc/sysctl.conf > /dev/null
then
oldvalue=$(grep -v '^#' /etc/sysctl.conf|grep kernel.shmall|sed 's/=/ /g'| awk '{ print $2}')
if [ $oldvalue -lt 4194304 ]
then
sed -i "s|\("kernel.shmall" *= *\).*|\14194304|" /etc/sysctl.conf
fi
else
echo "kernel.shmall=" >> /etc/sysctl.conf
sed -i "s|\("kernel.shmall" *= *\).*|\14194304|" /etc/sysctl.conf
fi
is there any modifications do i need to do in script to add "kernel.shmall=4194304" value to file sysctl.conf where there is no parameter kernel.shmall