User Tools

Site Tools


opus:spring2013:jserosky:journal

C Programming Journals

February 6, 2013

Alright, got the “code c” thing to work. Here is my first C program, so all can C, and many more to come (hopefully).

1
#include <stdio.h>
int main()
{
    printf("Hello, World!\n");
    return(0);
}

March 5, 2013

Joe taught me how to copy a file from lab46 onto a flash drive while connected via PuTTy from the Windows OS so I could actually copy and paste more than one line easily.

March 6, 2013

Created a function that adds by counting.

2
#include <stdio.h>
int add(int a,int b)
{
int r=a;
int i;
  For (i=0;i<b;i++)
  {
  r=r+1;
  }
return(r);
}

Unix Journals

February 6, 2013

The symbolic link in lab0x1 is very interesting. You can make changes to the link, such as adding or removing files, and it also changes the linked directory. I also found out that “rm” does not work on directories, and through the use of my logic skills found out that “rmdir” removes directories! Another interesting thing I found is that when you create a file in a symbolic link, and delete that symbolic link that the file will still be in the linked directory. For the manual pages I couldn't see any difference between the “du” and “du -h” commands. All of the arguments were fairly easy to find though, since the short version of them is simply the letter the argument starts with.

Mar 25, 2013

Case Study 0x1

Worked on the Case study and found some interesting things. The man tar pages explain how to tar directories and multiple files. Also created a unix directory in my src.

Lab0x2

Got to the root director(/) by typing in (cd /). I tried going into the root directory and I was denied.To get to my home directory I went to the home directory, did a ls listing and went to the jserosky directory, which is my home directory. For question 4, a is relative, and the others are absolute. For question 8, a is 400, b is 644, c is 755, d is 701. The code need to symbolically change permissions is (chmod u=rw,g=x,o=x Makefile), where u is the user, g is the group, and o is any others, or world. This gives read and write permissions to the user, and execute permissions to the group and world. The “incantation used to make the lab2 directory have r,w,x for the user, nothing for the group, and search for the world is (chmod 701 lab2).

Mar 27, 2013

Lab 0x3

When you cat the /etc/motd file it displays the same text when you login to lab46. For the head and tail utilities I used ”-nK“ where K is the number of lines from the beginning or end. The tail -f utility is interesting but I feel that it would have no practical use.

Mar 29, 2013

Case Study0x3

The file is an ASCII text file.It is indeed what it appears to be. gzip compressed file, was “file.txt.” gzip compressed file, was “file.txt,” max speed. The abcd.txt is not a text file. This file is actually a gzipped “abcd.tar” file with max compression.To open these files, I changed the name of abcd.txt to abcd.tar.gz. I proceeded to gunzip it and tar -xf it. Then I used the file utility on the making.waves file and found it was zipped, so I unzipped it. It spat out a unix.text file which I then used the cat utility on.

Apr 17, 2013

Lab0x4

Used the vi editor to create a .signature file. The ~/.bash_history file is the history of all bash entries by the user. The shell is /bin/bash, my mail directory is ~/Maildir, I'm using an xterm terminal, my path is ”/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin.“ I echoed the path by using echo $PATH. My alias for the ls utility is 'ls –color=auto'.

Apr 24, 2013

Lab0x5

(Any periods at the end of quotes are the ending of the sentence, not part of the material inside the quotes.)

