========week 8========
===10/21/2014===
==echo $RANDOM==
% Modulus
/ Division
34 % 5 = 4
34 / 5 = 6
Modulus is the remainder.
echo
‘ ‘
$( )
$(( ))
echo $(($RANDOM%100)) values 0-99
echo $(($RANDOM%100)+1)) values 1-100
#!/bin/bash
choice=$((($RANDOM%100)+1))
guess=0
while [ ”$guess” -lt 6 ];do
echo -n “Guess a number:”
read number
if [ “$number” -eq “$choice” ]; then
echo “You have correct now”
exit 0
elif [ “$number” -lt “$choice” ]; then
echo “Higher”
else
echo “Lower”
fi
let guess=$guess+1
done
exit 0
====10/23/2014====
cat data | grep ‘2’ | wc -l
bc = binary calculator
obase=16
quit
answer=’echo “2+2” | bc’
echo $answer
#!/bin/bash
total=0
evens=0
for number in `cat data`; do
evenchk=`echo "$number%2"|bc`
if [ "$evenchk" -eq 0 ]; then
let evens=$evens+1
fi
let total=$total+1
done
echo "Out of $total numbers, there are $evens even numbers."
exit 0
===take status output===
-calculate project points
-calculate opus points
-calculate attendance
-calculate project % -36%
-calculate opus % -36%
-calculate attendance % -28%
-calculate current grade
========week 9========
==10/28/2014==
echo “6/7” | bc -l
echo “(6/7)*100” | bc -l go to man bc*
echo “(6/7)*100” | bc -l | cut -d`.` -f1
echo "$(echo "(6/7)*100" | bc -l | cut -c1-5)%"
attendance - username
status unix | grep mgleaso7
===take data from horizontal to vertical===
Only one “Enter” at the end.
status unix | grep mgleaso7 | tr -s ' ' '\n'
^ new line
$ end of a line
grep -v ‘^$”
==status unix | grep mgleaso7 | tr -s ' ' '\n' | grep X | wc -l==
missed=$(status unix | grep mgleaso7 | tr -s ' ' '\n' | grep X | wc -l)
======Week 10======
=====Nov 4, 2014=====
===WildCards===
? - match any single char
[ ] - character class. match any one of the enclosed characters.
*- match 0 or more of anything inverted character class
===Regular Expressions (RegEx)===
. - match any single character
* - 0 or more of the previous char class
[^ ] - do not match one of the enclosed
\< - match start of word
\> - match end of word
^ - match start of line
$ - match end of line
===Extended RegEx===
| or
( ) grouping → \( \)
+ - match one or more of the previous.
cat words | grep '^[a-z][a-z][a-z][a-z]*$' | wc -l
cat words | grep '^.*[aeiouy].*[aeiouy].*[aeoiouy].*$' |wc -l
ccat words | egrep '(ed)$|(ing)$' | wc -l
egrep = grep + moar
fgrep = fast grep, no regex
=====11/6/2014=====
status unix | grep ‘opus’ | grep ‘week[02468]’
egrep ‘week([02468] | [0-9] [02468] )’
1 : opus : week2entry
| sed ‘s/^.*\([01]\):\([a-z][a-z]*\):\(week\)\([0-9]\)\(.*\)$/
getent passwd | grep '^[mg]' | sed 's/^\([a-z][a-z0-9]*\):x:\([0-9][0-9][0-9][0-9]\):5000:\(.*\):\/home.*$/\3 is user \1 with userid \2 /g'
======Week 11======
=====11/11/2014=====
*/4 **** /usr/bin/who
where is status
=====11/13/2014=====
at commands
at - executes command at specified time
atrm - deletes job by job number
at 16:16 - sets command at 4:16 Linux time
ls > out - command that will run at 4:16
atq - shows the list of commands that you set to run
crontab -e - lets you choose an editor to create a repeating command
*/4 * * * * /usr/bin/who - runs that command every 4 minutes of every hour, day, week, month
After a successful crontab command it should say: crontab: installing new crontab
last - shows when a user logged in
last | grep $USER | wc -l - shows how many times you logged in
last | grep $USER| grep Oct | wc -l - shows how many times you logged in October