Chitchat

======

Battery on my 14 year old laptop finally died. Maybe I can find a cheap ups or get a better ups and then use my cheap one with the laptop.

Made another parallel port breakout cable.

About to determine the fate of some old P-I  motherboards.

Need to clean up the man cave to do some soldering.

——————————-

Writing your first script and getting it to work to successfully write a shell script, you have to do three things:
Write a script
Give the shell permission to execute it
Put it somewhere the shell can find itWriting a scriptA shell script is a file that contains ASCII text. To create a shell script, you use a text editor sucj as vim or nano. A text editor is a program, like a word processor, that reads and writes ASCII text files. There are many, many text editors available for your Linux system, both for the command line environment and the GUI environment. Now, fire up your text editor
[you@yourllinuxbox you]$ nano yourfirstscriptand
type in your first script as follows:
#!/bin/bash
# My first script
echo “Hello World!”
The clever among you will have figured out how to copy and paste the text into your text editor. Then (^X) exit. Say (Y)es to save the modified buffer.  If you have ever opened a book on programming, you would immediately recognize this as the traditional “Hello World” program. Save your file with some descriptive name. How about yourfirstscript?The first line of the script is important. This is a special clue given to the shell indicating what program is used to interpret the script. In this case, it is /bin/bash. Other scripting languages such as perl, awk, tcl, Tk, and python can also use this mechanism.The second line is a comment. Everything that appears after a “#” symbol is ignored by bash. As your scripts become bigger and more complicated, comments become vital. They are used by programmers to explain what is going on so that others can figure it out. The last line is the echo command. This command simply prints what it is given on the display.
Setting permissionsThe next thing we have to do is give the shell permission to execute your script. This is done with the chmod command as follows:[you@yourllinuxbox you]$ chmod 755 yourfirstscriptThe “755” will give you read, write, and execute permission. Everybody else will get only read and execute permission. If you want your script to be private (i.e., only you can read and execute), use “700” instead.
Putting it in your pathAt this point, your script will run. Try this:[you@yourllinuxbox you]$ ./yourfirstscriptYou should see “Hello World!” displayed. If you do not, see what directory you really saved your script in, go there and try again.Before we go any further, I have to stop and talk a while about paths. When you type in the name of a command, the system does not search the entire computer to find where the program is located. That would take a long time. You have noticed that you don’t usually have to specify a complete path name to the program you want to run, the shell just seems to know.Well, you are right. The shell does know. Here’s how: the shell maintains a list of directories where executable files (programs) are kept, and just searches the directories in that list. If it does not find the program after searching each directory in the list, it will issue the famous command not found error message.

This list of directories is called your path. You can view the list of directories with the following command:

[you@yourllinuxbox you]$ echo $PATH

This will return a colon separated list of directories that will be searched if a specific path name is not given when a command is attempted. In our first attempt to execute your new script, we specified a pathname (“./”) to the file.

You can add directories to your path with the following command, where directory is the name of the directory you want to add:

[you@yourllinuxbox you]$ export PATH=$PATH:directory

A better way would be to edit your .bash_profile file to include the above command. That way, it would be done automatically every time you log in. (Not really used anymore)

[you@yourllinuxbox you]$ PATH=$PATH:~/bin
[you@yourllinuxbox you]$ export PATH

Most modern Linux distributions encourage a practice in which each user has a specific directory for the programs he/she personally uses. This directory is called bin and is a subdirectory of your home directory (/home/you/). If you do not already have one, create it with the following command:

[you@yourllinuxbox you]$ mkdir bin

Move your script into your new bin directory and you’re all set.

[you@yourllinuxbox you]$ mv yourfirstscript ~/bin/.

Now you just have to type:

[you@yourllinuxbox you]$ yourfirstscript

and your script will run.

——————————-

Simple tree. Invoke with:

$ ./hollidaytree.sh 24

code:

