Saturday, November 20, 2010

Linux Part 2 Lesson 1

Bash Scripts. Make Your own executable shells

Part 2 is about scripts. How do we write a script, what's the syntax and how do we make it executable?

First, there is a basic rule! In the first line we write:
#!/bin/bash
to determine that the script we write is a bash script. (Don't know what is a bash? See Part 1 lesson 1)

And after that we can write code.
Let's see what steps do we need to follow to make a bash script of Part 1 Lesson 4

Bash Scripts can take arguments, which we can access in the script
$index
i.e $1 is the first argument given in the command line.

The code is similar to those we wrote in the command line. However, now we have to make a text file which will contain our code.
We'll use a command line text editor, nano.
->type nano in the command line and press enter.

now determine which script to use (don't know what to write? Start from the beginning again)

This script will get your favourite artist from the command line, and add any songs found in the playlist.

The previous code was:
for music in *line*Dion*/*/*.wma; do
audacious -e "$music" &
done

know, it will be:

for music in $1/*/*.wma; do
audacious -e "$music" &
done

press control O and give a name to the file and then enter to save it. Remember, it will be saved in your current directory.

->Make it executable! How? With chmod +x nameOfScript
copy it in the /bin directory so it can be run any time
->now run it:
nameOfScript *Dion*


Notes:
  1. if you have permission problems with copying to /bin use sudo or login as root and copy it there.
  2. We named our script AddToAudaciousPlaylist
  3. It is a good name to remember what it does!
  4. Remember not to put .wma if your songs are mp3.
  5. And the question of the day: How will we make user to choose the song format? Think about it! Next lesson is about improving our script!!!

And yeahhh! You have make your own first open source program in linux!What is open source? ;)
Remember! The script should be run in the directory that your music files live! Like before!

Friday, November 12, 2010

Lesson 5 Revise, Answers of the Questions

Today we'll make a revision of the previous lessons answering the questions of lesson 4.
Here are the questions:
  1. Why have we used '&' after audacious -e "$music"? What does it means? try to open other programs with '&' at the end and without it!
  2. Why we put the audacious -e "$music" & in the for loop and didn't used a playlist variable like before? What script is better?
  3. Why music variable has a '$' in the for loop?
  4. Why have we put *.wma instead of *.mp3? Are you going to do the same?
  5. Why the -E became a -e? Check man audacious to find out!

  1. & runs the command or program in background, so the terminal is free for putting other commands!
  2. Because the -e adds songs to the current playlist.
  3. If a variable is going to be used for output must have $ in front
  4. The songs of Celine Dion was in wma format. If yours are mp3 or other format you shouldn't use wma.
  5. Because -E creates a temporary playlist.

Monday, November 8, 2010

Linux Lessons Part 1 Lesson 4

So, here is our case for today:
We want to make a playlist with our favorite artists.

This is a problem that needs string matching.
String is a sequence of alphanumerical characters.

So, let's consider the problem:

One of our favorite artists is Celine Dion.

But there are some problems in our folders:
The name of Celine Dion is correct, but in french, i.e. it's Céline Dion. Also, not all folders have just the artist's name. E.g there is a folder Celine Dion - Titanic.
So, let's go back to previous lessons.
Remember the * sign?
It means whatever characters. So if I write *l* means, all the strings that contain the letter l.
In the previous lessons we were searching for mp3's like that, *.mp3. It means whatever string ends with the characters .mp3 .
So, we are going to use that.
E.g if we are searching for folders of Celine Dion we are going to search only the characters that are common. Remember! Neither use so many nor so little:
We used *line*Dion* : this means, whatever characters, then 'line' then whatever characters and then Dion. We could use *Dion* or *C*line*Dion, but it's up to you what you think is right for your case.

So that's the previous code:

for music in */*/*.mp3; do
playlist+=$music;
done; audacious "$playilist" -E

Now we want to make a permanent playlist with our favourite artists!
Make sure that the playlist is empty:
audacious &
choose playlist, delete playlist (it closes the playlist, if you want
the playlist export it before deleting)

run that command:

for music in *line*Dion*/*/*.wma; do
audacious -e "$music" &
done


So after that you can run as many scripts as you want and add your favorite songs.
Then export the playlist so you can use it again.

Questions to consider until Saturday:
  • Why have we used '&' after audacious -e "$music"? What does it means? try to open other programs with '&' at the end and without it!
  • Why we put the audacious -e "$music" & in the for loop and didn't used a playlist variable like before? What script is better?
  • Why music variable has a '$' in the for loop?
  • Why have we put *.wma instead of *.mp3? Are you going to do the same?
  • Why the -E became a -e? Check man audacious to find out!
The answers of these questions will be published on Saturday, but it would be great if you share your opinions in our facebook wall!

Saturday same place :P

Saturday, November 6, 2010

Linux Lessons Part 1 Lesson 3

This lesson is about music. We all struggle with the GUI's to create a playlist.
In this lesson we will see how to create a simple playlist and on next lesson we will make it a little more complicated, so the playlist will have the exact songs we want.
The commands below was executed in linux Ubuntu Ultimate Edition 2.8.
If you have an other distribution of linux you will need to install audacious if you don't have it.
To install it in Ubuntu : sudo apt-get install audacious
In fedora: yum install audacious.
If you can't install it google it.

To create a playlist: check man audacious.
check those parts:






So let's say that:
Our songs are in directories which are in other directories.
All music files are .mp3

we will use the very useful for statement again.
we will use audacious but we will call it in the command line.
first use the command cd and change directory where your music files are.
my is cd $HOME/Music
and then create a list with the songs and load it on audacious like that:

for music in */*/*.mp3; do
playlist+=$music;
done; audacious "$playilist" -E

The first command is for that goes through each directory, and then goes through each another directory which are in the first directory. Then finds all mp3 files and adds them to the variable playlist.
The done closes the for, and then loads the playlist on audacious as a temporary playlist.

Question to consider until Wednesday:
How can you load both mp3 and wma ?

See you on Wednesday.
You can email your answer!

PS: if you can't install audacious try a similar command with the music player you have on your machine after you check its man pages!!!

Saturday, October 30, 2010

Linux Lessons part 1 Lesson 2

In the previous lesson, we discussed how to create folders with a common name, but with different number, e.g. a year number.
Our Case was to create folders, that our photos would sort out by their year.
E.g the photos taken in 2009 will go to the photo2009 folder.
Now, the first thing to consider is the folder reference. We won't speak about folders. In windows you call them folders. In Linux you call them directories. So you have 11 directories from 2000 until 2010. Is that ok? (If you have from 2001 until 2010 see again the previous lesson because there was a mistake in the code)
Now, in another directory, or in the same, you have 1000 photos or more, which have taken from 2000 until now.
Let's see one by one, our new tools we will need to sort them out.

1)date:

The program date, outputs the current date and time, if no arguments are given.
If you write in your terminal: man date , you will have a manual, or help which explains the arguments date can take.
There is an argument -r, which says



So, if we write date -r filename the output will be the date of the last time we modified that file.


But we only want the year taken (in our case).
How do we do that?
If you look in the man date again, you will notice a FORMAT part.


So, if we add a Format argument, the %G we'll get only the year.
Notice the syntax of date:


That means, write date, then the options (or arguments), the file and then the format after a + symbol.
In conclusion we write this:
date -r filename +%G
Voila:


So this is the date instruction!

2)variables
A variable is a random name we use to put things in it.
E.g name=Vasilis
mynumber=23
myage=20

name, mynumber and myage are variables.
Vasilis, 23 and 20 are the contents of each variable!
In lesson 1 we used in the for statement a variable! Can you guess its name?
Answer: Yes, its name was 'i'

3)``
To put an output of a program or command in a variable we use ``.
e.g. dateofphoto=`date -r filename`

4)mv
The mv instructions moves a file from a place to another.

5)cd
change directory

So, now we have our tools, we also have our folders.
So in your terminal write each line below followed by enter.

cd /path_where_the_photos_are
enter
for pics in *;do date_taken=`date -r $pics +%G`; mv $pics photos$date_taken; done


For any inquires or errors you notice let as know by:
email, facebook wall, or commnent.

The power of Linux, Lessons for Dummies part 1

Here is the beginning of a big Linux tutorial.
In most of the lessons we'll use bash.
Bash is the common Linux Shell, and stands for Bourne again shell!
The tutorials will have 2 parts: The case, that's the problem we face, a solution with common Windows knowledge, and a solution with Bash Script.
Vaslabs trials have made in an Ubuntu 10.04 Lucid Linux Machine, but there is no difference at all in every distribution you have. If you are new to Linux, Ubuntu is the best choice for you.

The Case:
We want to create 11 folders, each one will have the name photos and then a year number starting from 2000. In these folders we will put later some photos according the year they have been taken.

Solution:
1) In windows, or in Linux using file browser:
Go to the place you want to create the folders, right click, create folder, give it a name, e.g. photos2000, and keep doing that until you reach photos2010.
2)With a bash script:
So we want to make 11 folders in a specific location. It is not necessary to go to that location, so we won't change directory. Since you are new to Linux we won't even use a for, but will suggest that best solution later.
Even without a for the solution is faster.
So for that job will need:
1)a terminal (to write the commands)
2)the command mkdir which means make directory
3)the up arrow(it's on the keyboard)
4)and the path we want to make our folders.

So a simple solution is:
open the terminal.
write: mkdir /path/photos2000
press enter.
A folder named photos2000 has been created in /path.
then press the up arrow
The mkdir /path/photos2000 will show again.
Press backspace one time and then press 1.
now you will have mkdir /path/photos2001
press enter. etc...

But that is a very simple, and stupid solution. This is file browser thinking.
We can automate the above procedure by adding a for command.
So we'll need a couple of extra tools:
1) the for command
2)the let command (let allows mathematical operations)

So write that script instead.
for ((i=0;i<=10;i++)); do let number=2000+$i; mkdir "photos"$number; done
And press enter. The folders shall be created successfully. If you have any problems, don't
hesitate, write your problem on our facebook wall, or here as a comment.

Saturday, September 25, 2010

Kaspersky Lab provides its insights on Stuxnet worm

Kaspersky Lab's experts believe that Stuxnet manifests the beginning of the new age of cyber-warfare.

The recent Stuxnet worm attack is sparking lots of discussion and speculation about the intent, purpose, origins and -- most importantly – the identity of the attacker and target.

Kaspersky Lab has not seen enough evidence to identify the attackers or the intended target but we can confirm that this is a one-of-a-kind, sophisticated malware attack backed by a well-funded, highly skilled attack team with intimate knowledge of SCADA technology.

We believe this type of attack could only be conducted with nation-state support and backing.

"I think that this is the turning point, this is the time when we got to a really new world, because in the past there were just cyber-criminals, now I am afraid it is the time of cyber-terrorism, cyber-weapons and cyber-wars," said Eugene Kaspersky, co-founder and chief executive officer of Kaspersky Lab.

Speaking at the Kaspersky Security Symposium with international journalists in Munich, Germany, Kaspersky described Stuxnet as the opening of "Pandora's Box."

"This malicious program was not designed to steal money, send spam, grab personal data, no, this piece of malware was designed to sabotage plants, to damage industrial systems," he said.

"I am afraid this is the beginning of a new world. 90-ies were a decade of cyber-vandals, 2000's were a decade of cybercriminals, I am afraid now it is a new era of cyber-wars and cyber-terrorism," Kaspersky added.

Researchers at Kaspersky Lab independently discovered that the worm exploited four separate zero-day vulnerabilities. Our analysts reported three of these new vulnerabilities directly to Microsoft and coordinated closely with the vendor during the creation and release of software fixes.

In addition to exploiting four zero-day vulnerabilities, Stuxnet also used two valid certificates (from Realtek and JMicron) which helped to keep the malware under the radar for quite a long period of time.

The worm's ultimate aim was to access Simatic WinCC SCADA, used as industrial control systems that monitor and control industrial, infrastructure, or facility-based processes. Similar systems are widely used in oil pipelines, power plants, large communication systems, airports, ships, and even military installations globally.

The inside knowledge of SCADA technology, the sophistication of the multi-layered attack, the use of multiple zero-day vulnerabilities and legitimate certificates bring us to an understanding that Stuxnet was created by a team of extremely skilled professionals who possessed vast resources and financial support.

The target of the attack and the geography of its outbreak (primarily Iran) suggests that this was not a regular cyber-criminal group. Moreover, our security experts who analyzed the worm code insist that Stuxnet's primary goal was not to spy on infected systems, but to conduct sabotage. All the facts listed above indicate that Stuxnet development was likely to be backed by a nation state, which had strong intelligence data at its disposal.

Kaspersky Lab believes that Stuxnet is a working – and fearsome – prototype of a cyber-weapon, that will lead to the creation of a new arms race in the world. This time it will be a cyber-arms race