Bashforsysadmins-Scriptlistingbyfile 1470005386
Bashforsysadmins-Scriptlistingbyfile 1470005386
/bin/more
==============================
SCRIPT NAME: arrayex.sh
==============================
#!/bin/bash
# simple array list and loop for display
clear
case $MENUCHOICE in
1)
echo "Congratulations for Choosing the First Option";;
2)
echo "Choice 2 Chosen";;
3)
echo "Last Choice Made";;
*)
echo "You chose unwisely";;
esac
==============================
SCRIPT NAME: checkargs2.sh
==============================
#!/bin/bash
USERNAME=$1
PASSWORD=$2
echo "The following Username is $USERNAME and Password is $PASSWORD"
==============================
SCRIPT NAME: comments.sh
==============================
#!/bin/bash
# This line is intended to be used as a general description of the script
# and anything that it does
echo "We are using the default user called: $MYUSERNAME" # display to the
console
DATETIMESTAMP=`date`
echo "This is when the script was run: $DATETIMESTAMP" # this is the
timestamp of run
==============================
SCRIPT NAME: env.sh
==============================
#!/bin/bash
clear
cd $DIRECTORY 2>/dev/null
expr 1 + 5
echo $?
rm doodles.sh
echo $?
expr 10 + 10
echo $?
==============================
SCRIPT NAME: execops.sh
==============================
#!/bin/bash
# execution operators example
expr 2 + 2
expr 2 + 2 \* 4
expr \( 2 + 2 \) \* 4
==============================
SCRIPT NAME: ex.sh
==============================
#!/bin/bash
exec 5<>$FILE
exec 5>&-
==============================
SCRIPT NAME: forsample.sh
==============================
#!/bin/bash
# this is a demo of the for loop
SHELLSCRIPTS=`ls *.sh`
# global variable
USERNAME=$1
# scrip - start
clear
# displays a message
funcExample () {
echo "This is an example"
}
funcExample2
funcExample
funcExample
==============================
SCRIPT NAME: ifexpr.sh
==============================
#!/bin/bash
# test multiple expressions in single if statement
FILENAME=$1
IFS="$DELIM"
clear
DOCFILE="script_listing"
echo "#!/bin/more" > "$DOCFILE"
rm tmplisting.txt
==============================
SCRIPT NAME: nested.sh
==============================
#!/bin/bash
# demo of nested functions and some abstraction
# global variable
GENDER=$1
echo "A Human has $ARMS arms and $LEGS legs - but what gender are we?"
echo ""
funcMale () {
BEARD=1
echo "This man has $ARMS arms and $LEGS legs, with $BEARD
beard(s)..."
echo ""
}
funcFemale () {
BEARD=0
echo "This woman has $ARMS arms and $LEGS legs, with $BEARD
beard(s)..."
echo ""
}
}
# function definitions - stop
# script - start
clear
echo "Determining the characteristics of the gender $GENDER"
echo ""
# global variables
TMPFILE="tmpfile.txt"
TMPFILE2="tmpfile2.txt"
# script - start
echo "Write something to tmp file for later use..." > $TMPFILE
echo "Write something to tmp file 2 for later user..." > $TMPFILE2
# script - stop
==============================
SCRIPT NAME: overriding.sh
==============================
#!/bin/bash
# override/trap the system exit and execute a custom function
# global variables
TMPFILE="tmpfile.txt"
TMPFILE2="tmpfile2.txt"
# script - start
echo "Write something to tmp file for later use..." > $TMPFILE
echo "Write something to tmp file 2 for later user..." > $TMPFILE2
# script - stop
==============================
SCRIPT NAME: readfile.sh
==============================
#!/bin/bash
# simple file reading (non-binary) and displaying one line at a time
echo ""
echo "Your Full Name is: $FIRSTNAME $LASTNAME"
echo ""
echo "Enter Your Age: "
read USERAGE
echo "In 10 Years, You will be `expr $USERAGE + 10` years old."
==============================
SCRIPT NAME: returnval.sh
==============================
#!/bin/bash
# demo of return values and testing results
# global variable
YES=0
NO=1
FIRST=$1
SECOND=$2
THIRD=$3
# script - start
funcDisplayDialogMenu
# script - stop
==============================
SCRIPT NAME: simplefunc.sh
==============================
#!/bin/bash
# this is a simple function example
echo "Starting the function definition..."
funcExample () {
echo "We are now INSIDE the function..."
}
funcExample
==============================
SCRIPT NAME: simpleif.sh
==============================
#!/bin/bash
# simple if script for guessing a number
if [ $GUESS -eq 3 ]
then
echo "You Guessed the Correct Number!"
fi
==============================
SCRIPT NAME: simpleinfobox.sh
==============================
#!/bin/bash
# demo of a simple info box with dialog and ncurses
# script - start
# script - stop
==============================
SCRIPT NAME: simpleinputbox.sh
==============================
#!/bin/bash
# simple demo of an input dialog box
# script - start
# script - stop
==============================
SCRIPT NAME: simplemsgbox.sh
==============================
#!/bin/bash
# demo of a message box with an OK button
# script - start
if [ "$1" == "shutdown" ]; then
funcDisplayMsgBox "WARNING!" "Please press OK when you are ready to
shut down the system" "10" "20"
echo "SHUTTING DOWN NOW!!!"
else
funcDisplayMsgBox "Boring..." "You are not asking for anything fun..."
"10" "20"
echo "Not doing anything, back to regular scripting..."
fi
# script - stop
==============================
SCRIPT NAME: substitution.sh
==============================
#!/bin/bash
# This script is intended to show how to do simple substitution
shopt -s expand_aliases
alias TODAY="date"
alias UFILES="find /home -user user"
TODAYSDATE=`date`
USERFILES=`find /home -user user`
A=`TODAY`
B=`UFILES`
FILENAME=$1
echo "Testing for the Existence of a File called $FILENAME"
if [ ! -f $FILENAME ]
then
echo "File $FILENAME Does NOT Exist!"
fi
==============================
SCRIPT NAME: test.sh
==============================
#!/bin/bash
clear
clear
clear
done
==============================
SCRIPT NAME: varexample.sh
==============================
#!/bin/bash
MYUSERNAME="username"
MYPASSWORD="password123"
STARTOFSCRIPT=`date`
ENDOFSCRIPT=`date`
# script - start
clear
funcExample
echo ""
echo "Function has been called..."
echo ""
echo "GLOBAL variable = $GLOBALVAR (after the function call)"
echo "LOCALVAR variable = $LOCALVAR (after the function call)"
==============================
SCRIPT NAME: whilesample.sh
==============================
#!/bin/bash
# while loop example
echo "Enter the number of times to display the 'Hello World' message"
read DISPLAYNUMBER
COUNT=1