sfs.sh

From InterGen, 2 Years ago, written in Bash, viewed 1'216 times.
URL https://paste.intergen.online/view/15d5c2b9 Embed
Download Paste or View Raw
  1. #!/bin/bash
  2. # -------------------------------------------------------------------------------------------
  3. # sfs - s.earch f.ile s.ize and create a pastebin of the results
  4. # sfs Version: 1.1
  5. # Github: https://github.com/InterGenStudios/sfs
  6. # ---------------------------------------------------
  7. # InterGenStudios: 5-3-15
  8. # Copyright (c) 2015: Christopher 'InterGen' Cork  InterGenStudios
  9. # URL: https://intergenstudios.com
  10. # --------------------------------
  11. # License: GPL-2.0+
  12. # URL: http://opensource.org/licenses/gpl-license.php
  13. # ---------------------------------------------------
  14. # sfs is free software:
  15. # You may redistribute it and/or modify it under the terms of the
  16. # GNU General Public License as published by the Free Software
  17. # Foundation, either version 2 of the License, or (at your discretion)
  18. # any later version.
  19. # ------------------
  20.  
  21.  
  22. ###########################################
  23. ##---------------------------------------##
  24. ## BEGIN - INITIAL VARIABLE DECLARATIONS ##
  25. ##---------------------------------------##
  26. ###########################################
  27.  
  28. # Sets sfs version number
  29. vers=1.1
  30.  
  31. # Simple regex for number checking
  32. RE='^[0-9]+$'
  33.  
  34. # Sets timestamp
  35. stamp="$(echo $(date +"%m-%d-%Y") $(date +"%T"))"
  36.  
  37. #########################################
  38. ##-------------------------------------##
  39. ## END - INITIAL VARIABLE DECLARATIONS ##
  40. ##-------------------------------------##
  41. #########################################
  42.  
  43. #######################
  44. ##-------------------##
  45. ## BEGIN - FUNCTIONS ##
  46. ##-------------------##
  47. #######################
  48.  
  49. # Colors trailing text Red
  50. RED="\e[1m\e[31m"
  51.  
  52. # Colors trailing text Green
  53. GREEN="\e[1m\e[32m"
  54.  
  55. # Colors trailing text Yellow
  56. YELLOW="\e[1m\e[33m"
  57.  
  58. # Colors trailing text Blue
  59. BLUE="\e[1m\e[34m"
  60.  
  61. # Colors trailing text Bold White
  62. WHITE="\e[1m\e[37m"
  63.  
  64. # Removes any previously set colors
  65. NOCOLOR="\e[0m"
  66.  
  67. # A simple divider
  68. SEPARATOR () {
  69.  
  70.     echo -e "\n\n${BLUE}------------------------------------------------------------------------------${NOCOLOR}\n\n"
  71.  
  72. }
  73.  
  74. # Creates uniform look during script execution when called after any clear command
  75. HEADER () {
  76.  
  77.     echo -e "\n\n${BLUE}______________________________________________________________________________________________${NOCOLOR}\n"
  78.     echo -e "${WHITE}    sfs v${GREEN}$vers${NOCOLOR}"
  79.     echo -e "${BLUE}______________________________________________________________________________________________${NOCOLOR}\n\n"
  80.  
  81. }
  82.  
  83. HELPTEXT () {
  84.  
  85.     clear
  86.     HEADER
  87.     echo -e "${GREEN}sfs help:${NOCOLOR}\n"
  88.     echo "SFS is a simple cPanel server utility for finding files of a target size"
  89.     echo -e "and pastebinning the results.\n"
  90.     echo -e "------------------\n"
  91.     echo -e "${GREEN}USAGE:${NOCOLOR}\n"
  92.     echo -e "sfs  ...[${GREEN}target_directory${NOCOLOR}] [${GREEN}target_file_size${NOCOLOR}]   |   ...[${GREEN}target_directory${NOCOLOR}]  |  ${GREEN}-h ${NOCOLOR}(runs helptext)\n\n"
  93.     exit 0
  94.  
  95. }
  96.  
  97. GET_TARGET_FILESIZE () {
  98.  
  99.     clear
  100.     HEADER
  101.     echo -e -n "  ${GREEN}In ${WHITE}MB, ${GREEN}enter target file size${NOCOLOR} [Default = 100]: "
  102.     read TARGETSIZE
  103.     if [ -z "$TARGETSIZE" ]; then
  104.         SIZE=100
  105.         sleep 1
  106.     elif ! [[ $TARGETSIZE =~ $RE ]]; then
  107.         echo
  108.         echo -e "\n${RED}WARNING!${NOCOLOR}\n\n"
  109.         echo -e "${WHITE}$TARGETSIZE ${GREEN}isn't a number-size in MB.\n  Restarting...${NOCOLOR}"
  110.         sleep 2
  111.         GET_TARGET_FILESIZE
  112.     else
  113.         SIZE="$TARGETSIZE"
  114.         sleep 1
  115.     fi
  116.  
  117. }
  118.  
  119. LOOP () {
  120.  
  121.     echo -e "\n  ${RED}WARNING!${NOCOLOR}\n"
  122.     echo -e "  ${WHITE}$CHOICE ${GREEN}isn't a valid path on this server.\n"
  123.     sleep 1
  124.     echo -e "  ${GREEN}Please double check that you want to search.${NOCOLOR}\n\n  (Restarting...)"
  125.     SEPARATOR
  126.     sleep 1
  127.     GET_TARGET_FILESIZE
  128.  
  129. }
  130.  
  131. SEARCH () {
  132.  
  133.     # Default search size
  134.     SEARCHSIZE=$(($SIZE * 1000))
  135.     tput cuu 2 && tput el
  136.     echo -e "\n\n  ${GREEN}Server: ${WHITE}$HOSTNAME ${NOCOLOR}$stamp"
  137.     SEPARATOR
  138.     echo -e "  ${GREEN}Searching recursively in ${WHITE}$TARGET_DIR ${GREEN}for files ${WHITE}>= $SIZE${GREEN}M${NOCOLOR}"
  139.     SEPARATOR
  140.     find "$TARGET_DIR" -type f -size +"$SEARCHSIZE"k -exec ls -lh {} \; 2>/dev/null | awk '{ printf "%- 130s %s\n", $9,$5; }'
  141.     echo -e "\n\n  ${GREEN}Total Size of ${WHITE}$TARGET_DIR${GREEN}: ${WHITE}$DIR_SIZE${NOCOLOR}\n"
  142.     COUNT_FILES
  143.     echo "  Search Complete"
  144.     SEPARATOR
  145.     printf "\n\n"
  146.  
  147. }
  148.  
  149. PASTE () {
  150.  
  151.     PASTEFILE=$@;
  152.     curl -d name=sfs -d private=1 --data-urlencode text@"$PASTEFILE" -s https://paste.intergen.online/api/create > TEMPASTE
  153.     sed -i 's/view/view\/raw/g' TEMPASTE
  154.     SEPARATOR
  155.     echo -e "  ${GREEN}Your results are at${WHITE}:\n"
  156.     echo -e "  ${BLUE}  ====> ${WHITE}$(cat TEMPASTE)${NOCOLOR}\n\n  ${GREEN}Your paste will expire in 30 days${NOCOLOR}"
  157.     SEPARATOR
  158.     rm TEMPASTE
  159.  
  160. }
  161.  
  162. GET_FILECOUNTER_CHOICE () {
  163.  
  164.     clear
  165.     HEADER
  166.     echo -e -n "  ${GREEN}Find the number of total files in the ${WHITE}TARGET DIRECTORY${NOCOLOR} [${WHITE}y/N${NOCOLOR}]? "
  167.     read FILE_COUNTER
  168.  
  169. }
  170.  
  171. # Checks for FILESEARCH flag
  172. CHECK_FILECOUNTER_CHOICE () {
  173.  
  174.     if [ -z "$FILE_COUNTER" ] || [ "$FILE_COUNTER" = "N" ] || [ "$FILE_COUNTER" = "n" ]; then
  175.         FILECOUNTER=NO
  176.         echo -e "\n  ${YELLOW}FILECOUNTER SKIPPED\n  ${NOCOLOR}Getting target directory size..."
  177.     elif [[ $FILE_COUNTER =~ $RE ]]; then
  178.         echo -e "\n  ${RED}WARNING!\n  ${NOCOLOR}Incorrect entry...\nRestarting..."
  179.         sleep 2
  180.         GET_TARGET_FILESIZE
  181.     else
  182.         FILECOUNTER=YES
  183.         echo -e "  ${GREEN}FILECOUNTER ENABLED\n"
  184.         sleep 2
  185.         echo -e "  ${NOCOLOR}Getting target directory size..."
  186.     fi
  187.  
  188. }
  189.  
  190. # Counts # of files if target directory
  191. COUNT_FILES () {
  192.  
  193.     if [ "$FILECOUNTER" = "YES" ]; then
  194.         TOTAL_FILE_COUNT="$(echo $(($(du -ah "$TARGET_DIR" 2>/dev/null | wc -l) - 1)))"
  195.         echo -e "\n  ${GREEN}Total number of files in ${WHITE}$TARGET_DIR${GREEN}: ${WHITE}$TOTAL_FILE_COUNT${NOCOLOR}\n"
  196.     fi
  197.  
  198. }
  199.  
  200. CHECK_TARGET_DIR_EXISTS () {
  201.  
  202.     if [ ! -d "$TARGET_DIR" ]; then
  203.         LOOP
  204.     fi
  205.  
  206. }
  207.  
  208. GET_TARGET_DIR () {
  209.  
  210.     clear
  211.     HEADER
  212.     echo -e "  ${GREEN}Enter target search path or choose from the list below${WHITE}:${NOCOLOR}\n"
  213.     echo -e "  ${WHITE}1) ${GREEN}/home Directory${NOCOLOR}"
  214.     echo -e "  ${WHITE}2) ${GREEN}/var/log Directory${NOCOLOR}"
  215.     echo -e "  ${WHITE}3) ${GREEN}/usr/local/cpanel/logs Directory${NOCOLOR}"
  216.     echo -e "  ${WHITE}4) ${GREEN}/var/lib/mysql Directory${NOCOLOR}"
  217.     echo -e "  ${WHITE}5) ${GREEN}/backup Directory${NOCOLOR}\n"
  218.     echo -e "  ${WHITE}( ${GREEN}default${WHITE} =${GREEN} / Root Directory${WHITE} )\n"
  219.     echo -n "  [enter choice or directory path]: "
  220.     read DIR_CHOICE
  221.     case "$DIR_CHOICE" in
  222.               1) TARGET_DIR=/home;;
  223.               2) TARGET_DIR=/var/log;;
  224.               3) TARGET_DIR=/usr/local/cpanel/logs;;
  225.               4) TARGET_DIR=/var/lib/mysql;;
  226.               5) TARGET_DIR=/backup;;
  227.               *) if [ -z "$DIR_CHOICE" ]; then
  228.                     TARGET_DIR=/
  229.                  elif ! [[ $DIR_CHOICE =~ $RE ]]; then
  230.                     TARGET_DIR=$DIR_CHOICE
  231.                  fi;;
  232.     esac
  233.  
  234. }
  235.  
  236. GET_INPUT () {
  237.  
  238.     GET_TARGET_FILESIZE
  239.     GET_TARGET_DIR
  240.     GET_FILECOUNTER_CHOICE
  241.     CHECK_FILECOUNTER_CHOICE
  242.  
  243. }
  244.  
  245. #####################
  246. ##-----------------##
  247. ## END - FUNCTIONS ##
  248. ##-----------------##
  249. #####################
  250.  
  251. #############################################
  252. ##-----------------------------------------##
  253. ## BEGIN - MAKE SURE WE'RE RUNNING AS ROOT ##
  254. ##-----------------------------------------##
  255. #############################################
  256.  
  257. if [ "$(id -u)" != "0" ]; then
  258.     echo -e "\n\n${RED}${BLINK}--------${NOCOLOR}"
  259.     echo -e "${RED}${BLINK}WARNING!${NOCOLOR}"
  260.     echo -e "${RED}${BLINK}--------${NOCOLOR}\n\n"
  261.     echo -e "${WHITE}sfs must be run as ${RED}root${NOCOLOR}\n\n"
  262.     echo -e "${GREEN}(Exiting now...)${NOCOLOR}\n\n"
  263.     exit 1
  264. fi
  265.  
  266. ###########################################
  267. ##---------------------------------------##
  268. ## END - MAKE SURE WE'RE RUNNING AS ROOT ##
  269. ##---------------------------------------##
  270. ###########################################
  271.  
  272. #########################
  273. ##---------------------##
  274. ## BEGIN - CORE SCRIPT ##
  275. ##---------------------##
  276. #########################
  277.  
  278. if [ "$1" = "-h" ]; then
  279.     HELPTEXT
  280. else
  281.     if [ -z $1 ]; then
  282.         GET_INPUT
  283.     else
  284.         if [ -d $1 ] && [[ $2 =~ $RE ]]; then
  285.             TARGET_DIR="$1"
  286.             SIZE="$2"
  287.             GET_FILECOUNTER_CHOICE
  288.             CHECK_FILECOUNTER_CHOICE
  289.         elif [ -d $1 ] && [ -z $2 ]; then
  290.             TARGET_DIR="$1"
  291.             GET_TARGET_FILESIZE
  292.             GET_FILECOUNTER_CHOICE
  293.             CHECK_FILECOUNTER_CHOICE
  294.         fi
  295.     fi
  296. fi
  297. CHECK_TARGET_DIR_EXISTS
  298. DIR_SIZE="$(du -h $TARGET_DIR 2>/dev/null | tail -1 | awk '{print $1}')"
  299. mkdir -p /root/support/logs/sfs_logs
  300. clear
  301. HEADER
  302. SEARCH 2>&1 | tee searchfile
  303. sed -i -e 's/[\x01-\x1F\x7F]//g' -e 's|\[1m\[32m||g' -e 's|(B\[m||g' -e 's|\[1m\[34m||g' -e 's|\[2A\[K||g' -e 's|\[1m\[37m||g' -e 's|\[0m||g' searchfile
  304. PASTE searchfile
  305. mv searchfile /root/support/logs/sfs_logs/sfs_"$HOSTNAME"_"$(date +"%m-%d-%Y_%T")"
  306. printf "\n\n"
  307.  
  308. #######################
  309. ##-------------------##
  310. ## END - CORE SCRIPT ##
  311. ##-------------------##
  312. #######################
  313.  
  314. exit 0

