0

if trying to automated this checks, how would py function work with shell

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() 
2
  • what is wrong with mount -t $filesystem, e.g. mount -t xfs ?CommentedAug 18, 2022 at 13:10
  • ideally to focus on mount directory if its valid or not, in a case of directory exists , mount failed. let's say we have couple of types of fs , with different mount directories, im considering writing into existing mounting directories to valid or check if directories - subs are not empty
    – user538051
    CommentedAug 18, 2022 at 14:02

2 Answers 2

1

If you want to check whether a directory is "simply" a directory, or if it is used as a mountpoint, there is the mountpoint tool from the util-linux package.

Usage example

  • simple directory
    ~$ mkdir testdir ~$ mountpoint testdir testdir is not a mountpoint 
  • mount a filesystem to the directory
    ~$ sudo mount /my/external/filesystem testdir ~$ mountpoint testdir testdir is a mountpoint 

If you want to use it in shell scripts for automated tests, there is also a silent mode available:

if mountpoint -q testdir then # perform operations on the mounted filesystem else echo "Error, nothing mounted on testdir!" fi 
4
  • the directory could be always there once mount suceed , but doesn't mean everytime node reboot mount are sucess . key area if we could check whether direcotry works, or mount status active/enabled?
    – user538051
    CommentedAug 19, 2022 at 10:44
  • @user538051 I'm not sure if I understand you. If you reboot the node and the mount fails, that means that no filesystem is mounted to testdir, and mountpoint would return testdir is not a mountpoint...
    – AdminBee
    CommentedAug 19, 2022 at 10:46
  • but there's also case mount failed but there's directory exists / created manually from previous. let's say we have multiple mountpoint , some are sucess, some are not.
    – user538051
    CommentedAug 19, 2022 at 10:53
  • @user538051 Yes, but as you can see in my example, if I create the directory manually but don't mount anything to it, it will be correctly identified as "just a directory". So if the directory that is intended to be used as a mountpoint exists, but nothing is mounted to it (not yet, or because an attempt to mount failed), it should be treated correctly.
    – AdminBee
    CommentedAug 19, 2022 at 11:29
0

If I understand you correctly you want to make sure that all mounts were properly mounted before writing data to those directories. If that is correct I would suggest to set a immutable flag on the directory before mounting it. Here is an example:

[user@host ~]$ mkdir ./1 && sudo chattr +i ./1 [user@host ~]$ sudo touch 1/test.txt touch: cannot touch ‘1/test.txt’: Permission denied [user@host ~]$ sudo mount -t tmpfs none 1 [user@host ~]$ touch 1/test.txt && ls -l 1/test.txt -rw-r--r-- 1 user group 0 Aug 18 10:49 1/test.txt 
1
  • suppose if you have multiple mountpoints to check, how would you mountpoint -q [check multiple directories] if not mount them again
    – user538051
    CommentedAug 22, 2022 at 10:42

You must log in to answer this question.