Table of Contents

11/18/14

New Project: Time Online

- Accept via command-line argument, or user input if no arg, the desired user name to process.

- Validate that the indicated user exists, proceed only if/when ok.

- For each month of the semester determine: Number for that month Total time spent on the system that month in days hours mins Number of logins for histogram

last

lastlog

11/13/14

Cron Tab

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#   
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#   
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#  
# m h  dom mon dow   command
0 1 * * * ps aux > .temp/psauxdat
crontab -l shows cron table
crontab -e edit cron table 

AT command

at 16:26
ls > out
ctrl-d

OTHER COMMANDS

last

11/11/14

Scripting Optimization

whereis status

status: /usr/local/bin/status /usr/local/bin/status.logic

-rwxr-x--- 1 root lab46    105 Sep  9 11:26 status
-rwxr-x--- 1 root lab46    936 Sep 25 14:40 status.logic

lab46:Tue Nov 11:/usr/local/bin$ cat status
#!/bin/bash
#
# status - status.logic wrapper
#
sg ${USER} -c "/usr/local/bin/status.logic ${*}"

./myscript a b c

$# -count of arguments "3"
$* -all your arguments "a b c"
$0 -script name
$1 -"a"
$2 -"b"
$3 -"c"

status unix > output

status unix > ~/temp/output

rm -f output

if [ -e "~/temp/output" ]; then
    status unix > ~/temp/output
    
stat output | grep 'Modify' | sed 's/^Modify://g'

ftime=`date -d "$(stat output | grep 'Modify' | sed 's/^Modify://g')" +%s`

date +%s

-date +%s

time

ctime=`date +%s`
let dtime=$ctime-$ftime
echo $dtime

at 

cron/crontab

11/06/14

More RegEx

Sed

status unix | grep opus | egrep 'week([02468]|[0-9][02468])'

status unix | grep opus | grep 'week[02468]'

status unix | grep 'opus' | sed 's/^.*\([01]\):\([a-z][a-z]*\):\(week\)\([0-9]\)\(.*\)$/\5 for \3 \4 \2 [\1]/g'

11/04/14

Wildcards

? -match any single character

[] -characters match any of these enclosed characters

* -match 0 or more of anything

[^] -do not match any of these enclosed characters

Regular Expressions(RegEx)

. -match any single character
* -0 or more of the previous
[] -char class match one of enclosed
[^] -do not match one of enclosed
\< -matches start of word
\> -match end of word
^ -match start of line
$ -match end of line 

Extended RegEx

| Or
( ) grouping ---> \( \) "SED"
+ match 1 or more of the previous

Examples

cat words | grep  '^....$' | wc -l
cat words | grep '[aeiouy].*[aeiouy].*[aeiouy]' | wc -l
cat words | grep '[^A-F]' | wc -l

egrep=grep+moar

fgrep–>fast grep, no regex

11/01/14

Kind of researching favorite commands by unix users.

man 7 ascii -A nice built in ascii table

Ctrl+U - Cut the current line Ctrl+Y - Paste a line cut with Ctrl+U Ctrl+L - Clear the screen and redraw the current line Ctrl+G - Get a new line and abandon the current one CTRL+R in BASH for searching/activating previously executed commands

apropos - search the manual page names and descriptions “Thanks Hass”

diff - compare files line by line

“cd -” returns you to the previous directory

10/28/14

echo "$(echo "(6/7)*100"|bc -l|cut -c|-5)%"
$`()`

Scripting Project

take status output

Display this stuff.

Class Notes 10/23/14

Data proc review

cat data | grep 2 | wc -l

BC and scripting

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

fi
let total=$total+1
done
echo "Out of $total numbers, there are $evens even numbers"
exit 0   

The mysterious output.

Out of 20 numbers, there are 7 even numbers

Class Notes 10/21/14

Sudo random numbers

echo $RANDOM

Command Expansions

\ \

$( )

$(( ))

modulus division remainder integer division

34%5=4
34/5=6

echo $(( $RANDOM%100 ))

0-99

              MAX-MIN  MIN
echo $((( $RANDOM%100 )+1))

0-100

VIM .sh “Guessing Game”

#!/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

exit 0
elif [ "$number" -lt "$choice" ]; then

else

fi
let guess=$guess+1

done

exit




lab46:Tue Oct 21:~$ bash what.sh 
Guess a number: 50
Lower
Guess a number: 25
Lower
Guess a number: 10
Lower
Guess a number: 5
Lower
Guess a number: 4
Lower
Guess a number: 3
This is correct!

NOW COMPLETE WITH CHEAT MODE!

#!/bin/bash
choice=$((($RANDOM%100)+1))
echo $choice
guess=0
93
Guess a number: 93
This is correct!

Class Notes 10/07/14

ls -a : list all do not ignore entries starting with .

alias : customize commands and their default arguments

alias bob='echo boo'

