Sunday, August 29, 2010

Execute command from a file on Ontap

Occasionally we want to quickly or periodically run a set of pre defined commands on filers, like when we are making little change in network configuration and want to minimize the network down time or when we are creating a volume and know snap reserve, snap schedule, de-dupe, autosize or anything else which needs to be changed after every volume creation. If you are executing commands from unix terminal then a better way would be to keep all the commands in a text file and would do something like

bash>for $i in vol1
>do
>snap sched $i 0
>snap reserve $i 0
>blah $i
>blah $i
>done

and everything would be done, but imagine how would you do if you are doing through console. Unfortunately Ontap doesn't supports any kind of script not even for loop so we have to run each and every line of command either by typing on console or doing a copy-paste from text file from our desktop.

However there is a better way, use notepad to create set of command as you would execute on console with correct order, copy it off to filer and use 'source' command to execute each and every line from it. I know it's not such a brilliant idea as still you have to copy and paste everything to a file on filer however it's wee better than executing each and every command on console.

Think about you have to re-run /etc/rc so either you can use 'rdfile /etc/rc' to print everything on console and copy all the the line and execute on console or just run 'source /etc/rc' and let it run all the commands for you. You can also use 'source -v /etc/rc' to print the commands on console but not to execute, just to get an idea if there are any junk characters or any unwanted command inside the file, just as a precaution you better be sure that all the commands are valid and correct as if a command fails source doesn't stops there and just goes to next command in list.

Use it and I am sure you will like it next time when you are making some changes on filer which needs ten different commands to be executed.

2 comments:

Mickey Baker said...

This isn't quite right. ONTAP will gleefully execute ssh/rsh commands from trusted, authenticated hosts!

rsh/ssh command scripts are supported - you simply need to take a few minutes to learn how to pass your parameters to rsh commands. It really isn't difficult and so much more secure than putting potentially dangerous commands (like the one you use for illustration) on the filer.

Good luck, write for examples or check out communities.netapp.com

Alternatively, you can simply map the administrative shares from the filer on your

Unknown said...

Hi Mickey,

You are absolutely right about remotely running rsh/ssh commands but what difference it brings, think for a moment that you are in situation where you can't reach to a host, let it be network down or something else now what would you do? I never said that you should run a series of commands using 'source' what I want to say is you have one more way also to run series of commands if you are out of all other ways.

My example given here may be incorrect if not dangerous and I never said that for creating a volume you should do that way, you can use DFM/filer view/system manager or something else also.

Main content for this post is the command 'source' and not the example, now how you interpet that example is down to you.

Anyway thanks for sharing your views.

Cheers,
Mohit