I created a directory called lab5 and used the touch utility to create eight files. When I run the file* argument with the ls utility it gives me a list of all the files in the directory (file1, file2, file3, etc…). When I did ls file? it showed me only five of the files: 1,2,3,4, and a. I'm going to guess that the others weren't displayed because they have more than one character after the 'file.' When I did ls file[23] it resulted in file2 and file3 showing up. This is because I just told it to look for a name that has “file” followed by either a 2 or 3. On the fourth ls trial, using ls file[24a]*, it returned files 2, 4, 41, and a. This happens because I looked for a file that begins with 'file', the character after that is either a 2, 4, or a, and then the last characters are any characters that haven't been specified. I used the cat utility to send the text to my file1 file and thought I was looking at the login info, so I created a file1.txt and did the same thing, but I realized this time that was supposed to be there. The changed made by the append is that there is a line after the original text that says “This is text.” The next step replaced all of the previous data with “More text…” The ls file* | grep “file1” > file2 put text into file2 that named all of the files that started with “file1.” I tried to file555 to no avail. The second attempt still prompted an error. This doesn't work because you're trying to redirect a stderr with a stdout redirection. The 2> works at redirecting the error. When I typed “cat < file2” it took the text inside the file and redirected to the stdin. When I typed in the echo $PATH it spat out ”/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local/java/bin.“ The second echo “$PATH” attempt gave me the same path. The echo '$PATH' returned $PATH. The wc utility is the word count for a file or group of files. To show just the length of the lines you would use wc –lines. My command line was “cat /etc/motd | wc -l” and I got 15 lines. For the first wildcard challenged I used “ls ????” to find all of the files that were four characters in length. For the second challenge I used “ls [jcs]*” to find 16 files. Surprisingly, I think I got this one on the first try, I used “ls [abc]*[rst]” to find five files. These files are bzcat, bzip2recover, bzless, cat, and chvt. To display the long file I used the literal quotes: “cat 'Long File $PATH for Shell Lab.text'” and it worked, I'm done!

Case Study 0x5

I gave public_html read and execute permissions for the world. Running into some issues currently with copying cs.html to my public_html directory. Sent an email, awaiting reply.

Apr 25, 2013

Lab 0x6

1.) I used the ls -l utility on my script1.sh file to view its permissions. The permissions are rw for world, r for group and r for the user. I changed the user to have all permissions by using the chmod utility. This is what I typed: chmod 647 script1.sh. I found that this doesn't work so I gave the world execute permission: chmod 747 script1.sh.

2.) Read in num1 as 3 and num2 as 7, then used the let utility to add both num1 and num2 and set that value to num1, when I echoed num1 it gave me 10. To get the year only I used this: date +%Y. To store the output of the date utility I put the entire command, date +%Y in parentheses and put a $ in front of it.

1
echo "Enter your birth year"
read age1
year=$(date +%Y)
let num1=$year-$age1
echo $num1

And I just realized why all your code in c prog documents are numbered. Edited my script a little:

2
#!/bin/bash
echo "Enter your birth year"
read age1
year=$(date +%Y)
let num1=$year-$age1
echo "You are "$num1" years old."

I'm guessing the pick=$1) picks a random number from 0 to 20. Here's my code:

3
#!/bin/bash
pick=$((RANDOM % 20))
echo "Guess a number between 1 and 20"
read num1
if [ "$num1" -eq "$pick" ] ; then
        echo "Good guess!"
else
        echo "Guess again!"
        read num2
fi
if [ "$num2" -eq "$pick" ] ; then
        echo "Good guess!"
else
        echo "Guess again!"
        read num3
fi
if [ "$num3" -eq "$pick" ] ; then
        echo "Good guess!"
else
        echo "Guess again!"
        read num4
fi
if [ "$num4" -eq "$pick" ] ; then
        echo "Good guess!"
else
        echo "Sorry, you lose."
fi

Right now I'm wondering if I am supposed to be denied every time I create a script file or if I've done something wrong. It's easy to fix, but still annoying.

4.) I created the loop to all be on one line by changing echo to echo -n and I put a space inside the quotes to add a space every time. To do the second part I changed the initial i value to 20, changed the looping statement to i>=2 and changed the increment of i++ to a decrement of i=i-2.

5.) The list-based loop displayed all of the colors, in order of appearance in the code. The loop iterates eight times, with only 7 colors. On the fifth loop the variable color is set to blue.

Apr 26, 2013

Lab 0x6

Found something pretty neat. After I ran my program that creates the files I wanted an easy way to remove them, so I just did a rm file* and it prompted me and asked if I wanted to delete them all and it worked. I have no idea how to have two files with the same names in a directory.

Case Study 0x6

The / is mounted on /dev/xvda1. /home is mounted on nfs:/home. tmp is mounted on /dev/xvda2. The permissions on my terminal file are 620. When I changed my messaging the permissions changed from 620 to 600. This allows users to write on my terminal session, since they have the permission when it is there. I typed cat /etc/motd > /dev/null. /dev/null might be useful if you had some output that was an infinite loop.

Lab0x7

1.)

