[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#18118: postgresql: postgresql modifies /etc/crontab rather than adding file



Philip Hands wrote:
  >> Kevin Dalley wrote, referring to Bug#18118:
  >>   >It would be nice if postgresql upgrade would remove the lines from
  >>   >/etc/crontab which were added by previous version of postgresql.
  >> 
  >> For a while, it did.  Nevertheless, it is a violation of policy to 
  >> modify /etc/crontab, which is why I have taken it out.
  >> 
  >> Should I reinstate the removal?  It would add these lines to postinst:
  >>...
  >sed seems like a simpler way of doing this than awk:

Ah well, in Unix there's always more than one way to do it; I like awk!

I can also think of a way to do it with a mixture of grep, cut, head and tail!
How about a Perl contribution, anyone?  We could put the whole lot into a
little note on inventive ways to use basic commands.

  >
  >  sed -e '/^#-- postgresql begin /,/^#--  postgresql end /d'  \
  >    /etc/crontab > $TMP

I hadn't thought of this way of using sed to deal with a block; I
presume that the patterns make the command equivalent to (say) 10,12d

  >BTW Is it worth worrying about broken files ?  Either method will delete
  >to the end of the file if the end comment is missing -- does this matter ?
 
I'd prefer not to risk breaking anything; so, with awk:

   if grep -qs '^#-- postgresql begin *$' /etc/crontab
   then
	TMP=`mktemp /tmp/pg.XXXXXX` || exit 1
	awk 'BEGIN {found=0}
   /^#-- postgresql begin *$/ {found = 1}
   /^#-- postgresql end *$/ {found = -1}
	{if (!found) print}
	{if (found == -1) found=0}
	END {if (found) exit 1}' /etc/crontab >$TMP &&
		if [ -f $TMP ]
		then
			mv $TMP /etc/crontab
		fi
   fi

This will not delete anything unless the whole block is found.

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver

PGP key from public servers; key ID 32B8FAA1



--
To UNSUBSCRIBE, email to debian-policy-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org


Reply to: