Beruflich Dokumente
Kultur Dokumente
# ./for.sh
one
two
three
while
#!/bin/sh
#
# An example of using while to wait for a file to exist
#
SpecialFile="${1:-/tmp/BeginAutoTask}"
[ -f $SpecialFile ] && FileCheck=true
echo "Watching for $SpecialFile to show up"
while [ "$FileCheck" != "true" ]; do
[ -f $SpecialFile ] && FileCheck=true
echo -e ".\c"
sleep 10
done
echo "$SpecialFile Exists now, running the one time process.."
rm $SpecialFile
#
# Insert Automated Process Here
#Eg:
# Suspend
# Update
# Resume
#
echo
ExitCode=$?
if [ $ExitCode -ne 0 ]; then
echo "An Error may have occurred"
else
echo "The Process was Successful"
fi
case
#!/bin/sh
#
echo "This is the Server menu:
1) sc58lsigp01
2) sc58lsigp02
3) sc58lsigp03
4) sc58lsigp04
"
echo -e "Which server would you like to log into? [1] \c"
read Variable
#
case $Variable in
2) Server=sc58lsigp02;;
3) Server=sc58lsigp03;;
4) Server=sc58lsigp04;;
1|*) Server=sc58lsigp01;; # Default Last
esac
#
echo "Logging into $Server"
#
ssh $Server
read
#!/bin/sh
#
# The read command is used to assign user responses to variables
#
echo "Waiting for your answer..."
read Response
echo
echo "Thank you, you entered $Response"
#
echo -e "\nWould you like to interact some more? [y] \c"
read Answer
if [ "$Answer" = "" -o "$Answer" = "y" ]; then
# Put more functionality here
echo "I am not programmed to continue with this dialogue yet."
#
else
echo "I understand, nothing personal. Have a good day!"
fi
expr
#!/bin/sh
#
# The expr utility can be used to use arithmetic equations on variables which are
numbers.
#
Base=${1:-10}
Add=${2:-5}
Total=`expr $Base + $Add`
#
echo "$Base + $Add = $Total"
# ./expr.sh
10 + 5 = 15
# ./expr.sh 20
20 + 5 = 25
# ./expr.sh 20 32
20 + 32 = 52
test and set -x
#!/bin/sh
#
# test is a command to determine if a value is successful
# in shell, test is actually the left square bracket [
#
# set -x can be used to display code execution
# and can be turned back off with set +x
set -x
#
parmOne=${1:-true}
parmTwo=${2:-true}
#
[ "$parmOne" = "$parmTwo" ] && echo "$parmOne is equal to $parmTwo"
#
set +x
#
test "$parmOne" != "$parmTwo" && echo "$parmOne is not equal to $parmTwo"