File Test Options
| -b file | True if file exists and is a block special file |
| -c file | True if file exists and is a character special file |
| -d file | True if file exists and is a directory |
| -e file | True if file exists |
| -f file | True if file exists and is a regular file |
| -G file | True if file exists and is owned by the effective group ID |
| -g file | True if file exists and has SGID set |
| -k file | True if file exists and has its "sticky" bit set |
| -l file | True if file exists and is a symbolic link |
| -O file | True if file exists and is owned by effective ID |
| -p file | True if file exists and is a named pipe |
| -r file | True if file exists and is a readable |
| -S file | True if file exists and is a socket |
| -s file | True if file exists and has a size greater than zero |
| -u file | True if file exists and has SUID set |
| -w file | True if file exists and is writable |
| -x file | True if file exists and is executable |
| file1 -ef file2 | True if both files have the same device and inode numbers |
| file1 -nt file2 | True if file1 is newer (modification date) than file2 |
| file1 -ot file2 | True if file1 is older (modification date) than file2 |
- IF, WHILE, DO
if [ -z "$" ]; then
while [ -z "$" ]
do
....(some code)...
done
fi
- FOR, DO, DONE
for i in word1 word2 ...wordn
do
action involving $i (which = word)
done
- AWK & SED
NEW_VARIABLE="`/sbin/ifconfig -a|grep -A 2 eth0|awk '/inet/ { print $2 }'|sed -e s/addr://`"
- MAIL Notification
# build the Message & Subject variables
echo "No major canges in disk use on $HOSTNAME" > $MESSAGE
echo " " >> $MESSAGE
echo "`cat $DISKUSE`" >> $MESSAGE
echo "$HOSTNAME - Disk Space Report" > $SUBJECT
# send the message to address $EMAIL
echo "`cat $MESSAGE`" | mail -s "`cat $SUBJECT`" $EMAIL
- Test if File Exists with Non-Zero Size
if [ -s $DIFFTEST ] ;then
- Test for Exact Equal (of number value)
if [ $SCHEDULED == $ACTUAL ] ;then
- Get IP Address
# get external address from by greping ifconfig
EXIP="`ifconfig -a|grep -A 2 $EXIF|awk '/inet/ { print $2 }'\
|sed -e s/addr://`"
- Get Broadcast Address
EXBCAST="`ifconfig -a|grep -A 2 $EXIF|awk '/inet/ { print $3 }'\
|sed -e s/Bcast://`"
- Get DNS Server IP's
# get dns servers from resolv.conf file
# first line is path, next 3 are dns servers
NAMED1="`cat /etc/resolv.conf|grep -n nameserver|grep 2:\
|sed -e s/nameserver//|sed -e s/2://`"
NAMED2="`cat /etc/resolv.conf|grep -n nameserver|grep 3:\
|sed -e s/nameserver//|sed -e s/3://`"
NAMED3="`cat /etc/resolv.conf|grep -n nameserver|grep 4:\
|sed -e s/nameserver//|sed -e s/4://`"
- Remove Spaces from Filenames
for x in `ls -1|sed -e s/"\ "/_/g`;do mv "`echo $x|sed -e s/_/"\ "/g`" ${x};done