$bob boo

PS1= : Prompt pimping PS1='\h:\w\$ '

mkdir -p jklsfjdklsjdkljflkjkl/sfjdklfjdkljfasd/jsdlasfdasfdafas/

rm -rf remove with recursive force

Environment Variables

PATH=$op

op=$PATH

Edit the .bashrc file to modify terminal session (aliases)

SHELL SCRIPTS

myscript.sh or .bash

to run!

bash myscript.sh

./myscript.sh

#!/bin/bash

“sh-bang”

echo -n “What is your name? ” read name echo “Hello, $name,nice to meet you”

-gt -ge -lt -le -ne -eq

Class Notes 10/07/14

Command: tag>ls -l /bin/ls

Process: Program in action

PID: Process identification - 16 bit value - Fork bomb used up all the process IDs

Command: ps - shows current processes

cat - continuous running process of cat

kill -l PID , -HUP PID, kill pid

fms - Find my screen

ps aux|grep $USER

top

bash -bourne again shell

sh -bourne shell

csh -C shell

BSD LSD SYSTEMV SYSVR6

jobs: list of stopped jobs

bg - runs stopped process in background fg - runs stopped process in foreground

Purposeless

I'm not entirely in the mood to write about unix at the moment. So, I will share some musings with you.

Let's see here I woke up this morning dreading the thought of going to work. (Perusal) However, I must do my service to my country by slinging Pennsylvanians wine.

Arriving at the front door of my workplace I then switch gears, becoming happy and go lucky. “Hi, how y'all today?” The first innocent group of people to meet my eye. I than began to regurgitate customer service banter. “Five wines for five dollars, or you can try as many as you'd like until you're visibly intoxicated.” Y'know the painful cheesy joke or two that gets em going. Next I begin to tell them about the wondrous wonders of my place of employ. Before you know it I'm waste deep in customer service. I'm shouting at people I don't even know. People are shouting at me. People are walking in the door from places i didn't even know existed. I mean where do all these people come from? Y'know really just coming out of the wood work. “Excusme me?” I turn around to see an old lady and what appears to be her special friend. “Yes? Can i help you” This lady and her friend had to be pushing centuries. “There's no toilet paper in the ladies rest room” :(

….To Be Continued….

PuzzleBox2

Definitely an eye opener, hehe. I have learned many things about myself probably way more than anyone would care to notice.

Bottom Line:Things aren't always as they seem and one should question their own logic often when trying to attempt a project like this.

This project took me way longer than it probably should have. Credit goes out to those who helped.

I also learned that there is multiple ways to skin a cat… Disregard the horrid expression, but all of those ways should be learned.

Within the next few weeks here i would really like to get into bash scripting to make certain tasks a little easier and less redundant.

I have so much to learn in this realm of GNU/Linux but i refuse to give up.

Archiving

Ohhhh my brain hurts…

Realizations: I did not realize that compression and archiving were to separate functionales, or rather i assumed they were the same thing.

I found it interesting how a lot of thought was put into optimizing how we store, transmit, and present data. As a result i am more curious about obscure file types.

Archiving: The act of taking multiple files and presenting them as one.

Compression: Taking a file and optimizing the amount of memory space it takes up (in some cases compressing while maintaining the integrity of the original document) or at times purposefully degrading the file for faster transmission.

These functions should be separate from one another especially in a unix enviroment. The philosophy being “do one thing and do that one thing really well”.

CHMOD for dummies

Sep, 10 2014

So… This is a second entry in hopes that Matt will expunge the fact that there was no opus update last week. *sighhhh*

After reading through Unix for the Beginning Mage i found a simpler way of setting file privileges though both techniques get the job done.

This technique being used by issuing chmod but instead of a 3 digit string like “666” you can use letters using simple addition and subtraction.

For Example,

Lets say a currently set file permission is -rwx rw rw or “766”. By issuing chmod with the letter argument go-r where g and o specify group and other “chmod go-r” The file permission string would now appear like this -rwx w w. The read permission was basicly subtracted from the picture. You can also use a for “all” instead of typing ugo “user” “group” “other” to specify all groups. For instance, chmod a-r.

Cheers!

Repository Fun

Sep, 10 2014

Recently been playing around with mercurial due to “structured”

Finally cloned my repositories over from bitbucket, which makes me very happy. :D

But, before i got there i was moving directories around and found that when deleting a cloned repository it is harder then you would think. Having to use rm -r -f “recursive force” to get rid of .hg in my wiki. Then starting over by re-cloning the repository. Not to mention .hg is hidden from issuing a regular ls command which had me feeling hopeless. Finally, issued ls -f and saw that .hg was hiding in there.

I leave you with this…

Screen Command

Aug,31 2014

Brief walk-through on the screen command.

Start screen program. “screen”

Screen functions as follows…

More…

This should spice things up a bit in your terminal screen, cheers.