Thursday 1 September 2016

Dealing with permissions in the fat 32 sd card in linux system


-----------
FAT filesystems really don't have permissions.

The way that linux handles this is that when you mount a FAT drive, all
the files are given the _same_ file permissions at mount time.
Furthermore, once mounted, these permissions can't be modified.

The default permissions that mount will use for FAT partitions is
"rwxr-xr-x". To change this, you can add an option "umask=" in the fstab
file. For example, on my computer, I use:

/dev/hda1       /mnt/c          vfat    defaults,umask=0000 0 0

The argument to umask is and octal number. To understand what this number
means, you have to understand how file permissions actually work in unix.

The way file permissions are stored on the disk is as a 9-bit binary
number. The best way to show this is with examples. File permission are
commonly represented in three ways:

rwxr-xr-x  - human readable
111101101  - binary number
7  5  5    - 3 octal numbers

The last one is the most important. If you read the manpage for chmod, you
will notice that you can specify the desired permissions using and octal
number. Examples:

gsteele@atlas:~$ chmod 0755  foo
gsteele@atlas:~$ ls -l foo
-rwxr-xr-x    1 gsteele  gsteele   1123166 Mar 27 11:42 foo*
gsteele@atlas:~$ chmod 0766  foo
gsteele@atlas:~$ ls -l foo
-rwxrw-rw-    1 gsteele  gsteele   1123166 Mar 27 11:42 foo*
gsteele@atlas:~$ chmod 0777  foo
gsteele@atlas:~$ ls -l foo
-rwxrwxrwx    1 gsteele  gsteele   1123166 Mar 27 11:42 foo*

(Note: the first number is related to "special file permissions". You
should always leave this number as 0. You can read about these here:
http://www.lns.cornell.edu/public/COMP/info/fileutils/fileutils_3.html#SEC4)

Now, umask is like the binary NOT of the file permissions you want. For
example:

rwxr-xr-x  - desired file permissions
111101101  - binary file permissions
000010010  - umask
0  2  2    - octal umask

So, for example, in my fstab file, I use umask=0000, so that the
permissions on my dos drive are rwxrwxrwx. If you wanted the permissions
on the dos drive to be rwxrwxr-x, you would set umask=0002.
---------------
 

Extracted from http://electron.mit.edu/~gsteele/linuxfaq/index.html#2

Wednesday 31 August 2016

Process running in background

Keeping a process running after ending ssh session could be very useful.

-------
The best way is often the simplest.
nohup long-running-command &
It was made specifically for this, it even logs stdout to nohup.log
man nohup
If you want to "background" some already running tasks, then your best bet is to ctrl+z then run
bg (this will background your most recent suspended task, allowing it to continue running)
then a quick disown should keep the process running after you log out.
screen and others can do it, but that's not what they're for. I recommend nohup for tasks you know your going to leave behind and bg for tasks your already running and don't want to re-start.
Keep in mind, both are bash specific. If you're not using bash, then the commands could be different.
----
Extracted from http://askubuntu.com/questions/8653/how-to-keep-processes-running-after-ending-ssh-session

Friday 26 August 2016

Tip - place for scripts

* A place for putting common scripts (with execution permission) that must be available for all the system is

/usr/local/bin
It can be called in any location.   



* Also,when trying to run commands or scripts on startup you can put the required command to run inside the file
~/.bashrc for a local command
or
/etc/bash.bashrc for a global command (for example a command that requires sudo). 

Both of the above commands will ask for the sudo passwork. If you do not put sudo, the script will not run if it requires administrative priviledges

You can also put a command that requires sudo inside your local .bashrc but you will be asked to put the sudo password everytime your start a command line or the .bashrc is processed (for example when running source ~/.bashrc)


* Also, to run an administrative command without having to put the admin password and that you want to be executed at the end of each multiuser runlevel, put your command in the file

/etc/rc.local
Also, take into account that you do not need to put sudo, the execution of this file has already administrative priviledges .
 
Do not forget to finish the command by providing an exit value. 0 means sucess and any other value means error.
Example:  
exit 0 
 
 
* For other related information, visit:
http://askubuntu.com/questions/228304/how-do-i-run-a-script-at-start-up

Friday 19 August 2016


Setting static ip for your network card
 Edit the file /etc/network/interfaces and add this:

auto wlan0
iface wlan0 inet static
address 10.0.1.1
gateway 10.0.1.1
netmask 255.255.255.0
network 10.0.1.0
broadcast 10.0.1.255

wpa-ssid 'mynetwork'
wpa-psk '12345'


In order for this to take effect the networking service must be restarted
$ sudo /etc/init.d/networking restart


For more info, look here-> https://help.ubuntu.com/community/NetworkConfigurationCommandLine





Thursday 18 August 2016

Computers in a network




Arp-scan can scan the computers in a network
* Using Wi-Fi:
sudo arp-scan -l --interface=wlan0
* Using ethernet:
sudo arp-scan -l --interface=eth0 
* Connection by usb 
sudo arp-scan -l --interface=usb0
 
Answer from system:
Interface: usb0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8.1 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.2.15 02:00:86:9b:2a:ad (Unknown)

1 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.8.1: 256 hosts scanned in 1.289 seconds (198.60 hosts/sec). 1 responded

Thursday 5 May 2016


Python Function Arguments

In contrast to many languages, python has several types of parameters to be sent to a function:
  • Required arguments
  • Keyword arguments
  • Default arguments
  • Variable-length arguments
A tutorial about that is here: 
http://www.tutorialspoint.com/python/python_functions.htm


Tutorial to work with Python and Opencv

Complete tutorial.
http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/