Ubuntu Pastebin

Paste from smoser at Thu, 18 Aug 2016 18:05:05 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$ ./go.sh 
== is_azure_grep ==

real	0m0.345s
user	0m0.136s
sys	0m0.132s
== is_azure_read ==

real	0m0.030s
user	0m0.028s
sys	0m0.000s
== : ==

real	0m0.009s
user	0m0.012s
sys	0m0.000s

$ cat go.sh
#!/bin/bash

is_azure_read() {
    local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
    if [ -e "$dmi_path" ] && read vendor < "$dmi_path"; then
        [ "$vendor" = "Microsoft Corporation" ] && return 0
    fi
    return 1
}

is_azure_grep() {
    local dmi_path="/sys/class/dmi/id/board_vendor" vendor=""
    grep 'Microsoft Corporation' "$dmi_path" >/dev/null 2>&1
}

loop() {
   local num=$1 i="0"
   shift
   echo "== $@ =="
   while [ $i -lt $num ]; do
      "$@"
      i=$((i+1))
   done
}

num=${1:-100}
time loop $num is_azure_grep
time loop $num is_azure_read
time loop $num :
Download as text