1
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
jserosky   443  0.0  0.0  13596  1020 pts/19   SNs+ Jan22   0:00 /bin/bash
jserosky  8967  0.0  0.1  13636  2008 pts/11   SNs  18:41   0:00 -bash
jserosky  9328  0.0  0.1  13668  1968 pts/73   SNs  Apr12   0:00 /bin/bash
jserosky  9337  0.0  0.3  42644  5332 pts/73   SN+  Apr12   4:03 irssi
jserosky 10894  0.0  0.1  10916  1672 pts/11   TN   18:51   0:00 man ls
jserosky 10905  0.0  0.0  10360   996 pts/11   TN   18:51   0:00 pager -s
jserosky 13168  0.0  0.1  10916  1676 pts/11   TN   19:05   0:00 man df
jserosky 13178  0.0  0.0  10360   984 pts/11   TN   19:05   0:00 pager -s
jserosky 13790  0.0  0.1  10916  1676 pts/11   TN   19:09   0:00 man tty
jserosky 13801  0.0  0.0  10360   980 pts/11   TN   19:09   0:00 pager -s
jserosky 15534  0.0  0.0   8588   984 pts/11   RN+  19:19   0:00 ps u

If I were logged in more than once it would show both terminal sessions and their corresponding processes.

2.)I used ps -A u I couldn't find the inetd process. The most active processes are the ones run by the root user.

3.) This file type is a .c file. I know this because I am familiar with C. Yes it worked, and you run it by using ./count. It took 34.161 seconds for the program to finish. The number inside output is 33554432.000000. The process showed up and it took 101% of the CPU.

Whilst doing this lab I came up with an evil plan: an infinite loop script that writes to a user chosen by providing the input. I will try to test this invention on some poor soul.

5.) This is the spell I cast:

2
lab46:~/src/unix$ sleep 8; ls /var > multitask.lab.txt &

6.) When I tried to log out it told me there are stopped jobs. The purpose of this is to make sure you don't lose a job that you stopped but wanted to continue running at a later time. 7.) The links job is [10]+. When I tried to fg it an error popped up. I foreground the cat job by typing fg 8. I have no idea what the end of file character is. 8.) SIGHUP is #1, SIGTERM is #15, SIGKILL is #9, and SIGINT is #2. Both users are listed in the who output:

3
NAME       LINE         TIME             IDLE          PID COMMENT
synack   + pts/9        2013-04-14 02:30 00:58       28070 (69.194.56.177)
alius    + pts/10       2013-01-18 10:03  old        10102 (cpe-74-65-109-183:S.0)
smalik2  + pts/18       2013-01-20 15:14  old        26721 (mobile-198-228-195-067:S.0)
smeas    + pts/33       2013-02-27 20:11 09:07        3474 (li583-226:S.0)
jserosky + pts/46       2013-04-26 19:57   .         22196 (cpe-24-94-58-131.stny.res.rr.com)
tedmist1 + pts/53       2013-04-25 20:09 10:54        3715 (:pts/41:S.0)
ahughe12 + pts/29       2013-01-29 17:49  old        30065 (caprisun:S.0)
jserosky + pts/76       2013-04-26 20:00   .         22648 (cpe-24-94-58-131.stny.res.rr.com)
jcavalu3 + pts/54       2013-04-19 15:48  old        15136 (10.80.3.174)
ahughe12 + pts/78       2013-04-10 11:15  old        16517 (caprisun:S.1)

The terminal device numbers are 46 and 76. The PID of my screen sessions are 22219 and 22662. I killed #76 and I used kill 22662. The message generated by my console was something about the network not working. I am not logged in twice anymore.

4
lab46:~$ ps -U statd
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
statd     1016  0.0  0.0  14596     8 ?        Ss   Jan14   0:00 /sbin/rpc.statd

Apr 28, 2013

Lab0x8
1
lab46:~/devel$ gcc -o helloC helloC.c
lab46:~/devel$ g++ -o helloCPP helloCPP.cc
lab46:~/devel$ as -o helloASM helloASM.S
lab46:~/devel$ ld -o helloASM helloASM
helloASM: file not recognized: File truncated
lab46:~/devel$ ls
helloASM.S  helloC  helloC.c  helloCPP  helloCPP.cc
lab46:~/devel$ as -o helloASM.o helloASM.S
lab46:~/devel$ ld -o helloASM helloASM.o
lab46:~/devel$ ls
helloASM  helloASM.S  helloASM.o  helloC  helloC.c  helloCPP  helloCPP.cc
lab46:~/devel$

