Advertisement
CSenshi

OS - FUSE (test symlinks)

Jul 14th, 2019
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.66 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # to run please change mode
  4. # chmod +x check_dir.bash
  5.  
  6. if [ "$#" -ne 1 ]; then
  7.     echo "Illegal number of parameters"
  8.     echo 'Call : ./check_dir.sh mounted_dir'
  9.     exit 1
  10. fi
  11.  
  12. MOUNT_DIR=$1
  13. cd $MOUNT_DIR
  14.  
  15.  
  16. CMD="#### Command : "
  17.  
  18. test1(){
  19.     echo "Test 1 : link two files"
  20.     echo
  21.    
  22.     FILE1="file.txt"
  23.     FILE2="file_to_link.txt"
  24.     CONTENT="Test for linking..."
  25.    
  26.     echo "$CMD echo $CONTENT > $FILE1"
  27.     echo "$CONTENT" > $FILE1
  28.     echo
  29.    
  30.     echo "$CMD ln -s $FILE1 $FILE2"
  31.     ln -s $FILE1 $FILE2
  32.     echo
  33.    
  34.     echo "$CMD ls -l"
  35.     ls --color=auto -l
  36.     echo
  37.    
  38.     echo "$CMD cat $FILE1"
  39.     cat $FILE1
  40.     echo
  41.    
  42.     echo "$CMD cat $FILE2"
  43.     cat $FILE2
  44.     echo
  45.    
  46.     echo "Done!"
  47.     echo
  48. }
  49.  
  50. test2(){
  51.     echo "Test 2 : link two files inside same directory"
  52.    
  53.     mkdir test2_dir
  54.     cd test2_dir
  55.     mkdir dir
  56.     cd dir
  57.    
  58.     FILE1="file.txt"
  59.     FILE2="file_to_link.txt"
  60.     CONTENT="Test for linking inside directories..."
  61.    
  62.     echo "$CMD echo $CONTENT > $FILE1"
  63.     echo "$CONTENT" > $FILE1
  64.     echo
  65.    
  66.     echo "$CMD ln -s $FILE1 $FILE2"
  67.     ln -s $FILE1 $FILE2
  68.     echo
  69.    
  70.     echo "$CMD ls -l"
  71.     ls --color=auto -l
  72.     echo
  73.    
  74.     echo "$CMD cat $FILE1"
  75.     cat $FILE1
  76.     echo
  77.    
  78.     echo "$CMD cat $FILE2"
  79.     cat $FILE2
  80.     echo
  81.    
  82.     cd ..
  83.     cd ..
  84.    
  85.     echo "Done!"
  86.     echo
  87. }
  88.  
  89. test3(){
  90.     echo "Test 3 : link two files inside different directory"
  91.    
  92.     mkdir test3_dir
  93.     cd test3_dir
  94.     mkdir dir1
  95.    
  96.     FILE1="dir1/file.txt"
  97.     FILE2="file_to_link.txt"
  98.     CONTENT="Test for linking inside directories..."
  99.    
  100.     echo "$CMD echo $CONTENT > $FILE1"
  101.     echo "$CONTENT" > $FILE1
  102.     echo
  103.    
  104.     echo "$CMD ln -s $FILE1 $FILE2"
  105.     ln -s $FILE1 $FILE2
  106.     echo
  107.    
  108.     echo "$CMD ls -l"
  109.     ls --color=auto -l
  110.     echo
  111.    
  112.     echo "$CMD cat $FILE1"
  113.     cat $FILE1
  114.     echo
  115.    
  116.     echo "$CMD cat $FILE2"
  117.     cat $FILE2
  118.     echo
  119.    
  120.     echo "Done!"
  121.     echo
  122. }
  123.  
  124. test4(){
  125.     echo "Test 2 : link multiple files"
  126.     echo
  127.    
  128.     FILE="file_mm.txt"
  129.     FILE_MM="file_to_link_mm.txt"
  130.     CONTENT="TEST FOR MULTIPLE"
  131.    
  132.     echo "$CMD echo $CONTENT > $FILE"
  133.     echo $CONTENT > $FILE
  134.     echo
  135.    
  136.     echo "$CMD ln -s $FILE $FILE_MM$((0))"
  137.     ln -s $FILE $FILE_MM$((0))
  138.     echo
  139.    
  140.     MAX_NUM=9
  141.     for t in $(seq 0 $((MAX_NUM-1)))
  142.     do
  143.         echo "$CMD ln -s $FILE_MM$t $FILE_MM$((t+1))"
  144.         ln -s $FILE_MM$t $FILE_MM$((t+1))
  145.     done;
  146.    
  147.     echo
  148.     echo "$CMD ls -l"
  149.     ls --color=auto -l
  150.     echo
  151.    
  152.     echo "$CMD cat $FILE_MM$MAX_NUM"
  153.     cat $FILE_MM$MAX_NUM
  154.     echo
  155.    
  156.     echo "Done!"
  157.     echo
  158. }
  159.  
  160. test5(){
  161.     echo "Test 3 : link direcotires"
  162.    
  163.     DIR="dir"
  164.     DIR_TO_LINK="dir_to_link"
  165.    
  166.     mkdir $DIR
  167.     mkdir $DIR/a
  168.     mkdir $DIR/b
  169.     mkdir $DIR/c
  170.     mkdir $DIR/d
  171.     touch $DIR/file
  172.    
  173.     echo "$CMD ln -s $DIR $DIR_TO_LINK"
  174.     ln -s $DIR $DIR_TO_LINK
  175.     echo
  176.    
  177.     echo "$CMD ls -l"
  178.     ls --color=auto -l
  179.     echo
  180.    
  181.     echo "$CMD ls $DIR"
  182.     ls --color=auto  $DIR
  183.     echo
  184.    
  185.     echo "$CMD ls  $DIR_TO_LINK"
  186.     ls --color=auto  $DIR_TO_LINK
  187.     echo
  188.    
  189. }
  190.  
  191.  
  192. run_test(){
  193.     # check basic symlinking
  194.     test1
  195.    
  196.     # symlinking inside same directories
  197.     test2
  198.    
  199.     # symlinking inside different directories
  200.     test3
  201.    
  202.     # check symlinking to multiple sources
  203.     test4
  204.    
  205.     # check for directories
  206.     test5
  207. }
  208.  
  209.  
  210. START=$(date +%s.%N)
  211. run_test
  212. END=$(date +%s.%N)
  213. DIFF=$(echo "$END - $START" | bc)
  214.  
  215. echo "Elapsed time : $DIFF seconds"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement