Open main menu

CDOT Wiki β

Changes

OPS435 Lecture 5 - Bash

969 bytes added, 14:50, 9 February 2016
no edit summary
* Combining everything we learned so far
* Scripts from [[OPS335_Weekly_Schedule | OPS335 Labs]]
 
= In-class examples =
 
forloop.sh:
 
<source lang="bash">
#!/bin/bash
 
VAR=one
echo $VAR
VAR=two
echo $VAR
 
#for I_LIKE_VARIABLES in {0..100}
#for I_LIKE_VARIABLES in `seq 100`
for I_LIKE_VARIABLES in a b c
do
echo "Var is now: "$I_LIKE_VARIABLES
done
</source>
 
findinlogs.sh:
 
<source lang="bash">
#!/bin/bash
 
echo "I will now extract all of these files: "
cd logs
#ls cs-ssl*.bz2
 
for FILE in `ls cs-ssl*.bz2`
do
echo "Now working on $FILE"
#bunzip2 -k $FILE
bunzip2 < $FILE > /tmp/`basename $FILE .bz2`
done
 
#bunzip2 < $CHOSENNAME > `basename $CHOSENNAME .bz2`
</source>
 
wait.sh:
 
<source lang="bash">
#!/bin/bash
 
while sleep 1
do
echo "I'm still here"
if [[ `mount | grep sdb1 | wc -l` = 1 ]]
then
# If I got here - my USB stick is mounted
# Now figure out where it's mounted:
MOUNT_DIR=`mount | grep sdb1 | cut -f 3 -d' '`
cp $0 $MOUNT_DIR
echo "Copied self to $MOUNT_DIR, will now exit bye bye"
exit
fi
done
</source>