daily pastebin goal
29%
SHARE
TWEET

Untitled

dipBRUR Jan 12th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. read -p 'Enter the destinaion directory which will be created in Desktop: ' dest1
  3. dest="$HOME/Desktop/$dest1"
  4. mkdir -v $dest
  5. if [ $? -ne 0 ]
  6. then
  7.     echo exiting...
  8.     exit 1
  9. fi
  10.  
  11. cp -r /etc/* $dest
  12.  
  13. if [ $? -eq 0 ]
  14. then
  15.     echo "copy successfull"
  16. else
  17.     echo "copy faliled!"
  18.     read -p 'Do you want to run copy as administrator?(y/n): ' oth
  19.     if [ $oth == "y" ]
  20.     then
  21.         sudo rm -rf $dest
  22.         msg=$(sudo mkdir -v $dest)
  23.         sudo cp -rf /etc/* $dest
  24.         if [ $? -eq 0 ]
  25.         then
  26.             echo "copy successfull."
  27.         else
  28.             echo "copy failed!"
  29.         fi
  30.     fi
  31. fi
  32.  
  33.  
  34.  
  35.  
  36. #!/bin/bash
  37. if [ $# -ne 1 ]
  38. then
  39.     echo "worng arguments!"
  40.     echo "Usage: $0 <'a directory name'>"
  41.     exit 1
  42. fi
  43.  
  44. dir=$1
  45. cd $dir
  46. if [ $? -eq 0 ]
  47. then
  48.     echo "biggest 5 files are:"
  49.     find $dir -maxdepth 1 -type f -printf "%s bytes %p\n" | sort -nr | head -n 5
  50.     echo ""
  51.     echo "most recently modified 5 files:"
  52.     find $dir -maxdepth 1 -type f -printf "%t %p\n" | sort -nr | head -n 5
  53. else
  54.     echo "$dir is not a directory or directory not present"
  55. fi
  56.  
  57.  
  58.  
  59. #!/bin/bash
  60. read -p 'Enter your age: ' age
  61. if [ $age -ge 16 ]
  62. then
  63.     echo "you are allowed to drink alcohol."
  64. else
  65.     echo "you are not allowed to drink alcohol."
  66.     echo -n "you have to wait another $((16 - $age)) year"
  67.     if [ $((16-$age)) -eq 1 ]
  68.     then
  69.         echo "."
  70.     else
  71.         echo "s."
  72.     fi
  73. fi
  74.  
  75.   echo "enter file"
  76.                read n
  77.                echo "enter your choice 1.zip
  78.                       2.bzip2
  79.                       3.compress "
  80.                read ch
  81.                if [ $ch -eq 1 ]
  82.                then
  83.                zip archieve1 $n
  84.                if [ $? -eq 0 ]
  85.                then
  86.                echo "successfully zipped"
  87.                else
  88.                echo "zip failed"
  89.                fi
  90.                fi
  91.                if [ $ch -eq 2 ]
  92.                then
  93.                bzip2 archieve2 $n
  94.                if [ $? -eq 0 ]
  95.               then
  96.               echo "successfully bzip"
  97.               else
  98.               echo "bzip2 failed"
  99.               fi
  100.               fi
  101.               if [ $ch -eq 3 ]
  102.               then
  103.               compress archieve3 $n
  104.               if [ $? -eq 0 ]
  105.               then
  106.               echo "successfully compressed"
  107.               else
  108.               echo "compress failed"
  109.               fi
  110.               fi
  111.  
  112.  
  113.  
  114.  
  115.  
  116. #!/bin/bash
  117.  
  118. ARG_NUM=$#
  119.  
  120. if [ $ARG_NUM -gt 0 ]
  121. then
  122.         echo "Usage: ./homebackup.sh "
  123.         exit
  124. fi
  125.  
  126.  
  127. FREE_SPACE=$(df /home/backup | tail -1|awk '{print $4}')
  128. echo Free Space: $FREE_SPACE
  129.  
  130. USER_CHOICE=0
  131.  
  132. BACKUP_FILE_NAME="backup"$(date +%Y-%m-%d)".tar.gz"
  133.  
  134. echo "Please input your choice:"
  135. echo "0,full backup"
  136. echo "1,incremental backup"
  137.  
  138. read USER_CHOICE
  139.  
  140. case $USER_CHOICE in
  141.  
  142. 0)
  143.         echo "start to backup in full mode"
  144. ;;
  145. 1)
  146.         echo "start to backup in incremental mode"
  147.         if [ -f "/home/backup/backup.tar.gz" ]
  148.         then
  149.                 LAST_BACK_TIME=$(stat /home/backup/backup.tar.gz |grep Modify|awk -F. '{print $1}' |awk '{print $2" "$3}')
  150.                 LAST_BACK_TIME=$(date -d "$LAST_BACK_TIME" +%s)
  151.                 NOW=`date -d "-7 day" +%s`
  152.                 if [ $LAST_BACK_TIME -gt $NOW ]
  153.                 then
  154.                         echo "You cannot do backup operation"
  155.                         echo "The last backup is on " $(date -d @"$LAST_BACK_TIME" +%Y-%m-%d)
  156.                         exit
  157.                 fi
  158.         fi
  159. ;;
  160. *)
  161.  echo "wrong operation"
  162.     exit
  163. ;;
  164. esac
  165.  
  166. tar -cvf $BACKUP_FILE_NAME *.sh
  167. BACK_UP_SIZE=$(ls -la $BACKUP_FILE_NAME|awk '{print $5}')
  168. if [ $BACK_UP_SIZE  -gt $FREE_SPACE ]
  169. then
  170.   echo "Insufficient space in /home/backup, it need $BACK_UP_SIZE bytes"
  171.   exit
  172. fi
  173.  
  174. mv $BACKUP_FILE_NAME /home/backup/backup.tar.gz
  175.  
  176.  
  177.  
  178. declare nos[5]=(4 -1 2 66 10)
  179.  
  180. #
  181. # Prints the number befor sorting
  182. #
  183. echo "Original Numbers in array:"
  184. for (( i = 0; i <= 4; i++ ))
  185. do
  186.   echo ${nos[$i]}
  187. done
  188.  
  189. #
  190. # Now do the Sorting of numbers
  191. #
  192.  
  193. for (( i = 0; i <= 4 ; i++ ))
  194. do
  195.    for (( j = $i; j <= 4; j++ ))
  196.    do
  197.       if [ ${nos[$i]} -gt ${nos[$j]}  ]; then
  198.            t=${nos[$i]}
  199.            nos[$i]=${nos[$j]}
  200.            nos[$j]=$t
  201.       fi
  202.    done
  203. done
  204.  
  205. #
  206. # Print the sorted number
  207. #
  208. echo -e "\nSorted Numbers in Ascending Order:"
  209. for (( i=0; i <= 4; i++ ))
  210. do
  211.   echo ${nos[$i]}
  212. done
  213.  
  214.  
  215.  
  216.  
  217.  
  218. #!/bin/bash
  219. echo -n "Enter number of integers: "
  220. read n
  221. sum=0
  222. cnt=1
  223. while [ $cnt -le $n ]
  224. do
  225.     echo -n "enter $cnt th number: "
  226.     read num
  227.     sum=$((sum+num))
  228.     cnt=$((cnt+1))
  229. done
  230. echo -n "agerave: "
  231. echo "$sum / $n" | bc -l
  232.  
  233.  
  234.  
  235. #!/bin/bash
  236. echo "Enter a number: "
  237. read number
  238. rev=0
  239. while [ $number -gt 0 ]
  240. do
  241.     rev=$((rev*10 + number%10))
  242.     number=$((number/10))
  243. done
  244. echo "reversed number: $rev"
RAW Paste Data
Top