This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:mcooper6:start [2013/01/19 13:50] – [Bash Scripting: Intro] mcooper6 | user:mcooper6:start [2013/02/04 20:59] (current) – [CLI] mcooper6 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP left 40%> | ||
+ | ~~TOC~~ | ||
+ | </ | ||
+ | // | ||
+ | // | ||
+ | <WRAP centeralign 90% bigger> | ||
+ | <WRAP bigger fgred>A Record of Sorts</ | ||
+ | <WRAP muchbigger> | ||
+ | ... one man's trip down the rabbit hole. | ||
+ | </ | ||
+ | <WRAP left 50%> | ||
+ | <WRAP info left 80% bgwhite> | ||
+ | You have stumbled upon Matt Cooper' | ||
+ | </ | ||
+ | </ | ||
+ | <WRAP clear></ | ||
+ | |||
+ | =====Hi, I'm Matt===== | ||
+ | <WRAP centeralign 100% fgred> | ||
+ | Drawing on my fine command of language, I said nothing. | ||
+ | <WRAP rightalign 75%>- Mark Twain</ | ||
+ | </ | ||
+ | |||
+ | Hi, I'm Matt, small business owner, husband, father and lately, student of computer science. | ||
+ | |||
+ | <WRAP info box bgwhite> | ||
+ | Here are some interesting things (you decide) about me: | ||
+ | *I don't laugh at bad jokes, but dry humor is damned funny. | ||
+ | *I yell at politicians on TV. (Everyone has to have that one crazy thing, this is mine.) | ||
+ | *I should probably relax. | ||
+ | *I referee NCAA soccer games. Yep, for fun! | ||
+ | *My Lab46 Web Home is [[http:// | ||
+ | </ | ||
+ | In my professional life I develop web applications and business systems for small businesses. | ||
+ | |||
+ | |||
+ | The other side of my life revolves around my family. | ||
+ | =====Chemistry===== | ||
+ | A hastily-thrown-together group of information that may help you memorize some things (as it did me): | ||
+ | *[[chemistry|Chemistry Resources]] | ||
+ | =====Computer Organization===== | ||
+ | *[[m6800|m6800 Simulator (Wiki)]] | ||
+ | *[[http:// | ||
+ | =====C Programming===== | ||
+ | ====Dealing Cards==== | ||
+ | In the game Freecell, cards are dealt into columns. | ||
+ | |||
+ | This first snippet deals out the tableus (that is the columns) by dealing 1 card per column for 8 columns until all 52 cards have been dealt. | ||
+ | < | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main(){ | ||
+ | |||
+ | int ctDeal=0; | ||
+ | |||
+ | int deal[8][52]; | ||
+ | |||
+ | int row, col; | ||
+ | |||
+ | // deal the cards | ||
+ | |||
+ | for(row = 0; row < 52; row++){ | ||
+ | |||
+ | for(col = 0; col < 8; col++){ | ||
+ | | ||
+ | deal[col][row] = ctDeal; | ||
+ | ctDeal++; | ||
+ | |||
+ | if(ctDeal > 52){ | ||
+ | col = 8; | ||
+ | row = 52; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | // show the deal | ||
+ | |||
+ | ctDeal = 0; | ||
+ | |||
+ | for(row = 0; row < 52; row++){ | ||
+ | |||
+ | for(col = 0; col < 8; col++){ | ||
+ | |||
+ | printf(" | ||
+ | ctDeal++; | ||
+ | |||
+ | if(ctDeal > 52){ | ||
+ | row = 52; | ||
+ | col = 8; | ||
+ | } | ||
+ | } | ||
+ | printf(" | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | Next, a short snippet that takes care of some random numbering and dealing out 13 cards from each suit: | ||
+ | |||
+ | < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main(){ | ||
+ | |||
+ | int ctSpades = 0; | ||
+ | int ctClubs = 0; | ||
+ | int ctHearts = 0; | ||
+ | int ctDiamonds = 0; | ||
+ | int ctDeal = 0; | ||
+ | |||
+ | srand(time(NULL)); | ||
+ | |||
+ | printf(" | ||
+ | |||
+ | int num, num2, row, col; | ||
+ | |||
+ | row = 0; | ||
+ | col = 0; | ||
+ | |||
+ | while(ctDeal < 52){ | ||
+ | |||
+ | num = rand() % 4+1; | ||
+ | |||
+ | switch(num){ | ||
+ | |||
+ | case 1: | ||
+ | |||
+ | if(ctClubs < 13){ | ||
+ | printf(" | ||
+ | ctClubs++; | ||
+ | ctDeal++; | ||
+ | } | ||
+ | break; | ||
+ | |||
+ | case 2: | ||
+ | |||
+ | if(ctSpades < 13){ | ||
+ | printf(" | ||
+ | ctSpades++; | ||
+ | ctDeal++; | ||
+ | } | ||
+ | |||
+ | break; | ||
+ | |||
+ | case 3: | ||
+ | |||
+ | if(ctHearts < 13){ | ||
+ | printf(" | ||
+ | ctHearts++; | ||
+ | ctDeal++; | ||
+ | } | ||
+ | break; | ||
+ | |||
+ | case 4: | ||
+ | |||
+ | if(ctDiamonds < 13){ | ||
+ | printf(" | ||
+ | ctDiamonds++; | ||
+ | ctDeal++; | ||
+ | } | ||
+ | break; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | The process is as follows: Fist, generate a random number between 1 and 4 (I.E. the number of suits in a deck of cards); next, a switch statement is hinged upon this random number and a counter for each suit is incremented. | ||
+ | |||
+ | |||
+ | =====Data Structures===== | ||
+ | *[[http:// | ||
+ | |||
+ | ====Linked List Insert==== | ||
+ | |||
+ | The linked list is a fairly complex idea that consists of a series of simple ideas. | ||
+ | |||
+ | < | ||
+ | /* | ||
+ | * linkedlist4.c - singly linked list node insertion | ||
+ | * | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // The node | ||
+ | struct node { | ||
+ | int value; | ||
+ | struct node *next; | ||
+ | }; | ||
+ | typedef struct node Node; | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | Node *start, *tmp, *devnull; | ||
+ | |||
+ | int i = 0, input = 0; | ||
+ | |||
+ | start = tmp = NULL; | ||
+ | |||
+ | do { | ||
+ | printf(" | ||
+ | scanf(" | ||
+ | |||
+ | if ((start == NULL) && (input != -1)) | ||
+ | { | ||
+ | start = (Node *) malloc (sizeof(Node)); | ||
+ | tmp = start; | ||
+ | tmp -> value = input; | ||
+ | tmp -> next = NULL; | ||
+ | } | ||
+ | else if (input != -1) | ||
+ | { | ||
+ | tmp -> next = (Node *) malloc (sizeof(Node)); | ||
+ | tmp = tmp -> next; | ||
+ | tmp -> value = input; | ||
+ | tmp -> next = NULL; | ||
+ | } | ||
+ | } while (input != -1); | ||
+ | |||
+ | tmp = start; | ||
+ | |||
+ | printf(" | ||
+ | while (tmp != NULL) | ||
+ | { | ||
+ | printf ("(%d) %d -> ", i, tmp -> value); | ||
+ | tmp = tmp -> next; | ||
+ | i++; | ||
+ | } | ||
+ | printf (" | ||
+ | |||
+ | tmp = start; | ||
+ | printf(" | ||
+ | scanf(" | ||
+ | |||
+ | for (i = 0; i < (input - 1); i++) | ||
+ | { | ||
+ | tmp = tmp -> next; | ||
+ | } | ||
+ | |||
+ | if ((i == 0) && (input == 1)) | ||
+ | { | ||
+ | i++; | ||
+ | } | ||
+ | |||
+ | printf(" | ||
+ | scanf(" | ||
+ | |||
+ | // Create new node | ||
+ | devnull = (Node *) malloc (sizeof(Node)); | ||
+ | devnull -> value = input; | ||
+ | |||
+ | if (i != 0) // anything but the first | ||
+ | { | ||
+ | devnull -> next = tmp -> next; | ||
+ | tmp -> next = devnull; | ||
+ | } | ||
+ | else // the first node | ||
+ | { | ||
+ | devnull -> next = start; | ||
+ | start = devnull; | ||
+ | } | ||
+ | |||
+ | tmp = start; | ||
+ | i = 0; | ||
+ | |||
+ | printf(" | ||
+ | while (tmp != NULL) | ||
+ | { | ||
+ | printf ("(%d) %d -> ", i, tmp -> value); | ||
+ | tmp = tmp -> next; | ||
+ | i++; | ||
+ | } | ||
+ | printf (" | ||
+ | |||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====Linked List Delete==== | ||
+ | < | ||
+ | /* | ||
+ | * linkedlist3.c - singly linked list node deletion | ||
+ | * | ||
+ | */ | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // The node | ||
+ | struct node { | ||
+ | int value; | ||
+ | struct node *next; | ||
+ | }; | ||
+ | typedef struct node Node; | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | Node *start, *tmp, *devnull; | ||
+ | |||
+ | int i = 0, input = 0; | ||
+ | |||
+ | start = tmp = NULL; | ||
+ | |||
+ | do { | ||
+ | printf(" | ||
+ | scanf(" | ||
+ | |||
+ | if ((start == NULL) && (input != -1)) | ||
+ | { | ||
+ | start = (Node *) malloc (sizeof(Node)); | ||
+ | tmp = start; | ||
+ | tmp -> value = input; | ||
+ | tmp -> next = NULL; | ||
+ | } | ||
+ | else if (input != -1) | ||
+ | { | ||
+ | tmp -> next = (Node *) malloc (sizeof(Node)); | ||
+ | tmp = tmp -> next; | ||
+ | tmp -> value = input; | ||
+ | tmp -> next = NULL; | ||
+ | } | ||
+ | } while (input != -1); | ||
+ | |||
+ | tmp = start; | ||
+ | |||
+ | printf(" | ||
+ | while (tmp != NULL) | ||
+ | { | ||
+ | printf ("(%d) %d -> ", i, tmp -> value); | ||
+ | tmp = tmp -> next; | ||
+ | i++; | ||
+ | } | ||
+ | printf (" | ||
+ | |||
+ | tmp = start; | ||
+ | printf(" | ||
+ | scanf(" | ||
+ | |||
+ | for (i = 0; i < (input - 1); i++) | ||
+ | { | ||
+ | tmp = tmp -> next; | ||
+ | } | ||
+ | |||
+ | if (i != 0) // anything but the first | ||
+ | { | ||
+ | devnull = tmp -> next; | ||
+ | tmp -> next = devnull -> next; | ||
+ | } | ||
+ | else // the first node | ||
+ | { | ||
+ | devnull = start; | ||
+ | start = devnull -> next; | ||
+ | } | ||
+ | devnull -> next = NULL; | ||
+ | free(devnull); | ||
+ | |||
+ | tmp = start; | ||
+ | i = 0; | ||
+ | |||
+ | printf(" | ||
+ | while (tmp != NULL) | ||
+ | { | ||
+ | printf ("(%d) %d -> ", i, tmp -> value); | ||
+ | tmp = tmp -> next; | ||
+ | i++; | ||
+ | } | ||
+ | printf (" | ||
+ | |||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | =====Dell Latitude D531 Wifi===== | ||
+ | *[[http:// | ||
+ | =====Mac===== | ||
+ | *[[http:// | ||
+ | |||
+ | =====Mathy Stuff===== | ||
+ | ====The Lab46 Math Pages==== | ||
+ | *[[http:// | ||
+ | *[[http:// | ||
+ | *[[http:// | ||
+ | ====LaTeX on the Lab46 Wiki==== | ||
+ | |||
+ | I asked for, and was awarded with the DokuWiki LaTeX plugin, with hopes that I would be able to find some extra time to explore some mathematic markup and ultimately find a digital den for my math notes. | ||
+ | |||
+ | Here's an example of a matrix: | ||
+ | |||
+ | < | ||
+ | < | ||
+ | D_z | ||
+ | = \left| | ||
+ | \begin{array}{ccc} | ||
+ | y_1 ... C_1\\ | ||
+ | \vdots \ddots \vdots\\ | ||
+ | y_2 ... C_2\end{array} | ||
+ | \right| -> z = \frac{D_z}{D} => y = \frac{(-4)(-55)-(14)(0)}{(-4)(-12)-(14)(5)} => z = -10 | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | This is the output of the above LaTex: | ||
+ | |||
+ | < | ||
+ | D_z | ||
+ | = \left| | ||
+ | \begin{array}{ccc} | ||
+ | y_1 ... C_1\\ | ||
+ | \vdots \ddots \vdots\\ | ||
+ | y_2 ... C_2\end{array} | ||
+ | \right| -> z = \frac{D_z}{D} => y = \frac{(-4)(-55)-(14)(0)}{(-4)(-12)-(14)(5)} => z = -10 | ||
+ | </ | ||
+ | |||
+ | Here's another one showing some simple math layouts | ||
+ | |||
+ | < | ||
+ | < | ||
+ | \begin{array}{3} | ||
+ | -5(3x - 3y + 2z = 11)\\ | ||
+ | \underline{+ 15x - | ||
+ | 14y - 12z = -55\\ | ||
+ | .\end{array}\\ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | This is the output of the above LaTeX | ||
+ | |||
+ | < | ||
+ | \begin{array}{3} | ||
+ | -5(3x - 3y + 2z = 11)\\ | ||
+ | \underline{+ 15x - | ||
+ | 14y - 12z = -55\\ | ||
+ | .\end{array}\\ | ||
+ | </ | ||
+ | |||
+ | As you can see, LaTeX isn't the easiest on the eyes. In fact, it's a little ugly. But it does something that can't be done easily on any platform, so you have to respect that. | ||
+ | |||
+ | ===Useful Links=== | ||
+ | *[[http:// | ||
+ | *[[http:// | ||
+ | |||
+ | =====Musings===== | ||
+ | <WRAP centeralign 100% fgred> | ||
+ | Diplomacy is the art of saying "Nice doggie" | ||
+ | <WRAP rightalign 75%>- Will Rogers</ | ||
+ | </ | ||
+ | |||
+ | ====A Political Suggestion==== | ||
+ | |||
+ | A Metaphor: | ||
+ | |||
+ | Since there are two groups: | ||
+ | |||
+ | -Group 1 believes that every citizen is entitled to a chicken and a mule. | ||
+ | -Group 2 believes that, since there are plenty of chickens and plenty of mules, then we should simply give each citizen the opportunity to earn their chicken and/or mule ... and therefore, if a citizen goes without a chicken and/or a mule, then they must not have wanted the chicken or the mule. | ||
+ | |||
+ | Further, since the laws of nature state that possession of said chickens and mules must, at some point, be earned. | ||
+ | |||
+ | Then, I suggest that the Group 1 get together and start earning chickens and mules, and then give them all away to the citizens that they believe are entitled to those chickens and mules. | ||
+ | ====A is for Curiosity==== | ||
+ | Having been asked the question, 'What do you think your grade should be?' by more than one professor, I've cataloged my response here to save time in the future. | ||
+ | |||
+ | > | ||
+ | |||
+ | =====Java Programming===== | ||
+ | *[[/ | ||
+ | =====PHP Programming===== | ||
+ | *[[http:// | ||
+ | |||
+ | The objective of the project is simply an exercise in learning a new (to me) programming language using a simple data set. The following .PHP file reads in a local (to Lab46) file containing a single line which holds the first million digits of pi. The line is split into pages of 100 groups of 64 digits (that is, 6400 digits per page). | ||
+ | |||
+ | <code php> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <meta http-equiv=" | ||
+ | < | ||
+ | |||
+ | <link rel=" | ||
+ | </ | ||
+ | < | ||
+ | <?php | ||
+ | | ||
+ | $chunk = 64; // size of data chunk | ||
+ | $nearby = 21; // number of nearby pages | ||
+ | /* | ||
+ | | ||
+ | | ||
+ | * | ||
+ | | ||
+ | | ||
+ | * | ||
+ | | ||
+ | * ($max_rows * $chunk * $page_num + $max_rows * $chunk > ftell(END) ? | ||
+ | * $max_rows * $chunk * $page_num) + ftell(END) - ($max_rows * $chunk * $page_num) | ||
+ | | ||
+ | */ | ||
+ | |||
+ | $i = 0; // iterator | ||
+ | $odd = 0; // number of odd digits per line | ||
+ | $max_odd = 0; | ||
+ | $even = 0; | ||
+ | $max_even = 0; | ||
+ | $sum = 0; | ||
+ | $max_sum = 0; | ||
+ | $primes = 0; | ||
+ | |||
+ | $zeros = 0; | ||
+ | $ones = 0; | ||
+ | $twos = 0; | ||
+ | $threes = 0; | ||
+ | $fours = 0; | ||
+ | $fives = 0; | ||
+ | $sixes = 0; | ||
+ | $sevens = 0; | ||
+ | $eights = 0; | ||
+ | $nines = 0; | ||
+ | |||
+ | $file_name = " | ||
+ | $f = fopen($file_name, | ||
+ | //ECHO TITLE | ||
+ | echo "< | ||
+ | |||
+ | // BEGIN PAGINATION (minimal use of variables) | ||
+ | |||
+ | $p = (int)$_GET[' | ||
+ | echo "< | ||
+ | |||
+ | // go to the place sought | ||
+ | fseek($f, $chunk*$max_rows*$p); | ||
+ | echo ($p > 1 ? "< | ||
+ | echo ($p > 0 ? "< | ||
+ | |||
+ | // loop nearby previous page lines | ||
+ | $n = ($p < 1 ? 0 : ($p < $nearby ? 0 : $p-$nearby )); | ||
+ | $limit = $p; | ||
+ | for($n; $n < $limit; $n++){ | ||
+ | echo "< | ||
+ | } | ||
+ | echo "< | ||
+ | |||
+ | // go to end | ||
+ | fseek($f, -$chunk*$max_rows, | ||
+ | |||
+ | // loop nearby next page lines | ||
+ | $n = $p+1; | ||
+ | $limit = ($p+$nearby < round(ftell($f)/ | ||
+ | for($n; $n <= $limit; $n++){ | ||
+ | echo "< | ||
+ | } | ||
+ | echo ($p < ftell($f)/ | ||
+ | echo ($p != round(ftell($f)/ | ||
+ | |||
+ | // back to the place sought | ||
+ | fseek($f, $chunk*$max_rows*$p); | ||
+ | echo "</ | ||
+ | |||
+ | // END PAGINATION | ||
+ | |||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | |||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | |||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "</ | ||
+ | echo "</ | ||
+ | echo "< | ||
+ | |||
+ | echo "< | ||
+ | echo "< | ||
+ | |||
+ | echo "</ | ||
+ | echo "< | ||
+ | $i = $p*$max_rows; | ||
+ | while (!feof($f) && $i < ($p*$max_rows+$max_rows)) { | ||
+ | $d = fread($f, $chunk); | ||
+ | $a = str_split($d); | ||
+ | foreach($a as $v){ | ||
+ | if($v % 2 == 0){ | ||
+ | $even++; | ||
+ | }else{ | ||
+ | $odd++; | ||
+ | } | ||
+ | $sum += $v; | ||
+ | |||
+ | switch($v){ | ||
+ | case 0: | ||
+ | $zeros++; | ||
+ | break; | ||
+ | case 1: | ||
+ | $ones++; | ||
+ | $primes++; | ||
+ | break; | ||
+ | case 2: | ||
+ | $twos++; | ||
+ | break; | ||
+ | case 3: | ||
+ | $threes++; | ||
+ | $primes++; | ||
+ | break; | ||
+ | case 4: | ||
+ | $fours++; | ||
+ | break; | ||
+ | case 5: | ||
+ | $fives++; | ||
+ | $primes++; | ||
+ | break; | ||
+ | case 6: | ||
+ | $sixes++; | ||
+ | break; | ||
+ | case 7: | ||
+ | $sevens++; | ||
+ | $primes++; | ||
+ | break; | ||
+ | case 8: | ||
+ | $eights++; | ||
+ | break; | ||
+ | case 9: | ||
+ | $nines++; | ||
+ | break; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | echo "< | ||
+ | |||
+ | echo "</ | ||
+ | $odd = 0; | ||
+ | $even = 0; | ||
+ | $sum = 0; | ||
+ | |||
+ | $zeros = 0; | ||
+ | $ones = 0; | ||
+ | $twos = 0; | ||
+ | $threes = 0; | ||
+ | $fours = 0; | ||
+ | $fives = 0; | ||
+ | $sixes = 0; | ||
+ | $sevens = 0; | ||
+ | $eights = 0; | ||
+ | $nines = 0; | ||
+ | $primes = 0; | ||
+ | |||
+ | $i++; | ||
+ | } | ||
+ | echo "</ | ||
+ | echo "< | ||
+ | fclose($f); | ||
+ | ?> | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | =====References & Resources===== | ||
+ | *[[/ | ||
+ | =====*NIX===== | ||
+ | |||
+ | ====alias==== | ||
+ | To get a list of all current alias' | ||
+ | <cli> | ||
+ | :~$ alias | ||
+ | </ | ||
+ | |||
+ | So, for example to make a change to your ls command, issue the following: | ||
+ | <cli> | ||
+ | :~$ alias ls='ls -color=auto -a' | ||
+ | </ | ||
+ | The previous command will cause ls to automatically show color and dot files. | ||
+ | |||
+ | Other useful alias commands: | ||
+ | |||
+ | Protect yourself from accidental overwrite when copying files: (-i for interactive) | ||
+ | <cli> | ||
+ | :~$ alias cp='cp -i' | ||
+ | </ | ||
+ | |||
+ | Do the same when moving files: | ||
+ | <cli> | ||
+ | :~$ alias mv='mv -i' | ||
+ | </ | ||
+ | |||
+ | And of course for removing files: | ||
+ | <cli> | ||
+ | :~$ alias rm='rm -i' | ||
+ | </ | ||
+ | ====aptitude==== | ||
+ | ===Finding Packages=== | ||
+ | Installing a package begins with aptitude search (that is, unless you already know the name). | ||
+ | |||
+ | <cli> | ||
+ | :~$ aptitude search mysql | ||
+ | </ | ||
+ | |||
+ | The above command returns a list of all packages containing the search phrase. | ||
+ | |||
+ | ===Installing packages=== | ||
+ | |||
+ | Installing packages requires the '' | ||
+ | |||
+ | <cli> | ||
+ | :~$ sudo aptitude install less | ||
+ | |||
+ | :~$ sudo aptitude install screen | ||
+ | </ | ||
+ | Other packages I've installed: | ||
+ | *irssi | ||
+ | *ngircd | ||
+ | |||
+ | The previous commands install the less and screen utilities. (which I installed during Linux class earlier this week.) | ||
+ | |||
+ | <WRAP info> | ||
+ | screen has many more uses than just running irssi. | ||
+ | </ | ||
+ | ===Installing apache server=== | ||
+ | |||
+ | I began by checking to see if Apache was already installed on vm34.student.lab. | ||
+ | |||
+ | <cli> | ||
+ | :~$ aptitude search apache | ||
+ | </ | ||
+ | |||
+ | At the top of the list is Apache2 " | ||
+ | |||
+ | <cli> | ||
+ | :~$ sudo aptitude install apache | ||
+ | </ | ||
+ | |||
+ | After installing Apache, you can check the install using telnet. | ||
+ | |||
+ | <cli> | ||
+ | :~$ telnet localhost 80 | ||
+ | </ | ||
+ | |||
+ | However, since telnet is not yet installed on vm34, issue the following command: | ||
+ | <cli> | ||
+ | :~$ aptitude install telnet | ||
+ | </ | ||
+ | |||
+ | Then have another go at the previous command. | ||
+ | |||
+ | ===Uninstalling packages=== | ||
+ | |||
+ | Uninstalling packages is only slightly different from installing: | ||
+ | |||
+ | <cli> | ||
+ | :~$ sudo aptitude remove nano | ||
+ | </ | ||
+ | |||
+ | The previous command uninstalls the nano editor. (not sure who ever needed this in the first place ... vi) | ||
+ | |||
+ | ====Bash Scripting: Intro==== | ||
+ | All you need to create a bash file is a text editor and a bash shell to run it. Start by creating a file with no extension: | ||
+ | |||
+ | <cli> | ||
+ | :~$ nano ./ | ||
+ | </ | ||
+ | |||
+ | OR | ||
+ | |||
+ | <cli> | ||
+ | :~$ touch ./ | ||
+ | </ | ||
+ | |||
+ | OR | ||
+ | |||
+ | <cli> | ||
+ | :~$ vi ./ | ||
+ | </ | ||
+ | |||
+ | After you've created your file, open it with your favorite text editor and get ready to add your bash script. | ||
+ | |||
+ | Begin by adding the following to your bash file: | ||
+ | |||
+ | <code bash> | ||
+ | #! /bin/bash | ||
+ | |||
+ | usr=`who | grep $USER` | ||
+ | |||
+ | echo $usr | ||
+ | </ | ||
+ | |||
+ | This short script creates a variable (in this case, named '' | ||
+ | <WRAP info bgwhite> | ||
+ | What's ''# | ||
+ | </ | ||
+ | |||
+ | Now simply change the file permissions and you can call your new bash script from the command line: | ||
+ | |||
+ | <cli> | ||
+ | :~$ chmod +x ./ | ||
+ | |||
+ | # ... $USER refers to your linux username. | ||
+ | </ | ||
+ | |||
+ | Now call it: | ||
+ | |||
+ | <cli> | ||
+ | :~$ ./ | ||
+ | </ | ||
+ | |||
+ | This example, while very simple, illustrates one of the many ways that users can use bash scripts to turn Linux into a multi-tasking machine. | ||
+ | |||
+ | <cli> | ||
+ | :~$ PATH=$PATH: | ||
+ | </ | ||
+ | |||
+ | The dot above is very important. To make sure you got it right: | ||
+ | |||
+ | <cli> | ||
+ | :~$ echo $PATH | ||
+ | </ | ||
+ | |||
+ | You should see your updates at the end of the list. Now, you can call your bash script by name, and bash will happily search through all the possible directories listed in $PATH until it finds your new utility. | ||
+ | |||
+ | <cli> | ||
+ | :~$ basherific | ||
+ | </ | ||
+ | |||
+ | Next, using the redirection operator ''>>'', | ||
+ | <cli> | ||
+ | echo $usr >> whoami.txt | ||
+ | </ | ||
+ | Save your file and run it. | ||
+ | |||
+ | <cli> | ||
+ | :~$ ./ | ||
+ | </ | ||
+ | |||
+ | Now '' | ||
+ | |||
+ | <cli> | ||
+ | :~$ cat ./ | ||
+ | </ | ||
+ | |||
+ | The contents of your new file will be the results of your bash script. | ||
+ | |||
+ | Lets have one more test. Let's have the bash script tell us if we were successful. | ||
+ | |||
+ | <cli> | ||
+ | file ./ | ||
+ | </ | ||
+ | |||
+ | This is a programmer friendly way check to make sure that the script actually did what it was told to do. However, as usual, there' | ||
+ | |||
+ | Comment out this line | ||
+ | <cli> | ||
+ | #file ./ | ||
+ | </ | ||
+ | Then add this: | ||
+ | <cli> | ||
+ | if [ -e ./ | ||
+ | echo " | ||
+ | else | ||
+ | echo " | ||
+ | fi | ||
+ | </ | ||
+ | |||
+ | Save and close your bash script. | ||
+ | |||
+ | <cli> | ||
+ | :~$ rm ./ | ||
+ | |||
+ | :~$ ./ | ||
+ | </ | ||
+ | |||
+ | You should receive a message stating that your venture was a success. | ||
+ | |||
+ | <cli> | ||
+ | #echo $usr >> whoami.txt | ||
+ | </ | ||
+ | |||
+ | Now, when the script is run, '' | ||
+ | |||
+ | <WRAP info bgwhite> | ||
+ | The ''>''''>'' | ||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## Append to a file | ||
+ | ## | ||
+ | |||
+ | :~$ echo $usr >> whoami.txt | ||
+ | |||
+ | ## | ||
+ | ## Overwrite a file | ||
+ | ## | ||
+ | |||
+ | :~$ echo $usr > whoami.txt | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | === Useful Links === | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | ====Bash Scripting: Practical Examples==== | ||
+ | ===Looping=== | ||
+ | < | ||
+ | |||
+ | while read LINE ; do | ||
+ | |||
+ | echo " | ||
+ | |||
+ | done < fall2010-20100315.html | ||
+ | |||
+ | </ | ||
+ | |||
+ | The above lines simply tell bash to read in another line from the file, as long as there are more lines to read. Once the file runs out of lines, the script is done. | ||
+ | |||
+ | In this case, the actual iterator is LINE, so we can output that by itself to get the actual line of text, however we can't count using this line as an iterator, and wouldn' | ||
+ | |||
+ | < | ||
+ | |||
+ | while read LINE ; do | ||
+ | |||
+ | | ||
+ | echo "$N : $LINE" | ||
+ | |||
+ | done < fall2010-20100315.html | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now the code outputs line numbers, which might or might not come in handy. | ||
+ | |||
+ | ===numtest=== | ||
+ | *Obtain 4 numbers from the user; in a variable called sum, store the sum of these 4 numbers. In a variable called product, store the product. Consider utilizing “bc” to assist you. | ||
+ | |||
+ | This script uses a '' | ||
+ | |||
+ | <file bash numtest> | ||
+ | #!/bin/bash | ||
+ | |||
+ | product=1 | ||
+ | for((i=0; | ||
+ | num=0 | ||
+ | echo -n "Enter number $i: " | ||
+ | read num | ||
+ | let sum=$sum+$num | ||
+ | let product=$(($product*$num)) | ||
+ | done | ||
+ | |||
+ | echo "sum is $sum" | ||
+ | echo " | ||
+ | </ | ||
+ | |||
+ | ===nametest=== | ||
+ | *Prompts the user for their name, stores it in a variable, and outputs that name along with its length in units of characters. | ||
+ | |||
+ | This bash script accepts the user's name and then outputs the name and the number of characters. | ||
+ | |||
+ | <file bash http:// | ||
+ | #!/bin/bash | ||
+ | |||
+ | # | ||
+ | # a program that propts for a name, counts the characters | ||
+ | # and outputs the results | ||
+ | |||
+ | echo -n " | ||
+ | read name; | ||
+ | |||
+ | chars=$((`echo $name | wc -c` - 1)) | ||
+ | |||
+ | echo "Your name is $name it has $chars characters" | ||
+ | </ | ||
+ | |||
+ | ===numguess=== | ||
+ | *Write a “guess the number” game that allows the user 4 chances to guess the number. | ||
+ | |||
+ | This script generates a random number between 1 and 10. The user is allowed to guess 4 times before the number is given. | ||
+ | |||
+ | <file bash http:// | ||
+ | #!/bin/bash | ||
+ | |||
+ | RANGE=10 | ||
+ | rand=$(($RANDOM%$RANGE)) | ||
+ | thisFlag=1 | ||
+ | tries=1 | ||
+ | while [ $thisFlag -eq 1 ] | ||
+ | do | ||
+ | |||
+ | echo "Guess a number between zero and ten " | ||
+ | read num | ||
+ | |||
+ | if [ $num -eq $rand ]; then | ||
+ | echo "Got it!" | ||
+ | thisFlag=0 | ||
+ | else | ||
+ | if [ $tries -gt 3 ]; then | ||
+ | echo "The number is $rand" | ||
+ | thisFlag=0 | ||
+ | else | ||
+ | echo " | ||
+ | fi | ||
+ | fi | ||
+ | tries=$(($tries+1)) | ||
+ | done | ||
+ | </ | ||
+ | ===stringtest=== | ||
+ | *Prompt the user for some text, store it in a variable. Convert any uppercase letters to lowercase and store that in a separate variable. Display the before and after. | ||
+ | |||
+ | I used the '' | ||
+ | <file bash http:// | ||
+ | #!/bin/bash | ||
+ | |||
+ | echo -n "Enter a string " | ||
+ | |||
+ | read theString | ||
+ | |||
+ | lower=`echo " | ||
+ | |||
+ | echo "You entered $theString" | ||
+ | echo "Lower case: $lower" | ||
+ | |||
+ | </ | ||
+ | ===logcount=== | ||
+ | *Write a script that counts how many times you've logged in this month. | ||
+ | This script is pretty short, in fact, it was taken from timebandit (see below). | ||
+ | <file bash http:// | ||
+ | #!/bin/bash | ||
+ | |||
+ | echo " | ||
+ | </ | ||
+ | ===filejoin=== | ||
+ | *Create two or three sample text files, and write a script that simulates a database-y operation (like SELECT, VIEW, or JOIN– not all, just pick one and do it, commenting on what that operation should do, and how you've accomplished it) | ||
+ | |||
+ | In this case, I first created a program that creates files. | ||
+ | |||
+ | After that, filejoin simply puts it all back together using the '' | ||
+ | ===filejoin=== | ||
+ | <file bash http:// | ||
+ | #!/bin/bash | ||
+ | |||
+ | paste -d- test_logfile1 test_logfile2 > test_logfile3 | ||
+ | |||
+ | </ | ||
+ | ===filemaker=== | ||
+ | <file bash http:// | ||
+ | #!/bin/bash | ||
+ | # | ||
+ | # a program that makes 2 files | ||
+ | |||
+ | last | grep -v 'still logged in' | grep -v 'gone - no logout' | ||
+ | |||
+ | last | grep -v 'still logged in' | grep -v 'gone - no logout' | ||
+ | |||
+ | </ | ||
+ | ===webtest=== | ||
+ | |||
+ | *Write a script that, when run, will download a web page and compare it to an existing, but older, copy of the webpage and displays any differences OR performs a line/word count; then rename the current copy to a backup, and remove the old backup in preparation for the next run- you might want to do this on some web page whose HTML output might change somewhat regularly (digg, slashdot, google news, etc.) | ||
+ | |||
+ | This script uses '' | ||
+ | |||
+ | After everything' | ||
+ | |||
+ | <file bash http:// | ||
+ | #!/bin/bash | ||
+ | |||
+ | wget http:// | ||
+ | |||
+ | n_count=`cat index.html | wc -l` | ||
+ | |||
+ | o_count=`cat index.html.BU | wc -l` | ||
+ | |||
+ | echo " | ||
+ | |||
+ | if [ $o_count -gt $n_count ]; then | ||
+ | |||
+ | echo "The web page has more lines now" | ||
+ | |||
+ | elif [ $o_count -lt $n_count ]; then | ||
+ | |||
+ | echo "The web page has less lines now" | ||
+ | |||
+ | else | ||
+ | |||
+ | echo "The web page has the same number of lines" | ||
+ | |||
+ | fi | ||
+ | |||
+ | echo "Old count is $o_count, the new count is $n_count" | ||
+ | echo " | ||
+ | cat index.html > index.html.BU | ||
+ | |||
+ | echo " | ||
+ | rm -rf index.html | ||
+ | |||
+ | echo " | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===timebandit=== | ||
+ | *Devise and implement a simple script of your own whose purpose is well-defined, | ||
+ | |||
+ | This scripts has some interesting points within. | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | @lab46:~$ ./ | ||
+ | |||
+ | @lab46:~$ ./ | ||
+ | |||
+ | </ | ||
+ | |||
+ | The logic is as follows: | ||
+ | *Check to see if there are command line arguments | ||
+ | *If there are command line arguments, use those usernames, otherwise get a list from the home directory | ||
+ | *After that, loop through the list of users and get each users days, hours and minutes. | ||
+ | *Loop through the list of days, hours and minutes to compress into the smallest possible (I.E. 120 min -> 2 hours .... 48 hrs -> 2 days) | ||
+ | *Next, use the final value of days, hours and minutes to control the loops that output the " | ||
+ | *When it's all done, reset the variables to zero and have another go at it. | ||
+ | |||
+ | <file bash http:// | ||
+ | # A program that uses the last utility to determine the time that | ||
+ | # each student is logged on for the current month | ||
+ | # This program can be invoked by passing the students username as | ||
+ | # an arguement, which returns the logged time for that student; | ||
+ | # or the program can be invoked with no arguments to retrieve a | ||
+ | # list of all users' logged time | ||
+ | |||
+ | |||
+ | # check to see if the program has been invoked with arguements | ||
+ | # if yes, use those username, if no use the entire class list | ||
+ | |||
+ | if [ -z " | ||
+ | users=" | ||
+ | else | ||
+ | users=" | ||
+ | fi | ||
+ | |||
+ | # loop through the list to retrieve logged times | ||
+ | for n in $users; do | ||
+ | |||
+ | days=" | ||
+ | |||
+ | hours=" | ||
+ | |||
+ | minutes=" | ||
+ | |||
+ | # loop through the list of hours, removing leading zeros | ||
+ | # and adding the remaining numbers together | ||
+ | for h in $hours;do | ||
+ | |||
+ | # check for ' | ||
+ | chk=`echo $h | grep ' | ||
+ | |||
+ | # | ||
+ | #days=0 | ||
+ | |||
+ | if [ $chk -eq 0 ]; then | ||
+ | # not more than 24 hours | ||
+ | h=" | ||
+ | else | ||
+ | |||
+ | # get the number of days, then add it up as d | ||
+ | days=" | ||
+ | let totaldays=$totaldays+$days | ||
+ | |||
+ | # use the logic above to get h | ||
+ | h=" | ||
+ | fi | ||
+ | |||
+ | # add the hours extracted to totalhrs | ||
+ | let totalhrs=$totalhrs+$h | ||
+ | let totaldays=$totaldays+0 | ||
+ | done | ||
+ | |||
+ | # loop through the list of minutes, removing leading zeros | ||
+ | # and adding the remaining numbers together | ||
+ | for m in $minutes;do | ||
+ | m=" | ||
+ | let totalmin=$totalmin+$m | ||
+ | done | ||
+ | |||
+ | |||
+ | # devide totalminutes by 60 to extract the number of hours | ||
+ | # add hours extracted to hrs and leave the remaining minutes in min | ||
+ | hrs=$(($totalmin/ | ||
+ | min=$(($totalmin-$(($hrs*60)))) | ||
+ | |||
+ | # add totalhrs to hrs | ||
+ | hrs=$(($hrs+$totalhrs)) | ||
+ | |||
+ | # devide hrs by 24 to extract days from hrs, then add totaldays to get final number of days | ||
+ | days=$(($hrs/ | ||
+ | hrs=$(($hrs-$(($days*24)))) | ||
+ | days=$(($days+$totaldays)) | ||
+ | |||
+ | for ((nn=0; nn< | ||
+ | dbar=$dbar" | ||
+ | done | ||
+ | |||
+ | for ((nnn=0; nnn< | ||
+ | hbar=$hbar"#" | ||
+ | done | ||
+ | |||
+ | for ((nnnn=0; nnnn< | ||
+ | mbar=$mbar" | ||
+ | done | ||
+ | |||
+ | echo " | ||
+ | |||
+ | bar=" | ||
+ | |||
+ | printf " %-8s | %-2s : %-2s : %-2s | %-2s %-2s %-2s \n" $n $days $hrs $min $dbar $hbar $mbar | ||
+ | |||
+ | #echo "$n | $days days : $hrs hours : $min min | $dbar $hbar $mbar" | ||
+ | #echo "$n | $h" | ||
+ | |||
+ | bar="" | ||
+ | hbar="" | ||
+ | dbar="" | ||
+ | mbar="" | ||
+ | totalmin=0 | ||
+ | totalhrs=0 | ||
+ | totaldays=0 | ||
+ | days=0 | ||
+ | hrs=0 | ||
+ | min=0 | ||
+ | done | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====.bashrc==== | ||
+ | |||
+ | Fun may be had with the ~/.bashrc file in your home directory. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | ## | ||
+ | ## automagically ls files after CD | ||
+ | ## | ||
+ | |||
+ | cdl() { | ||
+ | cd " | ||
+ | ls -Alh --color=auto; | ||
+ | } | ||
+ | |||
+ | alias cdl=cdl | ||
+ | |||
+ | ## | ||
+ | ## auto update in 3 chars ... remove the -y if you please | ||
+ | ## | ||
+ | |||
+ | alias upd=' | ||
+ | |||
+ | ## | ||
+ | ## move around the file system a bit more swiftly | ||
+ | ## | ||
+ | |||
+ | alias ..='cd ..' | ||
+ | alias .2='cd ../..' | ||
+ | alias .3='cd ../ | ||
+ | alias .4='cd ../ | ||
+ | alias .5='cd ../ | ||
+ | |||
+ | ## | ||
+ | ## get me home | ||
+ | ## | ||
+ | |||
+ | alias home=' | ||
+ | |||
+ | ## | ||
+ | ## edit those pesky priviliged files a bit faster | ||
+ | ## | ||
+ | |||
+ | alias svi=' | ||
+ | |||
+ | ## | ||
+ | ## give me more information ... but only when I want it | ||
+ | ## | ||
+ | |||
+ | alias lls=' | ||
+ | |||
+ | ## | ||
+ | ## show me what's open in a pinch | ||
+ | ## | ||
+ | |||
+ | alias ports=' | ||
+ | |||
+ | ## | ||
+ | ## edit the hosts file | ||
+ | ## | ||
+ | |||
+ | alias hosts=' | ||
+ | |||
+ | </ | ||
+ | ====IRC==== | ||
+ | *[[rene|Rene the Lady Bot]] | ||
+ | |||
+ | ====jobs==== | ||
+ | |||
+ | List all running jobs: | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | :~$ jobs | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | List process ID (PID) of all running jobs: | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | :~$ jobs -p | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | Kill all running background jobs: | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | :~$ sudo kill -9 $(jobs -p) | ||
+ | |||
+ | ## | ||
+ | ## or | ||
+ | ## | ||
+ | |||
+ | :~$ sudo kill `jobs -p` | ||
+ | |||
+ | </ | ||
+ | ====Networking==== | ||
+ | Useful network connection Commands | ||
+ | *List IP address (similar to ipconfig in Windows) | ||
+ | <cli> | ||
+ | lab46:~ ifconfig | ||
+ | </ | ||
+ | *Show wireless networks that are available in the area along with basic encryption information | ||
+ | <cli> | ||
+ | lab46:~ iwlist scan | ||
+ | </ | ||
+ | *Show interface and driver associated with each networking device | ||
+ | <cli> | ||
+ | lab46:~ lshw -C network | ||
+ | </ | ||
+ | *Show hardware connected to the pci bus | ||
+ | <cli> | ||
+ | lab46:~ lspci -nn | ||
+ | </ | ||
+ | *Show USB connected hardware | ||
+ | <cli> | ||
+ | lab46:~ lsusb | ||
+ | </ | ||
+ | *Additional info on USB related hardware (good for USB dongles) | ||
+ | <cli> | ||
+ | lab46:~ lshw -C usb | ||
+ | </ | ||
+ | *List modules that will not be loaded by the Operating System at boot time | ||
+ | <cli> | ||
+ | lab46:~ cat / | ||
+ | </ | ||
+ | *List currently loaded kernel modules. (Example usage - lsmod | grep ndiswrapper) | ||
+ | <cli> | ||
+ | lab46:~ lsmod | ||
+ | </ | ||
+ | *List kernel IP routing table -- Good for troubleshooting problems with the gateway (netstat -rn = equivalent command) | ||
+ | <cli> | ||
+ | lab46:~ route -n | ||
+ | </ | ||
+ | *Set the default gateway to 192.168.1.1 | ||
+ | <cli> | ||
+ | lab46:~ sudo route add default gw 192.168.1.1 | ||
+ | </ | ||
+ | *Delete the default gateway setting | ||
+ | <cli> | ||
+ | lab46:~ sudo route del default gw 192.168.1.1 | ||
+ | </ | ||
+ | *Load the kernel module **** | ||
+ | <cli> | ||
+ | lab46:~ sudo modprobe ***** | ||
+ | |||
+ | Example usage: | ||
+ | lab46:~ sudo modprobe ndiswrapper | ||
+ | lab46:~ sudo modprobe r818x | ||
+ | lab46:~ sudo modprobe ath_pci | ||
+ | |||
+ | </ | ||
+ | *Unload the kernel module **** | ||
+ | <cli> | ||
+ | lab46:~ sudo modprobe -r **** | ||
+ | |||
+ | Example usage: | ||
+ | lab46:~ sudo modprobe -r ndiswrapper | ||
+ | </ | ||
+ | *Bring up/down the interface and clears the routing table for the specified interface | ||
+ | <cli> | ||
+ | lab46:~ sudo ifup eth0 | ||
+ | |||
+ | lab46:~ sudo ifdown eth0 | ||
+ | |||
+ | </ | ||
+ | *Bring up/down the interface for the specified interface | ||
+ | <cli> | ||
+ | lab46:~ sudo ifconfig eth0 up | ||
+ | |||
+ | lab46:~ sudo ifconfig eth0 down | ||
+ | </ | ||
+ | *Request IP address from DNS server for specified interface | ||
+ | <cli> | ||
+ | lab46:~ sudo dhclient | ||
+ | </ | ||
+ | *Release IP address associated with specified interface | ||
+ | <cli> | ||
+ | lab46:~ sudo dhclient -r | ||
+ | </ | ||
+ | *List firewall rules | ||
+ | <cli> | ||
+ | lab46:~ sudo iptables -L | ||
+ | </ | ||
+ | *List boot log -- good for troubleshooting problems with modules/ | ||
+ | <cli> | ||
+ | lab46:~ dmesg | more | ||
+ | </ | ||
+ | *Display kernel version | ||
+ | <cli> | ||
+ | lab46:~ uname -r | ||
+ | </ | ||
+ | *(Feisty and pre-releases (Edgy, etc)) - / | ||
+ | <cli> | ||
+ | lab46:~ /etc/iftab | ||
+ | </ | ||
+ | *List DNS servers associated with network connections (Network Manager) | ||
+ | <cli> | ||
+ | lab46:~ cat / | ||
+ | </ | ||
+ | *File which sets or modifies dns (domain name servers) settings | ||
+ | <cli> | ||
+ | lab46:~ cat / | ||
+ | </ | ||
+ | |||
+ | * http:// | ||
+ | * [[dell_latitude_d531_wifi|Dell Latitude D531 Wireless Network Setup]] | ||
+ | ====ps & kill==== | ||
+ | While installing a bot on Lab46, I found that I was going to have to kill the bot's processes (over and over again). | ||
+ | |||
+ | <cli> | ||
+ | :~$ ps | ||
+ | </ | ||
+ | |||
+ | The '' | ||
+ | |||
+ | <cli> | ||
+ | :~$ ps aux | ||
+ | </ | ||
+ | |||
+ | With list in hand (or in terminal) I picked out the process ID (PID) of my unsuspecting bot and pulled the trigger: | ||
+ | |||
+ | <cli> | ||
+ | :~$ kill <pid> | ||
+ | </ | ||
+ | |||
+ | ====screen==== | ||
+ | A few tricks in '' | ||
+ | |||
+ | <cli> | ||
+ | # ...replace < | ||
+ | :~$ screen -S < | ||
+ | </ | ||
+ | |||
+ | The above command opens a new screen session containing a second bash shell. | ||
+ | |||
+ | <cli> | ||
+ | :~$ screen -ls | ||
+ | </ | ||
+ | |||
+ | Reattach as you normally would, except now give screen the name of the session you seek: | ||
+ | |||
+ | <cli> | ||
+ | :~$ screen -r < | ||
+ | </ | ||
+ | |||
+ | Handy. | ||
+ | |||
+ | ====sudoers==== | ||
+ | After users have been added, it's helpful to give some users a little extra access. | ||
+ | <cli> | ||
+ | :~$ visudo | ||
+ | </ | ||
+ | Adding the following line to the sudoers file will give a user root privileges, except that they cannot change the root password. | ||
+ | <cli> | ||
+ | user ALL = (ALL) ALL, !/ | ||
+ | </ | ||
+ | ===Useful Links=== | ||
+ | * [[http:// | ||
+ | ====useradd==== | ||
+ | Adding users requires the following command: (again with sudo) | ||
+ | <cli> | ||
+ | :~$ sudo useradd -gadm -gunix -pxxxx -d/ | ||
+ | </ | ||
+ | (where $USER is your desired username) | ||
+ | |||
+ | The above command adds a user to the groups (-g) adm and unix. There is a difference between capital G and lowercase g, as the capital G will not actually add you to the desired group. | ||
+ | |||
+ | <cli> | ||
+ | :~$ sudo vi etc/group | ||
+ | </ | ||
+ | |||
+ | Once open, find the '' | ||
+ | |||
+ | <WRAP warning> | ||
+ | Using the -p option of the useradd command doesn' | ||
+ | </ | ||
+ | To see what I mean, issue the following command: (you may want to pipe this to less) | ||
+ | <cli> | ||
+ | :~$ sudo cat etc/shadow | less | ||
+ | </ | ||
+ | Scroll through the file and see that the password you entered with the -p option of the useradd command is there in plain text for all to see. Whoops. | ||
+ | |||
+ | <cli> | ||
+ | :~$ su $USER | ||
+ | </ | ||
+ | You will be prompted for your password. | ||
+ | <cli> | ||
+ | :~$ sudo passwd $USER | ||
+ | </ | ||
+ | Again, substitute $USER with your new user's name. You will then be prompted for the new password, and, once complete, the NEW password will be hashed. | ||
+ | |||
+ | =====VMWare===== | ||
+ | |||
+ | If you've ever locked yourself out of a box, you've probably used single user mode to recover the password. | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## edit the .vmx file for your VM adding the following | ||
+ | ## | ||
+ | |||
+ | :~$ vi / | ||
+ | |||
+ | ## | ||
+ | ## add this line to slow down the boot to give you time to hit F2 or whatever needs hitting | ||
+ | ## | ||
+ | |||
+ | bios.bootDelay = " | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now, hit your F2 and **select recovery mode**. | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## remount the drive in read/write mode | ||
+ | ## | ||
+ | |||
+ | :~$ mount -o remount,rw / | ||
+ | |||
+ | ## | ||
+ | ## you are now root | ||
+ | ## | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | ====CLI==== | ||
+ | |||
+ | You need to enable ssh before using the CLI within ESXi. Currently, the only way I know of doing this remotely is throught the VMWare vSphere client (Windows/ | ||
+ | |||
+ | From the client: click the host -> click the configuration tab -> click security profile -> under services click properties -> highlight ssh -> click options -> click start. | ||
+ | |||
+ | You can now ssh into the ESXi host. | ||
+ | |||
+ | ===Restart a VM=== | ||
+ | |||
+ | Begin by listing the running VM processes | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | :~$ esxcli vm process list | ||
+ | |||
+ | ## | ||
+ | ## Likely output ... shows 2 VMs running ... note the World ID | ||
+ | ## | ||
+ | |||
+ | ubuntu-vm | ||
+ | World ID: 1361123 | ||
+ | | ||
+ | VMX Cartel ID: 1361122 | ||
+ | UUID: 56 4d 20 bb dd 70 c4 80-e0 c6 f7 a6 ee 51 ee 25 | ||
+ | | ||
+ | | ||
+ | |||
+ | debian-vm | ||
+ | World ID: 1341691 | ||
+ | | ||
+ | VMX Cartel ID: 1341690 | ||
+ | UUID: 56 4d 18 73 98 73 59 c3-3e 71 44 ff 15 58 17 1e | ||
+ | | ||
+ | | ||
+ | |||
+ | </ | ||
+ | |||
+ | Next, use '' | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | :~$ vim-cmd vmsvc/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===Clone a VM=== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | :~$ vmkfstools -i / | ||
+ | |||
+ | </ | ||
+ | |||
+ | Next, to register the VM in the datastore, first copy the .vmx file into the newly created VM directory. | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## copy the .vmx file | ||
+ | ## | ||
+ | |||
+ | :~$ cp / | ||
+ | |||
+ | ## | ||
+ | ## register the VM | ||
+ | ## | ||
+ | |||
+ | :~$ vim-cmd solo/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===Regenerate a Missing (corrupted) .vmdk=== | ||
+ | |||
+ | Given a vm named slugworth, and a missing .vmdk file or corrupted ... here's how to regenerate: | ||
+ | |||
+ | First, identify the size of the file slugworth-flat.vmdk | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## navigate to the directory of ... | ||
+ | ## | ||
+ | |||
+ | :~$ cd / | ||
+ | |||
+ | |||
+ | ## | ||
+ | ## determine its size | ||
+ | ## | ||
+ | |||
+ | :~$ ls -l | ||
+ | |||
+ | -rw------- | ||
+ | -rw------- | ||
+ | -rw------- | ||
+ | -rw-r--r-- | ||
+ | -rwxr-xr-x | ||
+ | -rw-r--r-- | ||
+ | -rw-r--r-- | ||
+ | |||
+ | </ | ||
+ | |||
+ | Identify the type of SCSI controller the virtual disk is using by opening the .vmx file ... | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## determine the SCSI controller ... vitrualDev | ||
+ | ## | ||
+ | |||
+ | :~$ cat slugworth.vmx | grep -i scsi | ||
+ | |||
+ | scsi0.present = " | ||
+ | scsi0.sharedBus = " | ||
+ | scsi0.virtualDev = " | ||
+ | scsi0: | ||
+ | scsi0: | ||
+ | scsi0: | ||
+ | scsi0.pciSlotNumber = " | ||
+ | scsi0: | ||
+ | |||
+ | </ | ||
+ | |||
+ | Use the vmkfstools command to create a new virtual disk: | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## create a new disk | ||
+ | ## | ||
+ | |||
+ | :~$ vmkfstools -c 17179869184 -a lsilogic -d thin temp.vmdk | ||
+ | |||
+ | |||
+ | |||
+ | ## | ||
+ | ## -c size | ||
+ | ## | ||
+ | ## This is the size of the virtual disk. | ||
+ | ## | ||
+ | ## -a virtual_controller | ||
+ | ## | ||
+ | ## Whether the virtual disk was configured to work with BusLogic, LSILogic (for both lsilogic and lsilogic SAS) or IDE. | ||
+ | ## | ||
+ | ## -d thin | ||
+ | ## | ||
+ | ## This creates the disk in thin-provisioned format. | ||
+ | ## | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | Delete the un-needed temporary flat.vmdk | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | :~$ rm -rf temp-flat.vmdk | ||
+ | |||
+ | </ | ||
+ | |||
+ | Edit the new temp.vmdk and change the name of the .flat file to match the orphaned .flat file, and find and remove the line ddb.thinProvisioned = " | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | :~$ vi temp.vmdk | ||
+ | |||
+ | # Disk DescriptorFile | ||
+ | version=1 | ||
+ | CID=fb183c20 | ||
+ | parentCID=ffffffff | ||
+ | createType=" | ||
+ | |||
+ | # Extent description | ||
+ | RW 8388608 VMFS " | ||
+ | |||
+ | # Extent description | ||
+ | RW 8388608 VMFS " | ||
+ | |||
+ | |||
+ | # The Disk Data Base | ||
+ | #DDB | ||
+ | |||
+ | ddb.virtualHWVersion = " | ||
+ | ddb.geometry.cylinders = " | ||
+ | ddb.geometry.heads = " | ||
+ | ddb.geometry.sectors = " | ||
+ | ddb.adapterType = " | ||
+ | ddb.thinProvisioned = " | ||
+ | |||
+ | </ | ||
+ | |||
+ | Optionally, check the disk consistency | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## check disk consistency ... esxi 5.0 or later | ||
+ | ## | ||
+ | |||
+ | :~$ vmkfstools -e filename.vmdk | ||
+ | Disk chain is consistent | ||
+ | |||
+ | ## | ||
+ | ## check disk consistency ... esxi 5.0 or earlier | ||
+ | ## | ||
+ | |||
+ | :~$ vmkfstools -q test.vmdk | ||
+ | test.vmdk is not an rdm | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now start the VM. | ||
+ | |||
+ | Instructions taken from: [[http:// | ||
+ | |||
+ | ===vim-cmd=== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## Options available under vim-cmd | ||
+ | ## | ||
+ | |||
+ | hbrsvc/ | ||
+ | hostsvc/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==vmsvc== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## other options available under vim-cmd vmsvc/ | ||
+ | ## | ||
+ | |||
+ | acquiremksticket | ||
+ | acquireticket | ||
+ | connect | ||
+ | convert.toTemplate | ||
+ | convert.toVm | ||
+ | createdummyvm | ||
+ | destroy | ||
+ | device.connection | ||
+ | device.connusbdev | ||
+ | device.disconnusbdev | ||
+ | device.diskadd | ||
+ | device.diskaddexisting | ||
+ | device.diskremove | ||
+ | device.getdevices | ||
+ | device.toolsSyncSet | ||
+ | device.vmiadd | ||
+ | device.vmiremove | ||
+ | devices.createnic | ||
+ | disconnect | ||
+ | get.capability | ||
+ | get.config | ||
+ | get.config.cpuidmask | ||
+ | get.configoption | ||
+ | get.datastores | ||
+ | get.disabledmethods | ||
+ | get.environment | ||
+ | get.filelayout | ||
+ | get.filelayoutex | ||
+ | get.guest | ||
+ | get.guestheartbeatStatus | ||
+ | get.managedentitystatus | ||
+ | get.networks | ||
+ | get.runtime | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==solo== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## Options available under vim-cmd solo/ | ||
+ | ## | ||
+ | |||
+ | connect | ||
+ | disconnect | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==hbrsvc== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## Options available under vim-cmd hbrsvc/ | ||
+ | ## | ||
+ | |||
+ | vmreplica.abort | ||
+ | vmreplica.create | ||
+ | vmreplica.disable | ||
+ | vmreplica.diskDisable | ||
+ | vmreplica.diskEnable | ||
+ | vmreplica.enable | ||
+ | vmreplica.getConfig | ||
+ | vmreplica.getState | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==hostsvc== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## Options available under vim-cmd hostsvc/ | ||
+ | ## | ||
+ | |||
+ | advopt/ | ||
+ | autostartmanager/ | ||
+ | datastore/ | ||
+ | datastorebrowser/ | ||
+ | firmware/ | ||
+ | net/ hosthardware | ||
+ | rsrc/ | ||
+ | storage/ | ||
+ | summary/ | ||
+ | vmotion/ | ||
+ | connect | ||
+ | cpuinfo | ||
+ | disable_esx_shell | ||
+ | disable_ssh | ||
+ | disconnect | ||
+ | enable_esx_shell | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==internalsvc== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## Options available under vim-cmd internalsvc/ | ||
+ | ## | ||
+ | |||
+ | perfcount/ | ||
+ | vprobes/ | ||
+ | access_address | ||
+ | cold_quit | ||
+ | connect | ||
+ | disconnect | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==proxysvc== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## Options available under vim-cmd proxysvc/ | ||
+ | ## | ||
+ | |||
+ | add_np_service | ||
+ | add_tcp_service | ||
+ | connect | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==vimsvc== | ||
+ | |||
+ | <cli> | ||
+ | |||
+ | ## | ||
+ | ## Options available under vim-cmd vimsvc/ | ||
+ | ## | ||
+ | |||
+ | auth/ | ||
+ | connect | ||
+ | disconnect | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ====Resources==== | ||
+ | *[[http:// |