Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何在awk脚本中使用shell变量 #91

Open
vieyahn2017 opened this issue Jan 24, 2024 · 2 comments
Open

如何在awk脚本中使用shell变量 #91

vieyahn2017 opened this issue Jan 24, 2024 · 2 comments

Comments

@vieyahn2017
Copy link
Owner

echo "$result" | grep " sd" | awk -v nlun="$lun" '{print nlun" "$2" "$3}'
@vieyahn2017
Copy link
Owner Author

@vieyahn2017
Copy link
Owner Author

#!/bin/bash

tmpfile=/root/multipath_tmp
[ -e "$tmpfile" ] && rm -rf $tmpfile

function explain_one_foreach () {
        for lun in $(cat "$WWIDS" | grep -v ^# | sed s#/##g);
        do
                result=$(multipath -ll "$lun" 2> /dev/null)
                echo "$result" | grep " sd" | awk -v nlun="$lun" '{print nlun" "$3" "$2" "$5" "$6" "$7}' >> $tmpfile
        done
}

function explain_all () {
        results=$(multipath -ll 2> /dev/null)
        lun=""
        echo "$results" | while read line;
        do
                if [ "${line:0:2}" == "36" ]; then
                        lun=$(echo $line | awk '{print $1}')
                fi
                if [ $(echo $line | grep -c " sd") -eq 1 ]; then
                        echo "$line" | awk -v nlun="$lun" '{print nlun" "$3" "$2" "$5" "$6" "$7}'
                fi
        done
}

WWIDS=/etc/multipath/wwids
if [ ! -f /etc/multipath/wwids ]; then
    echo "/etc/multipath/wwids files not existed"
    if [ $(multipath -ll  2>&1 | grep -c "DM multipath kernel driver not loaded") -eq 1 ]; then
        echo "DM multipath kernel driver not loaded"
        exit 1
    fi
fi

explain_all >> $tmpfile
exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant