Display a directory as a web page.

Let’s say you want to allow someone access to files quickly via a web browser on your machine. You can do that with the help of python. All you do is change into the directory you want to serve up and then run the command:

python -m SimpleHTTPServer

Now, whoever needs to view that page simply points their browser to http://ADDRESS_OF_MACHINE:8000

Where ADDRESS_OF_MACHINE is either the IP Address or Domain of the machine (whichever applies). The user will then be able to navigate the files and folders within the directory you are serving up.

Desktop doesn't remember brightness settings after a reboot.

Every time I reboot my laptop the brightness goes back to 100% in Gnome. I wish it would keep the last one setting. Here is a quick workaround for that:-) edit the /etc/rc.local file by typing: vim /etc/rc.local and add the following line:
echo 5 > /sys/class/backlight/acpi_video0/brightness

It looks like this:
root@ProBook:~# cat /sys/class/backlight/acpi_video0/brightness
20
root@ProBook:~# echo 5 > /sys/class/backlight/acpi_video0/brightness
root@ProBook:~# vim /etc/rc.local
root@ProBook:~# cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo 12 > /sys/class/backlight/acpi_video0/brightness

exit 0
root@ProBook:~#

After the reboot the Gnome keeps our settings 🙂

Disabling the SUSE boot splash screen with the little white progress bar.

To disable the green SUSE boot splash screen with the little white progress bar:

vi /boot/grub/menu.lst
and set “splash=silent” to “splash=verbose” That will do 🙂
or/and enter the command echo 0 >/proc/splash on the command line to disable the graphical screen. To activate it again, enter echo 1 >/proc/splash.

iSCSI – Initiator and Target.

The target is the name of the iSCSI server. The iSCSI server offers its devices (disks, tape, dvd/cd, etc.) to the clients. One device can by accessed by a few clients.

At first we have to set up a target server:

debian# apt-get install iscsitarget iscsitarget-dkms

then edit the configuration file:

debian# vi /etc/default/iscsitarget

and then, set ISCSITARGET_ENABLE to true: “ISCSITARGET_ENABLE=true“.

Now, we can create a volume group:

debian# vgcreate vg1 /dev/sdc1

but before that, you have to use fdiks to create Linux LVM partition. The next step is to initializes PhysicalVolume for later use by the Logical Volume Manager (LVM):

debian# pvcreate /dev/sdc1

and then, create a logical volume in an existing volume group:

debian# lvcreate -L2000M -n disk_sdc vg1

Now, we can add the “sdc1” disk to /etc/iet/ietd.conf and comment out everything in that file.


Target iqn.2012-10.com.home:disk.sdc
Lun 0 Path=/dev/vg1/disk_sdc,Type=fileio
Alias LUN1
MaxConnections 0

and then, and start the target:

debian# /etc/init.d/./iscsitarget start

The initiator is the name of the iSCSI client. The iSCSI client has a block level access to the iSCSI devices, which can be a disk, tape drive, DVD/CD writer. One client can use multiple iSCSI devices.

To install the initiator:

debian# apt-get install open-iscsi

and then, edit the /etc/iscsi/iscsid.conf file, and set node.srartup to automatic

node.startup = automatic

and then, restart the initiator:

debian# /etc/init.d/./open-iscsi restart

Discover targets using the discovery record with the recid matching the the discovery type and portal passed in. If there is no matching record, it will be created using the iscsid.conf discovery settings. This must be passed in discoverydb mode to instruct iscsiadm to perform discovery. This option is only valid for SendTargets discovery mode.

To do this:

debian# iscsiadm -m discovery -t st -p 192.168.1.100

output:

debian# iscsiadm -m discovery -t st -p 192.168.1.100
192.168.0.100:3260,1 iqn.2012-10.com.home:disk.sdc

Specify the mode. op must be one of discoverydb, node, fw, host iface or session.
If no other options are specified: for discoverydb and node, all of their respective records are displayed; for session, all active sessions and connections are displayed; for fw, all boot firmware values are displayed; for host, all iSCSI hosts are displayed; and for iface, all ifaces setup in /var/lib/iscsi/ifaces are displayed.

and then:

debian# iscsiadm -m node

and finally we can log in, either by running:

iscsiadm -m node --targetname "iqn.2012-10.com.home:disk.sdc" --portal "192.168.1.100:3260" --login

Ohh… that’s useful:

debian# cat /proc/net/iet/volume
debian# cat /proc/net/iet/vsession

Immediately reboot Linux box.

If you want reboot you Linux box and the reboot, init 6 etc. and these commands do not work for you, or you just want to reboot the system in the very, very fast way, type:

echo b > /proc/sysrq-trigger

This is equivalent to the key combination Alt + SysRq + B which reboots the machine. (Immediately reboot the system, without unmounting or syncing filesystems).

kill – sends a signal to a process.

kill – sends a signal to a process.

For the list of available signals, type:

kill -l

Sample outputs:

1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT
17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU
25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28) SIGWINCH
29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN
35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4
39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12
47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14
51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10
55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6
59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX

SIGHUP (1) – Hangup detected on controlling terminal or death of controlling process.
SIGINT (2) – Interrupt from keyboard.
SIGQUIT (3) – Quit from keyboard (Ctrl-. or, Ctrl-4 or, on the virtual console, the SysRq key)
SIGILL (4) – Terminate the process and dump core.
SIGABRT (6) – Abort signal from abort(3) – software generated.
SIGFPE (8) – Floating point exception.
SIGKILL (9) – Kill signal, kill running process.
SIGTERM (15) – Termination signal.
SIGCONT (18) – Continue process if stopped.
SIGSTOP (19) – Stop process.
SIGSTP (20) – Stop typed at tty (CTRL+z) .

Linking Commands

Julia this is for you:-)

| command1 | command2
Linux shell pipes join the standard output of command1 to the standard input of command2. Output of the ps command is provided as the standard input to the grep command.
ps aux | grep bash

|| command1 || command2
Command2 is executed if, and only if, command1 returns a non-zero exit status i.e. command2 only runs if first command fails.
tar cvf user.tar.gz /home/user || mail -s ‘Backup failed’ user@domain.com < /dev/null && command1 && command2
Command2 is executed if, and only if, command1 returns an exit status of zero i.e. command2 only runs if first command1 run successfully.
apt-get update && apt-get upgrade

& command arg &
The shell executes the command in the background in a subshell. The shell does not wait until the command finish, and the return status is 0. The & operator runs the command in background while freeing up your terminal for other work. For example: find command is executed in background while freeing up your shell prompt.
find /home/user -name “*.jpg” > /tmp/usersjpg.txt &

; command1 ; command2
Separates commands that are executed in sequence. For example, ps is executed only after date command completes.
date ; ps

Copy files/folders accross a network in Linux using ssh, tar, scp and rsync.

SCP or secure copy is probably the easiest of all the methods, its is designed as a replacement for rcp, which was a quick copy of cp with network funcationability. Before scp does any copying it first connects via ssh. SCP encrypts data over your network connection, but by using the -C switch you can compress the data before it goes over the network. This can significantly decrease the time it takes to copy large files.

scp -r directory user@server:~/

or default port

scp "-P 7787" -r directory user@server:~/

TAR is usually used for achiving applications, but what we are going to do in this case is tar it then pipe it over an ssh connection. TAR handles large file trees quite well and preserves all file permissions, and works quite well with symlinks.

tar -czf - directory | ssh -p 7787 user@server tar -xzf - -C .

or default port

tar -czf - directory | ssh user@server tar -xzf - -C .

or

tar -xzf - directory | ssh user@server "cat > /directory/tarball.tar.gz"

or

dpkg -l | ssh user@server "cat > /directory/dpkg-list.txt"

RSYNC speciality lies in its ability to analyse files and only copy the changes made to files rather than all files. This can lead to enormous improvements when copying a directory tree a second time.

rsync -avze "ssh -p 7787" directory user@server:~/

or default port

rsync -avze ssh directory user@server:~/