Skip to main content
Fixed formatting and removed salutations (they're implied here)
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives

Output of the Commands piped to array:

Desired Output of Command:

2

4

6

user@machine:~$

user@machine:~$ autoLoadArchives
Output of the Commands piped to array:
Desired Output of Command:
2
4
6
user@machine:~$

If I remove the the -n flag and p command from sed:

`lsls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d`d

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives

output of the Commands piped to array:

mounting Archive: Archive\x206

mounting Archive: MY-USB

mounting Archive: PFI\x20ARCHIVE\x202

mounting Archive: PFI\x20Archive\x204

Desired Output of Command:

2

4

6

MY-USB

user@machine:~$

user@machine:~$ autoLoadArchives
output of the Commands piped to array:
mounting Archive: Archive\x206
mounting Archive: MY-USB
mounting Archive: PFI\x20ARCHIVE\x202
mounting Archive: PFI\x20Archive\x204
Desired Output of Command:
2
4
6
MY-USB
user@machine:~$ 

EDIT: Output from $ ls /dev/disks/by-label/ : Output from $ ls /dev/disks/by-label/:

user@machine:~$ ls /dev/disk/by-label/
Archive\x206  MY-USB  PFI\x20ARCHIVE\x202  PFI\x20Archive\x204
user@machine:~$ 

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

Thanks in Advance,

-Nick

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives

Output of the Commands piped to array:

Desired Output of Command:

2

4

6

user@machine:~$

If I remove the the -n flag and p command from sed:

`ls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d`

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives

output of the Commands piped to array:

mounting Archive: Archive\x206

mounting Archive: MY-USB

mounting Archive: PFI\x20ARCHIVE\x202

mounting Archive: PFI\x20Archive\x204

Desired Output of Command:

2

4

6

MY-USB

user@machine:~$

EDIT: Output from $ ls /dev/disks/by-label/ :

user@machine:~$ ls /dev/disk/by-label/
Archive\x206  MY-USB  PFI\x20ARCHIVE\x202  PFI\x20Archive\x204
user@machine:~$ 

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

Thanks in Advance,

-Nick

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives
Output of the Commands piped to array:
Desired Output of Command:
2
4
6
user@machine:~$

If I remove the the -n flag and p command from sed:

ls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives
output of the Commands piped to array:
mounting Archive: Archive\x206
mounting Archive: MY-USB
mounting Archive: PFI\x20ARCHIVE\x202
mounting Archive: PFI\x20Archive\x204
Desired Output of Command:
2
4
6
MY-USB
user@machine:~$ 

Output from $ ls /dev/disks/by-label/:

user@machine:~$ ls /dev/disk/by-label/
Archive\x206  MY-USB  PFI\x20ARCHIVE\x202  PFI\x20Archive\x204
user@machine:~$ 

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

added 2 characters in body
Source Link
choroba
  • 49.7k
  • 7
  • 92
  • 119

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives

Output of the Commands piped to array:

Desired Output of Command:

2

4

6

user@machine:~$

If I remove the the -n flag and p command from sed:

`ls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d`

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives

output of the Commands piped to array:

mounting Archive: Archive\x206

mounting Archive: MY-USB

mounting Archive: PFI\x20ARCHIVE\x202

mounting Archive: PFI\x20Archive\x204

Desired Output of Command:

2

4

6

MY-USB

user@machine:~$

EDIT: Output from $ ls /dev/disks/by-label/ :

user@machine:~$ ls /dev/disk/by-label/

Archive\x206 MY-USB PFI\x20ARCHIVE\x202 PFI\x20Archive\x204

user@machine:~$

user@machine:~$ ls /dev/disk/by-label/
Archive\x206  MY-USB  PFI\x20ARCHIVE\x202  PFI\x20Archive\x204
user@machine:~$ 

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

Thanks in Advance,

-Nick

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives

Output of the Commands piped to array:

Desired Output of Command:

2

4

6

user@machine:~$

If I remove the the -n flag and p command from sed:

`ls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d`

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives

output of the Commands piped to array:

mounting Archive: Archive\x206

mounting Archive: MY-USB

mounting Archive: PFI\x20ARCHIVE\x202

mounting Archive: PFI\x20Archive\x204

Desired Output of Command:

2

4

6

MY-USB

user@machine:~$

EDIT: Output from $ ls /dev/disks/by-label/ :

user@machine:~$ ls /dev/disk/by-label/

Archive\x206 MY-USB PFI\x20ARCHIVE\x202 PFI\x20Archive\x204

user@machine:~$

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

Thanks in Advance,

-Nick

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives

Output of the Commands piped to array:

Desired Output of Command:

2

4

6

user@machine:~$

If I remove the the -n flag and p command from sed:

`ls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d`

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives

output of the Commands piped to array:

mounting Archive: Archive\x206

mounting Archive: MY-USB

mounting Archive: PFI\x20ARCHIVE\x202

mounting Archive: PFI\x20Archive\x204

Desired Output of Command:

2

4

6

MY-USB

user@machine:~$

EDIT: Output from $ ls /dev/disks/by-label/ :

user@machine:~$ ls /dev/disk/by-label/
Archive\x206  MY-USB  PFI\x20ARCHIVE\x202  PFI\x20Archive\x204
user@machine:~$ 

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

Thanks in Advance,

-Nick

Added in requested output of ls /dev/disks/by-label/ command
Source Link

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives

Output of the Commands piped to array:

Desired Output of Command:

2

4

6

user@machine:~$

If I remove the the -n flag and p command from sed:

`ls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d`

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives

output of the Commands piped to array:

mounting Archive: Archive\x206

mounting Archive: MY-USB

mounting Archive: PFI\x20ARCHIVE\x202

mounting Archive: PFI\x20Archive\x204

Desired Output of Command:

2

4

6

MY-USB

user@machine:~$

EDIT: Output from $ ls /dev/disks/by-label/ :

user@machine:~$ ls /dev/disk/by-label/

Archive\x206 MY-USB PFI\x20ARCHIVE\x202 PFI\x20Archive\x204

user@machine:~$

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

Thanks in Advance,

-Nick

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives

Output of the Commands piped to array:

Desired Output of Command:

2

4

6

user@machine:~$

If I remove the the -n flag and p command from sed:

`ls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d`

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives

output of the Commands piped to array:

mounting Archive: Archive\x206

mounting Archive: MY-USB

mounting Archive: PFI\x20ARCHIVE\x202

mounting Archive: PFI\x20Archive\x204

Desired Output of Command:

2

4

6

MY-USB

user@machine:~$

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

Thanks in Advance,

-Nick

First off, apologies if this has been asked before, I searched both here and StackOverflow, tried the man pages, and I'm still drawing a blank.

I'm trying to write a script that will auto-mount our server's archive drives on booting (for security reasons, nothing attached to the machine is automatically mounted by the system).

What I have so far is this:

#! /bin/bash
archives=( `ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d`)

echo "Output of the Commands piped to array:"
for arcNum in ${archives[@]}; do
    echo "mounting Archive: $arcNum"
done

echo "Desired Output of Command:"
ls /dev/disk/by-label/ | sed -rn 's/.*archive\\x20(.*)/\1/Ip'|sort -d

Running it yields this in the terminal:

user@machine:~$ autoLoadArchives

Output of the Commands piped to array:

Desired Output of Command:

2

4

6

user@machine:~$

If I remove the the -n flag and p command from sed:

`ls /dev/disk/by-label/ | sed -r 's/.*archive\\x20(.*)/\1/I'|sort -d`

I end up with the raw unfiltered list in the array but a properly substituted and sorted unfiltered list in the command line version:

user@machine:~$ autoLoadArchives

output of the Commands piped to array:

mounting Archive: Archive\x206

mounting Archive: MY-USB

mounting Archive: PFI\x20ARCHIVE\x202

mounting Archive: PFI\x20Archive\x204

Desired Output of Command:

2

4

6

MY-USB

user@machine:~$

EDIT: Output from $ ls /dev/disks/by-label/ :

user@machine:~$ ls /dev/disk/by-label/

Archive\x206 MY-USB PFI\x20ARCHIVE\x202 PFI\x20Archive\x204

user@machine:~$

I have the horrible feeling that my problem is probably something idiotically noobish, but I'm honestly drawing a blank as to what's going on here.

Thanks in Advance,

-Nick

Source Link
Loading