├── cover.png ├── looplist.sh ├── loopinrange.sh ├── mp3towav.sh ├── loopwithstep.sh ├── ifstatement.sh ├── askingdatav2.sh ├── arrays.sh ├── askingdata.sh ├── casestatement.sh ├── custom-startup.sh ├── README.md ├── custom-shutdown.sh └── nestedifs.sh /cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SyncfusionSuccinctlyE-Books/Ubuntu-Server-Succinctly/HEAD/cover.png -------------------------------------------------------------------------------- /looplist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for number in 1 2 3 4 5 3 | do 4 | echo $number 5 | done 6 | exit 0 7 | -------------------------------------------------------------------------------- /loopinrange.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for number in {1..10} 3 | do 4 | echo "$number " 5 | done 6 | exit 0 7 | -------------------------------------------------------------------------------- /mp3towav.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for file in ./*.mp3 4 | do 5 | mpg -w ./wavs/"${file}".wav "$file" 6 | done 7 | -------------------------------------------------------------------------------- /loopwithstep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for number in {10..100..10} 3 | do 4 | echo "$number " 5 | done 6 | exit 0 7 | -------------------------------------------------------------------------------- /ifstatement.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Please enter type of fruit" 3 | read fruit 4 | 5 | if [ $fruit = apple ] 6 | then echo "Good, I like Apples" 7 | else echo "Oh no, I hate Oranges!" 8 | fi 9 | -------------------------------------------------------------------------------- /askingdatav2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | clear 3 | read -p "Please enter your name : " name 4 | echo "" 5 | read -p "Please enter your age : " age 6 | echo "" 7 | read -p "Please enter your sex. Male/Female : " sex 8 | echo "" 9 | echo "So you're a $age year old $sex called $name" 10 | -------------------------------------------------------------------------------- /arrays.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Declare array with 4 elements 3 | ARRAY=( 'Debian Linux' 'Redhat Linux' 'Ubuntu' 'Linux' ) 4 | # get number of elements in the array 5 | ELEMENTS=${#ARRAY[@]} 6 | 7 | # echo each element in array 8 | # for loop 9 | for (( i=0;i<$ELEMENTS;i++)); do 10 | echo ${ARRAY[${i}]} 11 | done 12 | -------------------------------------------------------------------------------- /askingdata.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | clear 3 | echo "Please enter your name" 4 | read name 5 | echo "Please enter your age" 6 | read age 7 | echo "Please enter your sex. Male/Female" 8 | read sex 9 | echo "So you're a $age year old $sex called $name" 10 | #Copy the file to the home directory and set permissions to executable 11 | -------------------------------------------------------------------------------- /casestatement.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "What is your preferred programming / scripting language" 3 | echo "1) bash" 4 | echo "2) perl" 5 | echo "3) phyton" 6 | echo "4) c++" 7 | echo "5) I do not know !" 8 | read lang; 9 | case $lang in 10 | 1) echo "You selected bash";; 11 | 2) echo "You selected perl";; 12 | 3) echo "You selected phyton";; 13 | 4) echo "You selected c++";; 14 | 5) exit 15 | esac 16 | -------------------------------------------------------------------------------- /custom-startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LOGFILE="/var/log/custom-start.log" 3 | TIMESTAMP=$(date +"%F %H:%M:%S") 4 | rm $LOGFILE 5 | exec 2>> $LOGFILE 6 | echo $TIMESTAMP >> $LOGFILE 7 | echo -e '\nnext command: ls /' >> $LOGFILE 8 | ls / >> $LOGFILE 9 | echo -e '\nnext command: ls /home' >> $LOGFILE 10 | ls /home >> $LOGFILE 11 | echo -e "\nnext command: ls /home/$USER/Desktop" >> $LOGFILE 12 | ls /home/$USER/Desktop >> $LOGFILE 13 | #Copy this file to /etc/init.d and set the file as executable 14 | #sudo chmod +x /etc/inid.d/custom-start.sh 15 | #Add this line to /etc/rc.local before "exit 0" 16 | #/etc/inid.d/custom-startup.sh 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ubuntu Server Succinctly 2 | 3 | This is the companion repo for [*Ubuntu Server Succinctly*](https://www.syncfusion.com/ebooks/Ubuntu_Server_Succinctly) by José Roberto Olivas Mendoza. Published by Syncfusion. 4 | 5 | Every file in the repo is a small bash script sample. 6 | 7 | Follow the instructions in each script to run it. 8 | 9 | [![cover](https://github.com/SyncfusionSuccinctlyE-Books/Ubuntu-Server-Succinctly/blob/master/cover.png)](https://www.syncfusion.com/ebooks/Ubuntu_Server_Succinctly) 10 | 11 | ## Looking for more _Succinctly_ titles? 12 | 13 | Check out the entire library of more than 130 _Succinctly_ e-books at [https://www.syncfusion.com/ebooks](https://www.syncfusion.com/ebooks). 14 | 15 | 16 | -------------------------------------------------------------------------------- /custom-shutdown.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | LOGFILE="/var/log/custom-exit.log" 3 | TIMESTAMP=$(date +"%F %H:%M:%S") 4 | rm $LOGFILE 5 | exec 2>> $LOGFILE 6 | echo $TIMESTAMP >> $LOGFILE 7 | echo -e '\nnext command: ls /' >> $LOGFILE 8 | ls / >> $LOGFILE 9 | echo -e '\nnext command: ls /home' >> $LOGFILE 10 | ls /home >> $LOGFILE 11 | echo -e "\nnext command: ls /home/$USER/Desktop" >> $LOGFILE 12 | ls /home/$USER/Desktop >> $LOGFILE 13 | 14 | #Copy the file to /etc/inid.d and set the file as executable. 15 | #sudo chmod +x /etc/init.d/custom-shutdown.sh 16 | #Add a symlink to call the script: 17 | #sudo ln -s /etc/init.d/custom-shutdown.sh /etc/rc0.d/K04custom-shutdown.sh 18 | #After a restart of the system you can check the logfiles: 19 | #cat /var/log/custom-exit.log 20 | #cat /var/log/custom-start.log -------------------------------------------------------------------------------- /nestedifs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Declare variable choice and assign value 4 4 | choice=4 5 | # Print to stdout 6 | echo "1. Bash" 7 | echo "2. Scripting" 8 | echo "3. Tutorial" 9 | echo -n "Please choose a word [1,2 or 3]? " 10 | # Loop while the variable choice is equal 4 11 | # bash while loop 12 | while [ $choice -eq 4 ]; do 13 | 14 | # read user input 15 | read choice 16 | # bash nested if/else 17 | if [ $choice -eq 1 ] ; then 18 | 19 | echo "You have chosen word: Bash" 20 | 21 | else 22 | 23 | if [ $choice -eq 2 ] ; then 24 | echo "You have chosen word: Scripting" 25 | else 26 | 27 | if [ $choice -eq 3 ] ; then 28 | echo "You have chosen word: Tutorial" 29 | else 30 | echo "Please make a choice between 1-3 !" 31 | echo "1. Bash" 32 | echo "2. Scripting" 33 | echo "3. Tutorial" 34 | echo -n "Please choose a word [1,2 or 3]? " 35 | choice=4 36 | fi 37 | fi 38 | fi 39 | done 40 | --------------------------------------------------------------------------------