They do indeed all work:

2
lab46:~/devel$ ./helloASM
Hello, World!
lab46:~/devel$ ./helloC
Hello, World!
 
lab46:~/devel$ ./helloCPP
Hello, World!
lab46:~/devel$

2.) I did get an error, it says “command not found.” I'm going to guess on this parpt by lab46:~/ prompt that you mean inside my devel directory because when I do it on my home directory nothing happens either time, but while in my devel directory the ./helloC works while the other does not. helloC.c appears to be a file containing c program text. The file utility says it is an “ASCII c program text.” The helloCPP.cc is an “ASCII C++ program text” file. The helloASM.S is an “ASCII assembler program text” file. There is a helloC.s file. It is an ASCII assembler program text file. It's displaying the assembly language version of that program. There's a hello.o file. It's an “ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped” file. This is the machine language code for the helloC.c file. 7.) hello is a linked assembly code file. helloC is the same exact thing. 9.) I copied the directory recursivley.

Case Study 0x8

2.) There are 8 bits in a char. It can have two unique states. The range of a signed short int is -32768 to 32767 and it is 16 bits. An unsgined int's range is 0 to 4294967295 and it is 32 bits. A long long int is 64 bits. 4.) The value is 4294967395, which is the value of an usigned int's range. The value of the signed short int after is -1 I did expect this because 0 - 1, in a signed value, is -1 5.) The final result is -32768. This makes sense because the bottom value is -32768.

3
#include <stdio.h>
 
int main()
{
        unsigned int a, x;
        signed short int b, y;
 
        a = 0;
        b = 32767;
        x = a - 1;
        y = b + 1;
 
        printf("signed short int before: %hd \t after: %hd\n", b, y);
 
        return(0);
}
Lab 0x9

1.) I used grep System passwd. This search displays the line that the string of text was on. I typed grep ^[b-d][aeiou] passwd on the command-line. This search looks for a string that starts with anything from a b to a d and is followed up by a vowel in the passwd file and displays the lines those strings are on. this is more powerful because it widens the search pattern, giving you more results. 3.)

4
lab46:/etc$ grep ^[jcsJCS] passwd
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
sshd:x:101:65534::/var/run/sshd:/usr/sbin/nologin
statd:x:105:65534::/var/lib/nfs:/bin/false
cl-builder:x:108:115::/usr/share/common-lisp/:/bin/false

I got one result for this:

5
lab46:/etc$ grep ^[r][aeiou].*[h]$ passwd
root:x:0:0:root:/root:/bin/bash
lab46:/etc$

5.) It is a symbolic link.

6
lab46:/usr/share/dict$ file words
words: symbolic link to `/etc/dictionaries-common/words'
lab46:/usr/share/dict$ cd /etc/dictionaries-common/words
-bash: cd: /etc/dictionaries-common/words: Not a directory
lab46:/usr/share/dict$ cd /etc/dictionaries-common
lab46:/etc/dictionaries-common$ ls
default.aff  default.hash  ispell-default  words
lab46:/etc/dictionaries-common$ file words
words: symbolic link to `/usr/share/dict/american-english'
lab46:/etc/dictionaries-common$ cd /usr/share/dict
lab46:/usr/share/dict$ ls
README.select-wordlist  american-english  words  words.pre-dictionaries-common
lab46:/usr/share/dict$ file american-english
american-english: UTF-8 Unicode text
lab46:/usr/share/dict$

6.)

7
lab46:/usr/share/dict$ grep ^.....$ american-english
lab46:/usr/share/dict$ grep ^[jcsJCS] american-english
lab46:/usr/share/dict$ grep ^[j].*[c].*[s]$ american-english
lab46:/usr/share/dict$ grep ^[aeiou].*[aeoiu]$ american-english
lab46:/usr/share/dict$ grep [jcsJCS][aeiou].*[est]$ american-english
lab46:/usr/share/dict$ grep ^[^jcs].*$ american-english
lab46:/usr/share/dict$ grep ^[^th]...*$ american-english
lab46:/usr/share/dict$ grep ^..[e]$ american-english
lab46:/usr/share/dict$ grep ^.*[b][o][b].*[^b]$ american-english
lab46:/usr/share/dict$ grep ^[b][l][u][e].*$ american-english
lab46:/usr/share/dict$ grep ^[^aeiyou]*$ american-english
lab46:/usr/share/dict$ grep ^[^aeiouy].[abcd].*[aeiouy]$ american-english
Case Study 0x9

