Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Shell Scripting

Shell Scripting

Shell scripting is the process of writing lists of commands to be run as a macro from a computer's shell ( or Terminal). These can contain any executable function, as well as a few others, that you would normally run in a Terminal. Once completed these macros can be instructed to run automatically upon different system events or times to help you to automate your life.

Jason Merlo

April 28, 2015
Tweet

Other Decks in Programming

Transcript

  1. .sh

  2. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  3. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  4. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  5. #!/bin/bash #check for arguments if [ “$#” -lt 2 ]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  6. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  7. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  8. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  9. #!/bin/bash #check for arguments if [[ $# -lt 2 ]]

    ; then echo "$0: illegal number of params" echo "usage: [dest folder] [backup dirs...]" exit 1 fi …
  10. … create_backup () { #archive file name archive="$host-$day-$1.tgz" #print start

    message echo echo "Backing up $1 to $dest_folder/$archive” echo #compress files using tar tar czvf "$dest_folder/$archive" "$1" } …
  11. … create_backup () { #archive file name archive="$host-$day-$1.tgz" #print start

    message echo echo "Backing up $1 to $dest_folder/$archive” echo #compress files using tar tar czvf "$dest_folder/$archive" "$1" } …
  12. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  13. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  14. … count=0 for folder in “$@" do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  15. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  16. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  17. … count=0 for folder in "$@"; do test $count -eq

    0 | | (create_backup $folder) count+=1 done …
  18. time=$(date “+%H”) case $time in [6-10]) echo “morning”;; [11-5]) echo

    “day”;; [6-10]) echo “evening”;; *) echo “night”;; esac