Subscribe
Accepted Solution

Function / command to append data to config files (rc, hosts...)?

Hi guys.

are you aware of / used before a function or command to append new data to configuration files (i.e like /etc/usermap.cfg and /etc/passwd) in WFA?

Thanks in advance,

Solal.

Re: Function / command to append data to config files (rc, hosts...)?

Hi Solal,

     Can you elaborate on what you are trying to do and why you need this ? This may help understand the need better and propose other solutions as well.

Regards

adai

Re: Function / command to append data to config files (rc, hosts...)?

I wrote a command to add an SSH publickey to a 7 Mode storage system, and I used API calls that just append to a file to get this done:

https://communities.netapp.com/docs/DOC-29903

You could copy the above command and modify it to meet your needs.  Hope that helps,

Mike

Re: Function / command to append data to config files (rc, hosts...)?

Thanks guys.

I got another example from Anatoly that really helped as well:

You can use ONTAP toolkit cmdlets Read-NcDirectory, Read-NcFile, Write-NcFile inside the command in WFA in order to do it

Example:

# connect to controller

Get-WFALogger -Info -message $("Connecting to " + $Cluster)

Connect-WfaCluster $Cluster

Read-NcDirectory -Path /vol/vs1_root/.vsadmin/config/etc -VserverContext vs1

Read-NcFile -Path /vol/vs1_root/.vsadmin/config/etc/master.passwd -VserverContext vs1

$data = "nobody2:*:65535:65535::::::"

Write-NcFile -Path /vol/vs1_root/.vsadmin/config/etc/master.passwd -Data $data -Append -VserverContext vs1

Re: Function / command to append data to config files (rc, hosts...)?

Thanks for sharing Solal. Very useful information.

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Re: Function / command to append data to config files (rc, hosts...)?

That's my final one that works in a workflow:

param (

  [parameter(Mandatory=$true, HelpMessage="Array name or IP address")]

  [string]$Array,

  [parameter(Mandatory=$true, HelpMessage="Full path to filer or vfiler requested file, example: hosts")]

  [string]$FilePath,

  [parameter(Mandatory=$true, HelpMessage="New Line to enter to the configuration file. One line at a time.")]

  [string]$LineEntered

)

# connect to controller

Connect-WfaController -Array $Array

$rootvol=Get-NaVolRoot

$fullpath="/vol/" + $rootvol.Name + "/etc/" + $FilePath

# Write the line to the file.

Write-NaFile -Path $fullpath -Append -Data $("`n" + "$LineEntered" + "`n")

   # End of Command

Re: Function / command to append data to config files (rc, hosts...)?

Hi Solal,

 

 

I am not able to append data in configuration files like as /etc/rc, /etc/hosts, /etc/exports...etc,    i am trying to go through your attachment but it is not opening .

 

So please tell me how can i append data in files.

 

Is there any command for copying and creating files and directories like as cp and mkdir?

 

 

Regards

 

Vinod