#!/bin/bash
declare -a a=('.' '~' "'" 'O' "'" '~' '.' '*')
[[ $# = 0 ]] && s=9 || s=$1
[[ $s -gt 5 ]] || s=5
for (( w=1, r=7, n=1; n<=$s; n++ )) ; do
  for (( i=$s-n; i>0; i-- )) ;  do
    echo -n " "
  done
  for (( i=1; i<=w; i++ )) ; do
    echo -n "${a[r]}"
    [[ $r -gt 5 ]] && r=0 || r=$r+1
  done
  w=$w+2
  echo " "
done;
echo " "
 

 

 

 

 
Code:
<HTML>
<BODY>
<!--
 var a=40,b=8,c=13,o="<div style='font-family:monospace;text-align:center;color:#094'>",
w=1,x=0,y="|#|<br>";for(i=1;i<a;i++){for(j=0;j<w;j++){x%c==0?o+="<span style='color:#D00'>O
</span>":o+="+";x++;}i%b==0?w-=4:w+=2;o+="<br>";}document.write(o+"<span style='color:#640'>"
+y+y+y+"</span></div>");
--> 
 <SCRIPT LANGUAGE="JavaScript">
var a=40,b=8,c=13,o="<div style='font-family:monospace;text-align:center;color:#094'>",w=1,x=0,y="|#|<br>";for(i=1;i<a;i++){for(j=0;j<w;j++){x%c==0?o+="<span style='color:#D00'>O</span>":o+="+";x++;}i%b==0?w-=4:w+=2;o+="<br>";}document.write(o+"<span style='color:#640'>"+y+y+y+"</span></div>");
</SCRIPT>
</BODY>
</HTML>
 
Awesome rotating tree when shown from a web page

 


Code:
<html>
<body>

<script type="text/javascript">
var size = 400;

var canvas = document.createElement('canvas');
canvas.width = size;
canvas.height = size;
document.body.appendChild(canvas);

var ctx = canvas.getContext('2d');

var p3d = [];

var p = [Math.random(), Math.random(), Math.random(), 0];

for (var i = 0; i < 100000; i++) {
    p3d.push([p[0],p[1],p[2],p[3]]);
    var t = Math.random();
    if (t<0.4) {
        _y = 0.4 * p[1];
        _x = 0.1 * p[0];
        _z = 0.6 * p[2];
        var r = Math.floor(3*t/0.4)/3.0;
        var rc = Math.cos(Math.PI*2.0*r);
        var rs = Math.sin(Math.PI*2.0*r);
        p[1] = _x+0.1*r+0.5*_y*_y;
        p[0] = _y*rc+_z*rs;
        p[2] = _z*rc-_y*rs;
        p[3] = 0.2*t + 0.8*p[3];
    } else {
        p[1] = 0.2 + 0.8*p[1];
        p[0] = 0.8 * p[0];
        p[2] = 0.8 * p[2];
        p[3] = 0.2 + 0.8*p[3];
    }
}

var rot = 0.0;

function render() {
    rot = rot + 0.1;
    var rc = Math.cos(rot);
    var rs = Math.sin(rot);

    ctx.strokeStyle='#FF7F00';
    ctx.lineWidth=2;
    ctx.beginPath();
    ctx.moveTo(size/2,size/8);
    ctx.lineTo(size/2,size*15/16);
    ctx.stroke();

    var img = ctx.getImageData(0, 0, size, size);
    for (var j = 0; j < size*size; j++) {
        img.data[4*j+0] = 0.5*img.data[4*j+0];
        img.data[4*j+1] = 0.5*img.data[4*j+1];
        img.data[4*j+2] = 0.5*img.data[4*j+2];
        img.data[4*j+3] = 255;
    }
    
    for (var i = 0; i < p3d.length; i++) {
        var px = p3d[i][0];
        var py = 0.5 - p3d[i][1];
        var pz = p3d[i][2];
        var col = Math.floor(128.0*p3d[i][3]);
        
        var _x = rc*px + rs*pz;
        var _z = rc*pz - rs*px;

        var z = 3.0 * size / (_z + 4.0);
        var x = size / 2 + Math.round(_x * z);        
        var y = size / 2 + Math.round(py * z);

        if(x>=0&&y>=0&&x<size&&y<size) {
            img.data[4 * (y * size + x) + 0] = col;
            img.data[4 * (y * size + x) + 1] = 128+col;
            img.data[4 * (y * size + x) + 2] = col;
            img.data[4 * (y * size + x) + 3] = 255;
        }
    }

    ctx.putImageData(img, 0, 0);
}

setInterval(render, 1000 / 30);
</script>
</body>
</html>

——————————-

Varied an existing script to show the NCAA college football standings. It is not formatted yet as I can get what I want without formatting. It is pretty much the same script to get the scores, but using a different web page to gather data.

 

 

###################################
# Score  Grabber
#
#===============================
# Assignments
# --------------------------------
datafile="tcf"
let "flag = 0"
let "year = 2014"
let "week = 14"

if [ "$week" -lt "10" ]; then
    let "a = 0"
fi
# end assignments
#=================================
#
# Get data file
#---------------------------------
elinks -dump "www.ncaa.com/standings/football/fbs/"  > $datafile
IFS='%'
#=================================
#
# Extract and display data
#---------------------------------
while read line
do fdata[$a]=$line
    echo $line | grep -q "Atlantic Coast"
    if  [ $? -eq 0 ]; then
        # header
        clear
        let "flag = 1"
    fi
    if [ $flag -eq 1 ]; then
        echo $line | grep -q "NCAA football"
            if [ $? -eq 0 ]; then
            let "flag = 0"
        else
            echo $line | grep -q "GameCenter"      
            if [ $? -eq 0 ]; then
                let "response = donothing"
            else
            line=`echo $line | sed 's/\[.*\]//'`
            echo $line
        fi
        fi
    fi
let "a += 1"
done < $datafile
# footer
echo ---------------------------------------------
echo
#===================================
# End.
####################################

For historical sake here is the score grabber listing

 ####################################
# NFL Score  Grabber
#
#===============================
# Assignments
# --------------------------------
datafile="tcf"
let "flag = 0"
let "year = 2014"
let "week = 14"

if [ "$week" -lt "10" ]; then
    let "a = 0"
fi
# end assignments
#=================================
#
# Get data file
#---------------------------------
elinks -dump "www.ncaa.com/scoreboard/football/fbs/$year/$a$week/"  > $datafile

#=================================
#
# Extract and display data
#---------------------------------
while read line
do fdata[$a]=$line
    echo $line | grep -q "NCAA Scoreboard"
    if  [ $? -eq 0 ]; then
        # header
        clear
        let "flag = 1"
    fi
    if [ $flag -eq 1 ]; then
        echo $line | grep -q "Featured Sections"
            if [ $? -eq 0 ]; then
            let "flag = 0"
        else
            echo $line | grep -q "GameCenter"      
            if [ $? -eq 0 ]; then
                let "response = donothing"
            else
                echo $line | sed 's/\[.*\]//'
            fi
        fi
    fi
let "a += 1"
done < $datafile
# footer
echo ---------------------------------------------
echo
#===================================
# End.
####################################

Here is the code for the pro-football script also.

  ####################################
# Score  Grabber
#
#===============================
# Assignments
# --------------------------------
datafile="nflscorefile"
a=1
flag=0
week=13
# phase 1 is preseason phase 2 is regular season #phase 3 is
phase=2
season=2014
#finished week = 1 unfinished week = 0
weekfinished=1
league="nfl"
# end assignments
#=================================
#
# Get data file
#---------------------------------
case $weekfinished in
1)
elinks "http://sports.yahoo.com/$league/scoreboard/?week=$week&phase=$phase&season=$season"  > $datafile
;;
0)
elinks "http://sports.yahoo.com/$league/scoreboard/"  > $datafile
;;
*)
#
;;
esac
#=================================
#
# Extract and display data
#---------------------------------
while read line
do fdata[$a]=$line
echo $line | grep -q "Home Score Away"
if  [ $? -eq 0 ]; then
# header
clear
echo
echo ------------------------------------------------
echo  $league  data for phase = $phase  week = $week  season = $season
echo ------------------------------------------------
echo
echo "       Home           Score              Away"
echo ""
let "flag = 1"
fi
if [ $flag -eq 1 ]; then
echo $line | grep -q "Latest NFL Videos"
if [ $? -eq 0 ]; then
let "flag = 0"
else
echo $line | grep -q "Home Score Away"
if  [ $? -ne 0 ]; then
case $weekfinished in
1)
echo $line | sed 's/\[.*\]//'
;;
0)
echo $line
;;
*)
#
;;
esac
fi
fi
fi
let "a += 1"
done < $datafile
# footer
echo ---------------------------------------------
echo
#===============================
# End.
################################

