CLI File Editing with NetApp Data ONTAP 7-Mode

Let me preface this by saying that it’s really not an expectation that you should, or even that you’re going to be, reading or modifying files from the storage array’s CLI. Files are meant to be accessed using a (surprise, surprise) file access protocol, such as NFS or SMB/CIFS, directly from a client. Having said that, it can be useful to use the CLI to modify system files such as /etc/rc or /etc/hosts, particularly during initial setup or maintenance activities, and I’ve done it myself hundreds if not thousands of times.

The biggest hurdle to overcome in CLI file editing is that there isn’t a real editor included in the shell. Nope – no vi or Vim, no emacs, nano, or any other editor you may expect or like. There isn’t even ed! Instead, file access and editing is done using rdfile to “read” or display the contents of a file, and wrfile to “write” the contents of a file. Rdfile is pretty straightforward – it’s essentially just a cat equivalent that takes a file and sends it to standard output (your screen).

mba-7m-1> rdfile /etc/hosts
#Auto-generated by setup Mon Nov 3 21:54:55 GMT 2014
127.0.0.1 localhost localhost-stack
127.0.10.1 localhost-10 localhost-bsd
127.0.20.1 localhost-20 localhost-sk
172.16.213.18 mba-7m-1 mba-7m-1-e0a

And no, before you ask: there is no included equivalent of more or less (for paging of output), nor anything like tail or head. More’s the pity.

Wrfile, on the other hand, is a little different and less friendly. It does the exact opposite of rdfile – it takes standard input (the keystrokes/characters you type into the console/shell) and sends (writes) it to a file. This makes it very easy to create a file – as long as you don’t make any typos! There is no interactive line editing with wrfile – if you make a mistake you’re essentially starting over. Your best course of action is to create your text locally on your workstation with your tool (Vim, notepad++, etc.) of choice, and then paste it into your terminal window.

After you’ve finished entering the desired content, make sure to hit Enter to be on a new line and then simply use Ctrl+c to end the input and terminate wrfile. If you aren’t on a new line, any text already entered on that line will not be saved. Don’t mind the “error reading standard input” – that’s normal.

mba-7m-1> wrfile /etc/thisisonlyatest
blah blah blah
line 2 blah blah blah
read: error reading standard input: Interrupted system call
mba-7m-1> rdfile /etc/thisisonlyatest
blah blah blah
line 2 blah blah blah

You need to be especially careful using wrfile to edit an existing file: it will overwrite the contents of the file you specify as soon as you hit Enter. Even if you don’t type anything and immediately Ctrl+c out, the damage is done and your file is now empty. For this reason, always be sure to rdfile the file prior to making any modifications to it so that you have a copy in your cache. In most cases, you’ll want to copy the contents printed out via rdfile to a local texteditor for modification; you’ll then copy the modified content and paste into the console window after starting the wrfile operation.

mba-7m-1> wrfile /etc/thisisonlyatest
read: error reading standard input: Interrupted system call
mba-7m-1> rdfile /etc/thisisonlyatest
mba-7m-1>

If all you need to do is to add a line (or lines) to a file, it’s best to use the “-a” parameter for wrfile in order to append to the existing file rather than overwriting it. This also works for creating a new file.

mba-7m-1> rdfile /etc/thisisonlyatest
/etc/thisisonlyatest: No such file or directory
mba-7m-1> wrfile -a /etc/thisisonlyatest Line1 foo
mba-7m-1> wrfile -a /etc/thisisonlyatest Line2 bar
mba-7m-1> rdfile /etc/thisisonlyatest
Line1 foo
Line2 bar

File editing via the Data ONTAP CLI is not a normal operation, it’s not very elegant (ok, it’s crude), and it’s really only intended for atypical administrative use-cases – but it gets the job done when you need it. Otherwise, follow the recommended method for modifying files by using a licensed file access protocol (NFS or SMB/CIFS) and edit from a remote client instead.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s