1.)

8
lab46:~$ grep -c ^.*[coast]*.*$ pelopwar.txt
1605
9
lab46:~$ grep -c ^.*coast.*$ pelopwar.txt
9
10
lab46:~$ grep -c ^again.*$ pelopwar.txt
4
11
lab46:~$ egrep ^'(Athens|Athenians)'.*$ pelopwar.txt
12
lab46:~$ egrep ^.*'(Corinth|Corinthians)'$ pelopwar.txt

3.) I got no results when I tried using fgrep the same way as I did for 2a. 4.)

13
lab46:~$ grep ^[jcs].*$ -m4 lastoutput.txt
jserosky pts/76       cpe-24-94-58-131 Sun Apr 28 12:54   still logged in
jmendoza pts/76       pool-96-238-204- Fri Apr 26 22:07 - 01:00  (02:52)
jcavalu3 pts/79       cpe-69-205-131-2 Fri Apr 26 21:40 - 21:46  (00:05)
cclay    pts/76       cpe-67-255-36-68 Fri Apr 26 20:17 - 20:37  (00:19)
lab46:~$
14
lab46:~$ grep ^[e-g].*$ -m4 lastlogoutput.txt
games                                      **Never logged in**
gnats                                      **Never logged in**
fetchmail                                  **Never logged in**
en007636         pts/12   portal.corning.c Tue Jul 10 12:58:51 -0400 2012
lab46:~$
Lab0xA

1.) The file is 78062 bytes. This is the file: fall2013-20130417.html.gz: gzip compressed data, was “fall2013-20130417.html”, from Unix, last modified: Wed Apr 17 11:11:49 2013, max compression I determined this by using the file utility. I gunzipped it. The html is 2597201 bytes. 2597201 to 78062 bytes. 2.) To search for CSIT 2044 I used /CSIT 2044 There are a few similarities, such as the term, date, levels, and which campus they are on.

Apr 30, 2013

Lab 0xA

3.) This is the regex code I used

1
:/[0-9][0-9][0-9][0-9][0-9].*[A-Z][A-Z][A-Z][A-Z] [0-9][0-9][0-9][0-9].*[0-9][0-9][0-9]

This is the code used for my sed substitution:

1
lab46:~$ cat fall2013-20130417.html | grep '[0-9][0-9][0-9][0-9][0-9].*[A-Z][A-Z][A-Z][A-Z] [0-9][0-9][0-9][0-9].*[0-9][0-9][0-9]' | sed 's/<*.*>*.*[0-9[0-9][0-9][0-9][0-9].>//g' | less

5.) There are 1182 classes offered. I got this result by adding a wc -l at the end. There are 19 CSCS classes. I used a grep CSCS with a word count to produce this number. 13 ENGL 2000 or higher. I used grep ENGL.2… with a word count. The math department is offering more courses. I did this by counting the numbers of ENGL courses and then counting the number of MATH courses and comparing them.

Case Study 0xA

1.) The permissions on them are different. The size of the files are different.

2
lab46:~$ file howlong
howlong: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
lab46:~$ file /usr/bin/uptime
/usr/bin/uptime: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

The output is different when I run them. To get howlong to run I had to change the permissions. 2.) They are binary, when the file utility was used it said they were executable files. The files are identical when using diff.

3
lab46:~$ md5sum howlong
da2388cb2b29d954c22db441bb16188c  howlong
lab46:~$ md5sum /usr/bin/uptime
da2388cb2b29d954c22db441bb16188c  /usr/bin/uptime

There is a difference:

4
lab46:~$ md5sum howlong
da2388cb2b29d954c22db441bb16188c  howlong
lab46:~$ md5sum /bin/cp
85e58085c89b09fceb6e3602356c07a9  /bin/cp
1)
$RANDOM % 20
opus/spring2013/jserosky/journal.txt · Last modified: 2013/04/30 14:58 by jserosky