0

Is it possible to add the following lines to multipath.conf through echo or anyother alternative command?

##ORA_FRA_IRD01P3 1x100GB multipath { wwid 350002ac006450f58 alias ORA_FRA_IRD01P3 }

There is a closed brace '}' at the end of the file. The above mentioned lines have to be pasted just above the closed brace '}' in the multipath.conf file.

Thanks,

1 Answers1

0

Here you go:

tac multipath.conf | sed 's/}/}\n##ORA_FRA_IRD01P3 1x100GB multipath { wwid 350002ac006450f58 alias ORA_FRA_IRD01P3 }/ ; ta ; b ; :a ; N ; ba' | tac > multipath.conf.tmp && mv -f multipath.conf.tmp multipath.conf

Example:

[root@joeyoung.io stackoverflow]# cat multipath.conf
{
        {
                line1
                line2
                line3
                line4
        }
}
[root@joeyoung.io stackoverflow]# tac multipath.conf | sed 's/}/}\n##ORA_FRA_IRD01P3 1x100GB multipath { wwid 350002ac006450f58 alias ORA_FRA_IRD01P3 }/ ; ta ; b ; :a ; N ; ba' | tac > multipath.conf.tmp && mv -f multipath.conf.tmp multipath.conf
[root@joeyoung.io stackoverflow]# cat multipath.conf
{
        {
                line1
                line2
                line3
                line4
        }
##ORA_FRA_IRD01P3 1x100GB multipath { wwid 350002ac006450f58 alias ORA_FRA_IRD01P3 }
}

Explanation

tac prints out the file in reverse order line by line starting from the last line of the file.

sed 's/}/}\n##ORA_FRA_IRD01P3 1x100GB multipath { wwid 350002ac006450f58 alias ORA_FRA_IRD01P3 }/ takes the first instance of } (which happens to the last instance of } in the file because tac prints the last line first) and replaces it with another }, followed by a newline, followed by the line of text that you wanted to insert into the file.

This stackoverflow answer explains the ; ta ; b ; :a ; N ; ba'.

The output of the sed call is piped back through tac to put it back in the original order.

The output of the last tac called is written out to a temporary file because we can't overwrite the original version of the file just yet.

Double ampersand (&&) means that if the first command was successful, continue on with the next command.

Finally we forcefully rename the temporary file to multipath.conf with the mv -f command, thus overwriting the original contents.

Community
  • 1
  • 1
Joe Young
  • 5,749
  • 3
  • 28
  • 27