Replies to sfs.sh rss

Title Name Language When
Xiaomi redmi 1s pc suite in english free download Anonymous bash 10 Months ago.
Hack-e-mail 3 скачать бесплатно Anonymous bash 10 Months ago.
Meghan trainor no mp3 download stafaband Anonymous bash 10 Months ago.
Zeus pan olimpu download pl torrent Anonymous bash 10 Months ago.
Microsoft office for mac free download full versio Anonymous bash 10 Months ago.
Sql для чайников 7-е издание скачать Anonymous bash 10 Months ago.
Nokia x2-02 прошивка модифицированная Anonymous bash 10 Months ago.
Password txt torrentsgames org Anonymous bash 10 Months ago.
Swansoft cnc simulator crack free download Anonymous bash 10 Months ago.
Pokemon ruby english rom download Anonymous bash 10 Months ago.
E-capture 601wd драйвер скачать Anonymous bash 10 Months ago.
Delux keyboard driver Anonymous bash 10 Months ago.
Wdmarvel key Anonymous bash 10 Months ago.
The fisherman and his soul краткое содержание Anonymous bash 10 Months ago.
Zz ward til the casket drops 320 torrent Anonymous bash 10 Months ago.

Reply to "sfs.sh"

Here you can reply to the paste above

A PHP Error was encountered

Severity: Core Warning

Message: Module 'imagick' already loaded

Filename: Unknown

Line Number: 0

Backtrace: