Advertisement
Guest User

Untitled

a guest
May 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.01 KB | None | 0 0
  1.   GNU nano 2.5.3                                                      File: chercheText.sh                                                                                                                  
  2.  
  3. #!/bin/bash
  4. function chercherText {
  5.         local code=1
  6.         for file in $(find $1 -type f -mtime -7 2> /dev/null); do
  7.                 if file $file | grep -q "text"; then
  8.                         echo $file
  9.                         code=0
  10.                 fi
  11.         done
  12.         return $code
  13. }
  14.  
  15. fout="/dev/stdout"
  16. while getopts "hf" option; do
  17.         case $option in
  18.                 h)
  19.                         echo "Usage : chercheText.sh [-h] [-f] [rep [...]]" >> $fout
  20.                         exit 2
  21.                         ;;
  22.                 f)
  23.                         fout=chercherText.$(date +"%d_%m_%Y")
  24.                         rm $fout 2> /dev/null
  25.                         touch $fout
  26.                         ;;
  27.                 *)
  28.                         echo "Options invalides" > /dev/stderr
  29.                         echo $usage > /dev/stderr
  30.                         exit 1
  31.                         ;;
  32.         esac
  33. done
  34.  
  35. shift $(($OPTIND -1))
  36. code=1
  37. case $# in
  38.         0)
  39.                 chercherText '.'
  40.                 exit $?
  41.                 ;;
  42.         1)
  43.                 if [ -d $1 ]; then
  44.                         chercherText $1
  45.                         exit $?
  46.                 else
  47.                         echo "$1 n'est pas un repertoire" > /dev/stderr
  48.                         exit 2
  49.                 fi
  50.                 ;;
  51.         *)
  52.                 for file in $*; do
  53.                         if [ -d $file ]; then
  54.                                 echo "Repertoire : $file" >> $fout
  55.                                 chercherText $file
  56.                                 code=$?
  57.                         else
  58.                                 echo "$file n'est pas un repertoire" > /dev/stderr
  59.                         fi
  60.                 done
  61.                 ;;
  62. esac
  63. exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement