Tuesday, September 18, 2007

OPS435 W3

OPS435W3
& - when you want to run any command or program in the background,

Foreground which u are running, running a program in the background you can have control while the foreground no

&& - com && com2 checks to see if the first command is successful then execute the second command.

Who | grep username

Com1 || com2 - || - not successful then execute this command

|| && is similar to if and else

Ls, who, pwd > f1

Use ( ) around commands that means you are grouping them together.

$(com1;com2) command substitution

(( )) – arithmetic expression – this is how the shell does arithmetic, this is used, for a couple of diff things, one arithmetic, also use the command to assign the results of a arithimitic function to a variable.

First put this a = 3 b=5
((c=b*a)) shows output

$((c=a*b)) shows standard output

echo $((a + $b*2))
u can use
+
-
*
%(remainder)
**(power of)
/
The shell does not care if it’s a variable name in this case when you don’t put the dollar sign infront it treats it as a variable name, this is a arithmetic command, everything inside it has to be numbers, since the shell knows, the moment it encounters text it says this must be a variable and replaces the variable name with the context, the shell automatically knows this, u may use it or not.

Echo $(( a**3 +b*6/3-1))

Display the remainder, this command is an integer number.


This week,

>> append
> replace

Pattern matching file name expansion,

Understanding Expansion

Echo Jim$d
JimBrown
Echo $dJim
Blank(nothing) no variable dJim

Echo {$d}Jim --use braces
{Brown}Jim

Appends the variable name within braces, leads us to the next item the braces can be used in many different forms to achieve many things
${var:offset:length}

This lets you cut poriotions of data from a file, we used cat for a variable and a file, this is a better way of doing it

Bd=19871223

Echo ${bd:0:4}

Echo my birth year is ${bd:0:4}

echo "The month of my birth is" ${bd:4:2}

Assignment will require you to do the following write s script anyone can use, the script will ask the user to enter the birthdate in the yyyymmdd and u take their birthday and tell them how many years month zodiac sign, Chinese anymore sign is, you are going to be using these formants and be doing all kinds of calculations to come up with the results.

Another thing you need to do , listen to this applies to every system, the following will apply, any time you ask the user for data, you never start using that data unless you verify it.

Before you start cutting out stuff u must verify the data is correct, so number one how many char do you except this data to be…8.... they have to be all numbers…check the date is valid.

This will tell u how many chars the data of a var contains,

Echo ${#bd}
# - tells you the

Echo puts a new line char at the end so you will get the wrong character, if you use the construct we have previously use it will be more correct,

Cover unique

Uniq unique

Sort unique | uniq -Cuts out the lines in ascending order

Uniq –d gives you the duplicate lines
Uniq –c – count how many lines exist in that data file

Cheat Sheet
Half a page of what you want, hand written.

Tr – translate, what this does it translates chars to this to this,

Tr abc 123 < galileo.txt

< input redirection

Every a = 1 b = 2 c=3

Tr ‘a-m0-4’ ‘n-z5-9’ Galileo.txt

All the capital letters will not be touched, the small letters will, pretend u have a file, u can change the data, so even if they get hold of the file its meaningless,

Tr ‘a-mA-M0-4n-zH-Z5-9’ ‘n-zN-Z5-9a-mH-M0-4’ < Galileo.txt > junk

Tr –d ‘%./.,fda?’ Galileo.txt
Deletes all the characters

That’s ur tr translate



The Find command,
Find [directory to search in] goes through every sub through that directory
Find .

Specify a search with specific items that have to be matched, for a file name,

Find . –name nameoffile

Find command does expansion not the shell, the find command can use regular expansion char, many capabilities, prevent the shell from interpreting f1* how do you prevent the shell, a backslash, single quotes, double quotes

Find . –name “name*” -type f –perm 600 –mtime 10 –exec rm –I {} \;

Type file, permissions 600, or greater 600 u put a +600, a minus for less in front of the 600

Also these files have to be more then ten days old in other words last time their were changed, they have to be ten days ago or more


-mtime 10 tend days +10 greater then 10 days, the find command has to match eatch and every one of them before it matches that file. Another one, -exec another command, rm –I interactively, {} represetnts standard output of the find command, ill show the full path will be redirecting into the braces, its going to delete all those files but first ask you, because its exec the find command it has to know where it ends, looking for ; to see where it ends but is that a special char to the shell ;, you don’t it to interpret as its own so you have a back slash.

Linux administrator on the weekend last Sunday you did a backup what you did u used a utility called backup, /bin/backup, tonight 3am you wanna do another back up a partial backup, you want to back up any files that have changed since the last backup.
Touch ts
Find

Chron utility to specify time sequence, this command will reside in a special file that the chron deamon looks at

Find / –newer ts –exec /bin/backup {} \;

Backup all new files

No comments: