shell / py変数を使用して複数のディレクトリを確認するためにマウントポイントを使用する方法

shell / py変数を使用して複数のディレクトリを確認するためにマウントポイントを使用する方法

このチェックを自動化したい場合、py関数はシェルでどのように機能しますか?

def success():
    print("###    ####end")
    print("###end")

# It can be called when the script fails and output the failed signal.
def failure():
    print("### ####end")
    print("###end")

# It can be called when the script needs to Export results.Separate multiple export results with \n.
# if you want to output multi line messages, you can call the function multiple times or add newline characters, for example, output("aaaaa\nbbbbb\nccccc\nddddd")
# Note: 1. If you create a job by calling an interface, the script can obtain the script output from the output field only by calling the output function.
# Note: 2. Only output messages are exported by the Export Result button on the page.
def output(msg):
    print("### ####end")
    print(msg)
    print("###end")

# Special output function for inspection work, output inspection results.Multiple inspection results are separated by %.
# example: inspect_output("$item_name1%$item_name2%$item_name3")
# Note: The inspection task definition script must use the inspect_output function.
def inspect_output(msg):
    print("### ####end")
    print("inspect_output:{msg} end".format(msg=msg))
    print("###end")
 
# Note:script content in the main function. Ensure that you call function success or failure.Otherwise, the system cannot capture the script output information.
def main():
    # Note: if output logs are needed, direct print(xxx) can be used.
    pass

if __name__ == "__main__":
    main()

ベストアンサー1

ディレクトリが「ただ」ディレクトリであることを確認したい場合、またはマウントポイントとして使用されている場合は、パッケージmountpoint内のツールを使用できますutil-linux

使用例

  • 単純なディレクトリ
    ~$ mkdir testdir
    ~$ mountpoint testdir
    testdir is not a mountpoint
    
  • ファイルシステムをディレクトリにマウントする
    ~$ sudo mount /my/external/filesystem testdir
    ~$ mountpoint testdir
    testdir is a mountpoint
    

自動化されたテストのためにシェルスクリプトで使用したい場合は、自動モードも使用できます。

if mountpoint -q testdir
then
    # perform operations on the mounted filesystem
else
    echo "Error, nothing mounted on testdir!"
fi

おすすめ記事