Guest User

Script

a guest
Oct 10th, 2023
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.46 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. clearFiles() {
  4.   rm *.dat
  5.   if [ $? -eq 0 ]
  6.   then
  7.     echo Files deleted
  8.   fi
  9. }
  10.  
  11. genFiles() {
  12.   for (( i=1; i<=$1; i++ ))
  13.   do
  14.     head -c ${i}M </dev/urandom >myfile${i}mb.dat
  15.   done
  16.   ls -l *.dat
  17. }
  18.  
  19. delFiles() {
  20. for f in *.dat
  21.   do
  22.     size=$(( $(stat -c %s $f) /1024/1024 ))
  23.     if [ $size -gt $1 ]
  24.     then
  25.       rm $f
  26.       echo Deleted file $f
  27.     fi
  28.   done
  29.   ls -l *.dat
  30. }
  31.  
  32. showWeather() {
  33.   curl -s "https://weather-broker-cdn.api.bbci.co.uk/en/observation/rss/$1" | grep "<desc" | sed -r 's/<description>//g; s/<\/description>//g'
  34. }
  35.  
  36. menu() {
  37.   clear
  38.   echo 1 - Delete all .dat files
  39.   echo 2 - Generate .dat files
  40.   echo 3 - Delete big .dat files
  41.   echo 4 - List all files
  42.   echo 5 - Planet info
  43.   echo 6 - Show weather
  44.   echo "x/q - Exit"
  45.   echo -n "Choose action: "
  46.   read -n 1 key
  47.   echo
  48. }
  49.  
  50. while true
  51. do
  52.   case "$key" in
  53.     "x" | "q" | "X" | "Q") break ;;
  54.     "1")
  55.       clearFiles
  56.       read -n 1
  57.     ;;
  58.     "2")
  59.       echo -n "File count: "
  60.       read count
  61.       genFiles $count
  62.       read -n 1
  63.     ;;
  64.     "3")
  65.       echo -n "Delete file greater than (mb): "
  66.       read maxsize
  67.       delFiles $maxsize
  68.       read -n 1
  69.     ;;
  70.     "4")
  71.       ls -la
  72.       read -n 1
  73.     ;;
  74.     "5")
  75.       ./script4.sh
  76.       read -n 1
  77.     ;;
  78.     "6")
  79.       echo -n "Enter city code: " # 524901 498817 5391959
  80.       read citycode
  81.       showWeather $citycode
  82.       read -n 1
  83.     ;;
  84.   esac
  85.   menu
  86. done
Advertisement
Add Comment
Please, Sign In to add comment