——————————-

More than one way to skin a cat.
# just a thought
IFS=’%’
line=” [173]Virginia                          3-5 5-7 310 289 5-2 0-5 Lost 1″

Screenshot - 12032014 - 08:56:43 AM

a=`echo $line | cut -c8-28`
b=`echo $line | cut -c29-31`
c=`echo $line | cut -c33-35`
d=`echo $line | cut -c38-40`
e=`echo $line | cut -c42-44`
f=`echo $line | cut -c46-48`
g=`echo $line | cut -c51-53`
h=`echo $line | cut -c56-61`

echo “<html>”> somefile.html
echo “<body>”>> somefile.html
echo “<table border=1>”>> somefile.html
echo “<tr><td>School</td><td>W-L</td><td>W-L</td><td>PF</td><td>PA</td><td>Home</td><td>Away</td><td>Current streak</td></tr>” >> somefile.html
echo “<tr><td>$a</td><td>$b</td><td>$c</td><td>$d</td><td>$e</td> \ <td>$f</td><td>$g</td><td>$h</td></tr>” >> somefile.html
echo “</table>”>> somefile.html
echo “</body>”>> somefile.html
echo “</html>”>> somefile.html

#————————————–
chmod +x testithtml.sh
./ testithtml.sh
links2 -dump somefile.html

 Firefox

——————————-

Ever wondered what your computer is looking for. Some of these could be avenues for hackers to get into your machine. Actually this is looking for processes bound to specific ports.Use the following command  to see wbat particular port your computer is listening for:Terminal – Look for the process bound to a certain port:

sudo netstat -tulpn | grep :8080
Look for the process bound to a certain port
Or you could look at all the ports to 1000;
$ cat portscan.sh
for i in {1..1000}
do
echo $i
sudo netstat -tulpn | grep :$i
done
$./portscan.sh > portscan.file
You might see something  like this in the file.
628
629
630
631
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      2217/cupsd
tcp6       0      0 ::1:631                 :::*                    LISTEN      2217/cupsd
632
633
Cups is the unix print mechanism, Something you might want to keep and eye on once in a while or less.

——————————-

Homemade chicken lard.

SUNP0018

Good day.

Advertisements