Skip to content

Commit e093067

Browse files
authored
Merge pull request #108116 from lanicolas/patch-52
Align bash style guide
2 parents 98ad5ec + 243ea7f commit e093067

File tree

1 file changed

+70
-70
lines changed

1 file changed

+70
-70
lines changed

articles/storage/files/storage-how-to-use-files-linux.md

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,18 @@ On other distributions, use the appropriate package manager or [compile from sou
8484
* **Ensure port 445 is open**: SMB communicates over TCP port 445 - make sure your firewall or ISP isn't blocking TCP port 445 from the client machine. Replace `<your-resource-group>` and `<your-storage-account>` and then run the following script:
8585

8686
```bash
87-
resourceGroupName="<your-resource-group>"
88-
storageAccountName="<your-storage-account>"
87+
RESOURCE_GROUP_NAME="<your-resource-group>"
88+
STORAGE_ACCOUNT_NAME="<your-storage-account>"
8989

9090
# This command assumes you have logged in with az login
91-
httpEndpoint=$(az storage account show \
92-
--resource-group $resourceGroupName \
93-
--name $storageAccountName \
91+
HTTP_ENDPOINT=$(az storage account show \
92+
--resource-group $RESOURCE_GROUP_NAME \
93+
--name $STORAGE_ACCOUNT_NAME \
9494
--query "primaryEndpoints.file" --output tsv | tr -d '"')
95-
smbPath=$(echo $httpEndpoint | cut -c7-${#httpEndpoint})
96-
fileHost=$(echo $smbPath | tr -d "/")
95+
SMBPATH=$(echo $HTTP_ENDPOINT | cut -c7-${#HTTP_ENDPOINT})
96+
FILE_HOST=$(echo $-- | tr -d "/")
9797

98-
nc -zvw3 $fileHost 445
98+
nc -zvw3 $FILE_HOST 445
9999
```
100100

101101
If the connection was successful, you should see something similar to the following output:
@@ -107,75 +107,75 @@ On other distributions, use the appropriate package manager or [compile from sou
107107
If you're unable to open up port 445 on your corporate network or are blocked from doing so by an ISP, you may use a VPN connection or ExpressRoute to work around port 445. For more information, see [Networking considerations for direct Azure file share access](storage-files-networking-overview.md).
108108
109109
## Mount the Azure file share on-demand with mount
110-
When you mount a file share on a Linux OS, your remote file share is represented as a folder in your local file system. You can mount file shares to anywhere on your system. The following example mounts under the `/mount` path. You can change this to your preferred path you want by modifying the `$mntRoot` variable.
110+
When you mount a file share on a Linux OS, your remote file share is represented as a folder in your local file system. You can mount file shares to anywhere on your system. The following example mounts under the `/mount` path. You can change this to your preferred path you want by modifying the `$MNT_ROOT` variable.
111111
112112
Replace `<resource-group-name>`, `<storage-account-name>`, and `<file-share-name>` with the appropriate information for your environment:
113113
114114
```bash
115-
resourceGroupName="<resource-group-name>"
116-
storageAccountName="<storage-account-name>"
117-
fileShareName="<file-share-name>"
115+
RESOURCE_GROUP_NAME="<resource-group-name>"
116+
STORAGE_ACCOUNT_NAME="<storage-account-name>"
117+
FILE_SHARE_NAME="<file-share-name>"
118118
119-
mntRoot="/mount"
120-
mntPath="$mntRoot/$storageAccountName/$fileShareName"
119+
MNT_ROOT="/mount"
120+
MNT_PATH="$MNT_ROOT/$STORAGE_ACCOUNT_NAME/$FILE_SHARE_NAME"
121121
122-
sudo mkdir -p $mntPath
122+
sudo mkdir -p $MNT_PATH
123123
```
124124
125-
Next, mount the file share using the `mount` command. In the following example, the `$smbPath` command is populated using the fully qualified domain name for the storage account's file endpoint and `$storageAccountKey` is populated with the storage account key.
125+
Next, mount the file share using the `mount` command. In the following example, the `$SMB_PATH` command is populated using the fully qualified domain name for the storage account's file endpoint and `$STORAGE_ACCOUNT_KEY` is populated with the storage account key.
126126

127127
# [SMB 3.1.1](#tab/smb311)
128128
> [!Note]
129129
> Starting in Linux kernel version 5.0, SMB 3.1.1 is the default negotiated protocol. If you're using a version of the Linux kernel older than 5.0, specify `vers=3.1.1` in the mount options list.
130130
131131
```azurecli
132132
# This command assumes you have logged in with az login
133-
httpEndpoint=$(az storage account show \
134-
--resource-group $resourceGroupName \
135-
--name $storageAccountName \
133+
HTTP_ENDPOINT=$(az storage account show \
134+
--resource-group $RESOURCE_GROUP_NAME \
135+
--name $STORAGE_ACCOUNT_NAME \
136136
--query "primaryEndpoints.file" --output tsv | tr -d '"')
137-
smbPath=$(echo $httpEndpoint | cut -c7-${#httpEndpoint})$fileShareName
137+
SMB_PATH=$(echo $HTTP_ENDPOINT | cut -c7-${#HTTP_ENDPOINT})$FILE_SHARE_NAME
138138
139-
storageAccountKey=$(az storage account keys list \
140-
--resource-group $resourceGroupName \
141-
--account-name $storageAccountName \
139+
STORAGE_ACCOUNT_KEY=$(az storage account keys list \
140+
--resource-group $RESOURCE_GROUP_NAME \
141+
--account-name $STORAGE_ACCOUNT_NAME \
142142
--query "[0].value" --output tsv | tr -d '"')
143143
144-
sudo mount -t cifs $smbPath $mntPath -o username=$storageAccountName,password=$storageAccountKey,serverino,nosharesock,actimeo=30,mfsymlinks
144+
sudo mount -t cifs $SMB_PATH $MNT_PATH -o username=$STORAGE_ACCOUNT_NAME,password=$STORAGE_ACCOUNT_KEY,serverino,nosharesock,actimeo=30,mfsymlinks
145145
```
146146
147147
# [SMB 3.0](#tab/smb30)
148148
```azurecli
149149
# This command assumes you have logged in with az login
150-
httpEndpoint=$(az storage account show \
151-
--resource-group $resourceGroupName \
152-
--name $storageAccountName \
150+
HTTP_ENDPOINT=$(az storage account show \
151+
--resource-group $RESOURCE_GROUP_NAME \
152+
--name $STORAGE_ACCOUNT_NAME \
153153
--query "primaryEndpoints.file" --output tsv | tr -d '"')
154-
smbPath=$(echo $httpEndpoint | cut -c7-${#httpEndpoint})$fileShareName
154+
SMB_PATH=$(echo $HTTP_ENDPOINT | cut -c7-${#HTTP_ENDPOINT})$FILE_SHARE_NAME
155155
156-
storageAccountKey=$(az storage account keys list \
157-
--resource-group $resourceGroupName \
158-
--account-name $storageAccountName \
156+
STORAGE_ACCOUNT_KEY=$(az storage account keys list \
157+
--resource-group $RESOURCE_GROUP_NAME \
158+
--account-name $STORAGE_ACCOUNT_NAME \
159159
--query "[0].value" --output tsv | tr -d '"')
160160
161-
sudo mount -t cifs $smbPath $mntPath -o vers=3.0,username=$storageAccountName,password=$storageAccountKey,serverino,nosharesock,actimeo=30,mfsymlinks
161+
sudo mount -t cifs $SMB_PATH $MNT_PATH -o vers=3.0,username=$STORAGE_ACCOUNT_NAME,password=$STORAGE_ACCOUNT_KEY,serverino,nosharesock,actimeo=30,mfsymlinks
162162
```
163163
164164
# [SMB 2.1](#tab/smb21)
165165
```azurecli
166166
# This command assumes you have logged in with az login
167-
httpEndpoint=$(az storage account show \
168-
--resource-group $resourceGroupName \
169-
--name $storageAccountName \
167+
HTTP_ENDPOINT=$(az storage account show \
168+
--resource-group $RESOURCE_GROUP_NAME \
169+
--name $STORAGE_ACCOUNT_NAME \
170170
--query "primaryEndpoints.file" --output tsv | tr -d '"')
171-
smbPath=$(echo $httpEndpoint | cut -c7-${#httpEndpoint})$fileShareName
171+
SMB_PATH=$(echo $HTTP_ENDPOINT | cut -c7-${#HTTP_ENDPOINT})$FILE_SHARE_NAME
172172
173-
storageAccountKey=$(az storage account keys list \
174-
--resource-group $resourceGroupName \
175-
--account-name $storageAccountName \
173+
STORAGE_ACCOUNT_KEY=$(az storage account keys list \
174+
--resource-group $RESOURCE_GROUP_NAME \
175+
--account-name $STORAGE_ACCOUNT_NAME \
176176
--query "[0].value" --output tsv | tr -d '"')
177177
178-
sudo mount -t cifs $smbPath $mntPath -o vers=2.1,username=$storageAccountName,password=$storageAccountKey,serverino,nosharesock,actimeo=30,mfsymlinks
178+
sudo mount -t cifs $SMB_PATH $MNT_PATH -o vers=2.1,username=$STORAGE_ACCOUNT_NAME,password=$STORAGE_ACCOUNT_KEY,serverino,nosharesock,actimeo=30,mfsymlinks
179179
```
180180
181181
---
@@ -185,45 +185,45 @@ You can use `uid`/`gid` or `dir_mode` and `file_mode` in the mount options for t
185185
You can also mount the same Azure file share to multiple mount points if desired. When you're done using the Azure file share, use `sudo umount $mntPath` to unmount the share.
186186
187187
## Automatically mount file shares
188-
When you mount a file share on a Linux OS, your remote file share is represented as a folder in your local file system. You can mount file shares to anywhere on your system. The following example mounts under the `/mount` path. You can change this to your preferred path you want by modifying the `$mntRoot` variable.
188+
When you mount a file share on a Linux OS, your remote file share is represented as a folder in your local file system. You can mount file shares to anywhere on your system. The following example mounts under the `/mount` path. You can change this to your preferred path you want by modifying the `$MNT_ROOT` variable.
189189
190190
```bash
191-
mntRoot="/mount"
192-
sudo mkdir -p $mntRoot
191+
MNT_ROOT="/mount"
192+
sudo mkdir -p $MNT_ROOT
193193
```
194194
195195
To mount an Azure file share on Linux, use the storage account name as the username of the file share, and the storage account key as the password. Because the storage account credentials may change over time, you should store the credentials for the storage account separately from the mount configuration.
196196
197197
The following example shows how to create a file to store the credentials. Remember to replace `<resource-group-name>` and `<storage-account-name>` with the appropriate information for your environment.
198198
199199
```bash
200-
resourceGroupName="<resource-group-name>"
201-
storageAccountName="<storage-account-name>"
200+
RESOURCE_GROUP_NAME="<resource-group-name>"
201+
STORAGE_ACCOUNT_NAME="<storage-account-name>"
202202
203203
# Create a folder to store the credentials for this storage account and
204204
# any other that you might set up.
205-
credentialRoot="/etc/smbcredentials"
205+
CREDENTIAL_ROOT="/etc/smbcredentials"
206206
sudo mkdir -p "/etc/smbcredentials"
207207
208208
# Get the storage account key for the indicated storage account.
209209
# You must be logged in with az login and your user identity must have
210210
# permissions to list the storage account keys for this command to work.
211-
storageAccountKey=$(az storage account keys list \
212-
--resource-group $resourceGroupName \
213-
--account-name $storageAccountName \
211+
STORAGE_ACCOUNT_KEY=$(az storage account keys list \
212+
--resource-group $RESOURCE_GROUP_NAME \
213+
--account-name $STORAGE_ACCOUNT_NAME \
214214
--query "[0].value" --output tsv | tr -d '"')
215215
216216
# Create the credential file for this individual storage account
217-
smbCredentialFile="$credentialRoot/$storageAccountName.cred"
218-
if [ ! -f $smbCredentialFile ]; then
219-
echo "username=$storageAccountName" | sudo tee $smbCredentialFile > /dev/null
220-
echo "password=$storageAccountKey" | sudo tee -a $smbCredentialFile > /dev/null
217+
SMB_CREDENTIAL_FILE="$CREDENTIAL_ROOT/$STORAGE_ACCOUNT_NAME.cred"
218+
if [ ! -f $SMB_CREDENTIAL_FILE ]; then
219+
echo "username=$STORAGE_ACCOUNT_NAME" | sudo tee $SMB_CREDENTIAL_FILE > /dev/null
220+
echo "password=$STORAGE_ACCOUNT_KEY" | sudo tee -a $SMB_CREDENTIAL_FILE > /dev/null
221221
else
222-
echo "The credential file $smbCredentialFile already exists, and was not modified."
222+
echo "The credential file $SMB_CREDENTIAL_FILE already exists, and was not modified."
223223
fi
224224
225225
# Change permissions on the credential file so only root can read or modify the password file.
226-
sudo chmod 600 $smbCredentialFile
226+
sudo chmod 600 $SMB_CREDENTIAL_FILE
227227
```
228228
229229
To automatically mount a file share, you have a choice between using a static mount via the `/etc/fstab` utility or using a dynamic mount via the `autofs` utility.
@@ -232,10 +232,10 @@ To automatically mount a file share, you have a choice between using a static mo
232232
Using the earlier environment, create a folder for your storage account/file share under your mount folder. Replace `<file-share-name>` with the appropriate name of your Azure file share.
233233
234234
```bash
235-
fileShareName="<file-share-name>"
235+
FILE_SHARE_NAME="<file-share-name>"
236236
237-
mntPath="$mntRoot/$storageAccountName/$fileShareName"
238-
sudo mkdir -p $mntPath
237+
MNT_PATH="$MNT_ROOT/$STORAGE_ACCOUNT_NAME/$FILE_SHARE_NAME"
238+
sudo mkdir -p $MNT_PATH
239239
```
240240
241241
Finally, create a record in the `/etc/fstab` file for your Azure file share. In the command below, the default 0755 Linux file and folder permissions are used, which means read, write, and execute for the owner (based on the file/directory Linux owner), read and execute for users in owner group, and read and execute for others on the system. You may wish to set alternate `uid` and `gid` or `dir_mode` and `file_mode` permissions on mount as desired. For more information on how to set permissions, see [UNIX numeric notation](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) on Wikipedia.
@@ -244,14 +244,14 @@ Finally, create a record in the `/etc/fstab` file for your Azure file share. In
244244
> If you want Docker containers running .NET Core applications to be able to write to the Azure file share, include **nobrl** in the SMB mount options to avoid sending byte range lock requests to the server.
245245
246246
```bash
247-
httpEndpoint=$(az storage account show \
248-
--resource-group $resourceGroupName \
249-
--name $storageAccountName \
247+
HTTP_ENDPOINT=$(az storage account show \
248+
--resource-group $RESOURCE_GROUP_NAME \
249+
--name $STORAGE_ACCOUNT_NAME \
250250
--query "primaryEndpoints.file" --output tsv | tr -d '"')
251-
smbPath=$(echo $httpEndpoint | cut -c7-${#httpEndpoint})$fileShareName
251+
SMB_PATH=$(echo $HTTP_ENDPOINT | cut -c7-${#HTTP_ENDPOINT})$FILE_SHARE_NAME
252252
253-
if [ -z "$(grep $smbPath\ $mntPath /etc/fstab)" ]; then
254-
echo "$smbPath $mntPath cifs nofail,credentials=$smbCredentialFile,serverino,nosharesock,actimeo=30" | sudo tee -a /etc/fstab > /dev/null
253+
if [ -z "$(grep $SMB_PATH\ $MNT_PATH /etc/fstab)" ]; then
254+
echo "$SMB_PATH $MNT_PATH cifs nofail,credentials=$SMB_CREDENTIAL_FILE,serverino,nosharesock,actimeo=30" | sudo tee -a /etc/fstab > /dev/null
255255
else
256256
echo "/etc/fstab was not modified to avoid conflicting entries as this Azure file share was already present. You may want to double check /etc/fstab to ensure the configuration is as desired."
257257
fi
@@ -299,15 +299,15 @@ sudo zypper install autofs
299299
Next, update the `autofs` configuration files.
300300
301301
```bash
302-
fileShareName="<file-share-name>"
302+
FILE_SHARE_NAME="<file-share-name>"
303303
304-
httpEndpoint=$(az storage account show \
305-
--resource-group $resourceGroupName \
306-
--name $storageAccountName \
304+
HTTP_ENDPOINT=$(az storage account show \
305+
--resource-group $RESOURCE_GROUP_NAME \
306+
--name $STORAGE_ACCOUNT_NAME \
307307
--query "primaryEndpoints.file" --output tsv | tr -d '"')
308-
smbPath=$(echo $httpEndpoint | cut -c7-$(expr length $httpEndpoint))$fileShareName
308+
SMB_PATH=$(echo $HTTP_ENDPOINT | cut -c7-$(expr length $HTTP_ENDPOINT))$FILE_SHARE_NAME
309309
310-
echo "$fileShareName -fstype=cifs,credentials=$smbCredentialFile :$smbPath" > /etc/auto.fileshares
310+
echo "$FILE_SHARE_NAME -fstype=cifs,credentials=$SMB_CREDENTIAL_FILE :$SMB_PATH" > /etc/auto.fileshares
311311
312312
echo "/fileshares /etc/auto.fileshares --timeout=60" > /etc/auto.master
313313
```

0 commit comments

Comments
 (0)