post_test

September 5th, 2020

Test123

How to use bash functions

August 4th, 2020

When you have a complex task to be done in bash, often using bash function will save you time reusing the same part of code.
In this tutorial, you can see how to use bash functions.

You can define a bash function in two ways:

function_name() {
#function code
}

If you use the function keyword you can omit the () parentheses:

function function_name {
#function code
}

After you have defined the function, you can call it writing its name:

function_name() {
#function code
}
function_name

If you want to pass arguments to the function you can just add it after the function call:

function_add() {
TOTAL_NUMBER=$(($1+$2))
}

function_add 5 3
echo “Total number is: $TOTAL_NUMBER”

this code will write:
Total number is: 8

In the upper code we used a global variable, you can also use the echo from a function to return a variable from the function:

function_add() {
TOTAL_NUMBER=$(($1+$2))
echo $TOTAL_NUMBER
}

FINAL_NUMBER=$(function_add 5 3)
echo “Total number is: $FINAL_NUMBER”

If you have any questions or improvements leave a comment !

How to repeat a command n times in Bash

August 3rd, 2020

Here a simple tutorial on how to repeat a command n times in Bash:

for i in {1..5}
do
echo “Command number:$i”
done
This example will print this output:

Command number: 1
Command number: 2
Command number: 3
Command number: 4
Command number: 5

we can write it as a single line too:
for i in {1..5}; do echo "Command number: $i"; done

If we need a condition-based expressions, we can use this approach as well:

for ((i=1;i<6;i++)); do echo "Command number: $i"; done

The same can be done using the while loop:

i=1
while [[ $i -le 5 ]]; do
echo "Command number: $i"
let ++i;
done

And we can write the above in the one line format too:
i=1; while [[ $i -le 5 ]]; do echo “Command number: $i”; let ++i; done

Open Network Object System(O.N.O.S)

April 20th, 2020

This project name is O.N.O.S that stand for Open Network Object System and it is an home automation system .
Using O.N.O.S. is possible to control any electric device with a single click.
The system is simple and user frendly in fact you can start using it within 5 minutes after removal from the box
(out of the box concept).
The user only has to insert the power plug to the ‘OnosCenter’ (the main brain of the system) and O.N.O.S. will make all the remaing work (no configuration required).
The mission of this project is to make users (also without computer and electrical knowledge) able to install and customize their own home automation system .
Without the need to call electricians, broke the walls and rewire the house and especially without spending a pile of money.

O.N.O.S. is modular so the user can start buying only the OnosCenter (wich allow to controll one power socket) and then he can buy only the modules needed.

The main difference between O.N.O.S and the other automation systems is that it doesn’t require using new wires or radio signals
because all the data transmission travels through the power line wires (powerline technology
http://en.wikipedia.org/wiki/Power-line_communication).
In order to use O.N.O.S. you don’t have to install any software or application since the system serves a webpage wich any device having a browser will be able to displays. (phones , tablets ,pcs ebook readers and so on)

The system works also locally so without using internet you could just connect to your local network ! this feature is not avaible in the cloud based automation systems.

Another big advantage in comparison to other systems is the fully customizable interface both in the graphics and in the zones division.
Is possible to modify the colour and the shape of the buttons that control the electrical appliances( is also possible to use pictures).
The zones division is easily configurable and within few clicks the user can renames and subdivides the electrical devices in each room.

Watch the demo videos :

Working :
The main pc also called OnosCenter communicates through the powerline to the other nodes (wich are the O.N.O.S devices to whom the user will connect the electrical appliances) .
When the user goes to the O.N.O.S. the OnosCenter will create a webpage based on the nodes status (turned on , off ..), pressing on a button the user will be able to change the node status associated with the button.
Then the button will change text and colour in order to confirm the successful operation.
If a node was shut down or unreachable the button will show this with a gray colour , so the user will know that the transaction is pending.
This ensures the user will always know the true status of the appliances controlled.

Technical notes (useful only to developers):

O.N.O.S. is released under open source license, this to enhance its development and to enable users to improve it further.

The software is completely free and can be run on any device wich has python so any pc with linux including the raspberry pi and BeagleBone will be fine (even on some routers with openwrt you can run it!)

No installation required, you just download the program and run it with python.

We hope to allow more people to ‘play’ with the internet of things for this reason the project was licensed under the open source GNU General Public License 3, which allows free use.

O.N.O.S. was developed using mainly build-in python libraries therefore does not require the installation of any additional libraries.

The O.N.O.S. nodes are Arduino based , you can build them yourself and so easily adapt the system to your needs.

If you have some question or suggestions please leave me a comment!

Stability Problem and boot fail with linux on amd1090t

April 14th, 2020

Once installed Debian Wheezy 7.3 on my pc , an Amd phenom 2 x6 1090t mounted on a asrock 890gx extreme 3 I discovered that often the system logs shows a boot error.
It was : rcu_sched detected stalls on CPUs/tasks:
All I could do then was to reboot the pc with the physical button.
Some other times after the boot had been succesfull my pc froze and I had to reboot again with the physical button .
Finnaly I discovered how to solve my problems.
I installed the driver amd64-microcode from the repositories and now my system is stable and never fail a boot.
amd64-microcode is a linux driver for amd processor.
So in order to install it open a terminal and execute those commands:


sudo apt-get update

sudo apt-get install amd64-microcode


if you don’t use hdmi audio and have an ati vga you should also edit the file user-blacklist.conf as follows:
sudo nano /etc/modprobe.d/user-blacklist.conf
Insert this in the file this line:

blacklist snd_hda_codec_hdmi

That’s it,  if I helped you please let me know with a comment.

How to compress all the folders in a directory with rar on Linux

April 14th, 2020

To compress all the folders in a directory on the current path (only the folders)
Open a bash terminal , move to the wanted path with cd , then type:


for dir in */
do
base=$(basename "$dir")
rar a "${base}" "$dir"
echo $base >> "log"
rm -rf "$base"
done

Press enter.
Each folder will be replaced with a rar file with the same name and the same files the folders had.
Try this on some test folders before using it on the final folders..

How to load all linux system in ram and increase considerably the pc speed

April 14th, 2020

Hello to everyone in this article I’m going to show you how to load all your linux system os to the ram

in order to get an outperforming pc with incredible speed.

Warning :

I recommend you make a back up of your system before following this guide.

I do not assume any responsibility for the loss of your data.

Requirement :

–At least 8 Gb of ram

–An operative system debian based, I tried on debian 7.02 and debian 6.06

probably it will work also on Ubuntu and others distro derived from debian.

–Medium knowledge of the linux terminal

Advantages:

At the end of this guide, you will have the faster system you have ever seen!!

Faster than any system installed on ssd!

In addition, we will create 2 grub entries that will allow you to choose

to run the system on the hard disk or on the ram.

When you choose to start on ram all changes made to the system in this mode will be

forgotten once restarted.

This means that you can install programs, test terminal commands

and other such things without fear of corrupting your system!

Disadvantages:

The startup may take up to 10 minutes depending on which hard drive you have and how much space occupies your Linux system.

During startup you will see a black screen with a blinking white cursor.

When you reboot you lose all data and changes that you have saved on the hard disk

you can avoid this problem in various ways which I will explain later.

Why on earth did I think to run the entire system on ram?

Because after I bought and assembled the pieces of my pc it was not

as fast as I wanted.

My pc was as follows:

Amd Phenom 2 X6 Black Edition

Motherboard ASRock 890GX Extreme3

16 GB G.SKILL DDR3 1600

I recently added an Ati 7970xfx Ghost Edition

After installing Mint Debian Edition I had an average fast system but I didn’t build

my pc to have a “just” average fast system.

So I decided to investigate and discover what did slow down my pc.

I found out that the problem are my hard disks.

I found an interesting post where they teach me how to remedy.

http://reboot.pro/topic/14547-linux-load-your-root-partition-to-ram-and-boot-it/

I decided to try the post’s guide.

The first time I thought the pc was not going to boot so I restarted it.

After that I understood that the pc needs more time to copy all the data from the hard disk to the ram.

I waited with the black screen and after about 12 minutes the pc showed me the login screen.

I tried the system and I was impressed by the responsiveness of the pc!

It was instantaneous!

You click to run a program and after you released the finger on the mouse the program is already there! Wonderful!

So I decided to write this guide.

Why loading on your ram all your system the pc become so faster?

Because the slower part fo the pc is the only mechanical part! the pc hard disk!!!

Every time you run a program it is read from the hard disk.

Also, the faster hard disk is a bottleneck for the nowadays PCs (warning this article is old, so now there are some pretty fast SSD )

Removing all the hard disk reading and writing process you remove a long waiting time!

The Ram is a lot faster than any hard disks.

DDR3 ram is rated from 6400 MB/s to 12800 MB/s varying from the model.

A solid-state disk is rated from 250MB/s to 600 MB/s varying from the model.

A rotary hard disk is rated from 50 to 150MB/s varying from the model.

Now you can see that the speed of the slower DDR3 ram is about 42 times faster

than the fastest rotary hard disk!

Your pc will not run 42 times faster but you will notice a great difference

and it is worth the work to gain that.

Let’s start with the guide:

I started with a version of Debian 7.2 installed from net cd so I installed

the bare minimum programs and Mate graphical interface.

Open a terminal

Write the following in order to make a back up of the fstab file:

sudo cp /etc/fstab /etc/fstab.bak

Now open with your favorite text editor as an administrator the file:

sudo pluma /etc/fstab or sudo gedit /etc/fstab or sudo nano /etc/fstab

Look for the line where there is the root partition /

Mine was written like this:

UUID=b4a375f0-3cae-41ec-a130-fd9fa5207b07 / ext4 noatime,errors=remount-ro 0 0

Make sure that on your old line of the root fsck is disabled so there should be 2 zeros as the end of the line, like in my example.

If there are not 2 zeros replace the numbers with two zeros

after that restart your PC.

Reopen the file and proceed as before.

At this point, replace the line of the root with:

none / tmpfs defaults,noatime,nodiratime,discard 0 0

Save and close the file.

Move yourself typing in the terminal:

cd /usr/share/initramfs-tools/scripts/

Make a copy of the file local with:

sudo cp local local.bak

Open with your favorite text editor as an administrator the file:

sudo pluma local or sudo gedit local or sudo nano local


Search a part like this:
# FIXME This has no error checking
# Mount root
if [ "${FSTYPE}" != "unknown" ]; then
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}
else
mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt}
fi[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
run_scripts /scripts/local-bottom
[ "$quiet" != "y" ] && log_end_msg}

In particular, you should find the line # Mount root that tells you that you are in the right place.
Replace the lines with following ones :

# FIXME This has no error checking
# Mount root
mkdir /ramboottmp
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /ramboottmp
mount -t tmpfs -o size=100% none ${rootmnt}
cd ${rootmnt}
cp -rfa /ramboottmp/* ${rootmnt}
umount /ramboottmp
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
run_scripts /scripts/local-bottom
[ "$quiet" != "y" ] && log_end_msg
}

Depending on the version of Linux you have ,you could have to change the lines
but should not differ by much.

Save and close the text editor.

Now run from terminal:
sudo mkinitramfs -o /boot/initrd.img-ramboot
May print 2 warning but is usual.

Restore now the old local with:
sudo cp -f local.bak local
Open the file /boot/grub/grub.cfg with your favorite text editor as an administrator :
sudo pluma /boot/grub/grub.cfg oppure sudo gedit /boot/grub/grub.cfg
Find the first part that look like this:
menuentry 'Debian GNU/Linux, con Linux 3.2.0-4-amd64' --class debian --class gnu-linux --class gnu --class os {
load_video
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd2,msdos1)'
search --no-floppy --fs-uuid --set=root b4a375f0-3cae-41ec-a130-fd9fa5207b07
echo 'Caricamento Linux 3.2.0-4-amd64...'
linux /boot/vmlinuz-3.2.0-4-amd64 root=UUID=b4a375f0-3cae-41ec-a130-fd9fa5207b07 ro quiet
echo 'Caricamento ramdisk iniziale...'
initrd /boot/initrd.img-3.2.0-4-amd64
}

Copy and paste it just above modifying it as following

In menuentry add a label that let you know that is the entry to run the system on ram :
I added RAM!!! (make sure to not made it too long or maybe will not work)
Now where is written :
initrd /boot/something
replace something with:
initrd.img-ramboot
My menuentry is like this:
menuentry 'Debian GNU/Linux,Linux3.2.0-4-amd64 RAM!!!' --class debian --class gnu-linux --class gnu --class os {
load_video
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd2,msdos1)'
search --no-floppy --fs-uuid --set=root b4a375f0-3cae-41ec-a130-fd9fa5207b07
echo 'Caricamento Linux 3.2.0-4-amd64...'
linux /boot/vmlinuz-3.2.0-4-amd64 root=UUID=b4a375f0-3cae-41ec-a130-fd9fa5207b07 ro quiet
echo 'Caricamento ramdisk iniziale...'
initrd /boot/initrd.img-ramboot
}

We created another grub entry equal to the original but that start with:
initrd /boot/initrd.img-ramboot
instead to start with
initrd /boot/initrd.img-3.2.0-4-amd64

So it load the system on Ram

At this point save and close the file.

Reboot and now you should have a new entry in the grub

Choose it and after 10 -15 minutes your pc will show you your linux system.

Now you have an extremely fast system

Rebooting and choosing the old grub entry you can run the old system .

Changing this system you will change also the on ram system.

I have the home folder almost empty and my system occupies 3.7 Gb then for me
6 Gb of ram would be enough to run the whole system in ram.
Because my system would use 4 Gb of ram to store the os files and the others 2 Gb as usual ram.

With 8 Gb you could probably run almost any os linux system in ram.

I recommend you to store all the files in a different partition.
So store only the programs configurations in your home folder.

In order to have a faster boot (from 15 minutes to 1 minute) i use a ssd .
Doing so the copying time from the ssd to ram is reduced a lot

I discovered recently that the suspend to ram feature works good on my linux pc .
So in 20 seconds my pc is ready after been suspended to ram!

If you have some questions ,suggestion ,corrections or you just like my articles please leave a comment.
Share this article to improve the computers speed and to spread the linux use.

Thanks to Tibor Áser Veres here the guide to run Ubuntu 16.04 LTS on ram:

Here is an Ubuntu version I made:
Step 1:
Make a copy of your initrd.img just in case…
you use a live session to restore it if it won’t boot
sudo cp /boot/initrd.img-x.x.x-xx-generic /boot/initrd.img-x.x.x-xx-generic.old replace the “x” characters with your system specific numbers…

Step 2:
Edit: /etc/default/grub in order to see the prompt form normal/ramboot mode…
Change: GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” >> GRUB_CMDLINE_LINUX_DEFAULT=””
Edit it with nano: sudo nano /etc/default/grub
Step 3:
Run update-grub after changes to take place… sudo update-grub

Step 4:
Edit: /usr/share/initramfs-tools/scripts/local You may want to use gedit,
so that you can search with ctrl+F in the file
Find this 2 lines in the script(search for: “# Mount root” FIXME line appears at more places, and it may be temporary until it’s fixed…):
# FIXME This has no error checking # Mount root Paste this under “# Mount root” line: ### Custom modification starts ### read -t 10 -p ‘Do you want to boot normally? (enter Y if so…)’ Yy case $Yy in [Yy]* ) clear echo ‘Booting normally’ mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt} ;; *) clear echo ‘Booting in RAM’ mount -t tmpfs -o rw,noatime,nodiratime,size=100% tmpfs ${rootmnt} mkdir /ramboottmp mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} /ramboottmp cp -rfa /ramboottmp/* ${rootmnt} umount /ramboottmp rm /ramboottmp ;; esac ### End of custom modifications ###

Remove or uncomment these lines: mount ${roflag} ${FSTYPE:+-t ${FSTYPE} }${ROOTFLAGS} ${ROOT} ${rootmnt}

Step 5:

sudo mkinitramfs -o /boot/initrd.img-x.x.x-xx-generic replace the “x” characters with your system specific numbers…

Final step: sudo reboot

How to launch custom scripts from right click menu on caja

April 14th, 2020

In order to create a script to launch it from mouse right click menu on caja you have to create a bash script and put it on :
/home/user/.config/caja/scripts/
Where you have to replace user with your username
After that make the script executable with:
sudo chmod +x nomescript.sh

A useful script is this one that compress the selected folder and then delete it keeping only the compressed one.
Use it at your own risk

prefix="file://"
string=$(echo $CAJA_SCRIPT_SELECTED_URIS | tr "%20" " " )  #replace %20 with double space
string=$(echo $string | tr "  " " " )  #replace double space with single space
#echo  "$string" >> a
file_path=$(echo "$string" | grep -oP "^$prefix\K.*")  #remove file:// from filename
current_file=$(basename "$file_path")  #get the name after the last slash
#echo  "$file_path" >> a
#echo  "$current_path" >> a
zip -r -j "$current_file" "$current_file" && rm -rf "$current_file"  #compress the file and delete the original

Method tested on debian 9 with Mate and Caja filemanager.

Best Pc hardware for gaming using virtual reality headset Lenovo Explorer

November 3rd, 2019

This is my setup that I’m currently using to play on steam with the VR headset Lenovo Explorer.

I think Lenovo Explorer is the most affordable way to try Vr experience on pc because the cost is much smaller that any other headset with similar characteristics.

Here is my Pc setup:

Cpu: Intel i7 8700
Intel Core i7 8700 Cpu Processore, Argento

Motherboard:
Asrock Z370 Extreme4 LGA 1151

Asrock Z370 Extreme4 LGA 1151 (Socket H4) ATX motherboard – Motherboards (DDR4-SDRAM, DIMM, 2133,4333 MHz, Dual, 64 GB, Intel)

Ram:
I Have bought a bit too much ram
Corsair Vengeance LPX 32 gb 3000MHZ

Corsair Vengeance LPX Memorie per Desktop a Elevate Prestazioni, 32 GB (2 X 16 GB), DDR4, 3000 MHz, C15 XMP 2.0, Nero

SSD:Samsung MZ-V7E250BW SSD 970 EVO, 250 GB, M.2, NVMe, Nero/Arancione

Video card: Nvidia gtx 1017 Ti

With these components the Pc

Come lanciare script personalizzati con il menu del pulsante destro di caja

June 17th, 2018

Per creare uno script ed eseguirlo dal menu del pulsante destro di caja basta creare uno script bash e metterlo in :
/home/user/.config/caja/scripts/
Dove al posto di user va messo il proprio utente.
Poi si deve rendere lo script eseguibile con sudo chmod +x nomescript.sh

Un esempio di script molto utile è questo sotto che comprime la cartella selezionata e poi la cancella tenendo solo la cartella compressa.
Usatelo a vostro rischio e pericolo.


prefix="file://"
string=$(echo $CAJA_SCRIPT_SELECTED_URIS | tr "%20" " " )  #replace %20 with double space
string=$(echo $string | tr "  " " " )  #replace double space with single space
#echo  "$string" >> a
file_path=$(echo "$string" | grep -oP "^$prefix\K.*")  #remove file:// from filename
current_file=$(basename "$file_path")  #get the name after the last slash
#echo  "$file_path" >> a
#echo  "$current_path" >> a
zip -r -j "$current_file" "$current_file" && rm -rf "$current_file"  #compress the file and delete the original

Metodo testato con debian 9 con Mate e gestore file Caja.