Advertisement
dzocesrce

[OS] Find Shell Scripts

Jan 22nd, 2024
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.59 KB | None | 0 0
  1. #!/bin/bash
  2. if [ $# -ne 3 ]
  3. then
  4.     echo "USAGE: `basename $0` imenik bajti some_file.txt"
  5.     exit 1
  6. fi
  7. if [ ! -d $1 ]
  8. then
  9.     echo "Imenikot prosleden kako argument ne postoi"
  10.     exit 1
  11. fi
  12. #there should also be a check if the second argument is a number but I did not find that part enteratining so let's hope it's a number
  13. file_name=`echo $3 | sed 's/\.txt//'`
  14. if [ ! -f $3 ]
  15. then
  16.     touch $3
  17. else
  18.     rm $3
  19.     touch ${file_name}_moved.txt
  20. fi
  21. #get all .sh files that weigh less than 150B from argument1 directory
  22. SCRIPTS=`ls -R $1 | awk '$4<150 && $10~/\.sh$/ {print $10}'`
  23. for script in $SCRIPTS
  24. do
  25.     #make sure they are executable by the user
  26.     chmod $script u+x
  27.     result=`./$script`
  28.     #just tryna detect whether they require to be called with arguments or not
  29.     #I know this segment looks kinda goofy but my hungry ass could not think of any other way atm
  30.     #I am not sure whether we should learn that by the output message or like the exit call or something
  31.     #if anyone knows more to it simply DM me :3
  32.     temp=`$result | grep USAGE`
  33.     if [ -f $3 ]
  34.     then
  35.         if [ "$result" == "$temp" ]
  36.         then
  37.             echo "$script se povikuva so argumenti" >> $3
  38.         else
  39.             echo "$script se povikuva bez argumenti" >> $3
  40.     else
  41.         if [ "$result" == "$temp" ]
  42.         then
  43.             echo "$script se povikuva so argumenti" >> ${file_name}_moved.txt
  44.         else
  45.             echo "$script se povikuva bez argumenti" >> ${file_name}_moved.txt
  46.     fi
  47. done
  48. if [ -f $3 ]
  49. then
  50.     cat $3
  51. else
  52.     cat ${file_name}_moved.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement