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:~/

Vim commnads.

You can save a lot of time when navigating through text by using appropriate movement commands.
Here are some basic commands:

e Move to the end of a word.

w Move forward to the beginning of a word.

3w Move forward three words.

b Move backward to the beginning of a word.

3b Move backward three words.

$ Move to the end of the line.

0 Move to the beginning of the line.

^ Move to the first non-blank character of the line.

) Jump forward one sentence.

( Jump backward one sentence.

} Jump forward one paragraph.

{ Jump backward one paragraph.

H Jump to the top of the screen.

M Jump to the middle of the screen.

L Jump to the bottom of the screen.

20 or 20 Move 20 pages up.

10 or 10 Move 10 pages down.

G Jump to end of file.

1G Jump to beginning of file the same as gg.

10G Jump to line 10.

'm Jump to the beginning of the line of mark m.

`m Jump to the cursor position of mark m.

'' Return to the line where the cursor was before the latest jump.

`` Return to the cursor position before the latest jump.

% Jump to corresponding item, e.g. from an open brace to its matching closing brace.

Source link

Mounting a NetWare volume on a Linux box

To mount a NetWare volume on a Linux box, the ncpfs must to be installed on a Linux box.
For a “rpm” distribution:

yum install ncpfs

For a “deb” distribution:

apt-get install ncpfs

then try mount the volume on the Linux box:

ncpmount -A 192.168.1.25 -S name_of_netware_server -V volumin_to_mount -U username.context -P password /mnt

to add this to /etc/fstab please use the following:

nbcs_data_server/xxhr.genacc.ndsadmin /share/Shared/XXHR/EBSPROD ncp volume=data/Shared/XXHR/EBSPROD,uid=ebsprod,gid=dba,mode=660,owner=root,A=nbcs_gisdata_server,passwdfile=/etc/edirpass 0 0

and create an edirpass password file in /etc/edirpass

echo "nbcs_gisdata_server/xxhr.genacc.ndsadmin:password" >> /etc/edirpass

Broken Grub menu – Debian.

Broken Grub menu: boot to the menu, drop to a consloe and boot Debian direct.
Sometimes the only thing that works when you boot is the Grub menu appears on your screen.
When you see Grub’s boot menu on your screen, instead fo selecting a boot item, press the “c” key.
That brings up a messages like this:

GNU GRUB version 1.99-14
Minimal BASH-like line editing is supported. For the firs word,
TAB lists possible command completions. Anywhere else TAB lists
posssible device or file completions. ESC at any time exits.

grub>

Now carry out the following commands at the grub prompt:

grub> search.file /sbin/init
hd0,msdos1
grub> search.file /boot/grub/device.map
hd0,msdos1
grub> search.file /vmlinuz
hd0,msdos1

Whatever you use, will ok. What we looking for is:
– Grub pointer to my Debian installation on drive number 1, partition number 1, your pointer
will be different from my example (hd0,msdos1)
– UUID assigned to this partition 625b756b-737e-4502-a914-9d351d50603a


grub> ls (hd0,msdos1)
Partition hd0,msdos1: Filesystem type ext2 - Last modification time
2012-01-11 10:57:44 Wednesday, UUID 625b756b-737e-4502-a914-9d351d50603a -
Partition start at 2048 - Total size 40134656 sectros
grub> set root='(hd0,msdos1)'
grub> linux /boot/vmlinuz-{press TAB key}
Possible files are:
vmlinuz-2.6.32-5-686 vmlinuz-3.2.0-1-686-pae
grub> linux /boot/vmlinuz-3.2.0-1-686-pae ro root=UUID=625b756b-737e-4502-a914-9d351d50603a
grub> initrd /boot/initrd.img-{press TAB key}
Possible files are:

initrd.img-2.6.32-5-686 initrd.img-3.2.0-1-686-pae
grub> initrd /boot/initrd.img-3.2.0-1-686-pae
grub> boot

and the machine boots 🙂

Yum local repository to be able to access a CDROM/DVD iso.

You do not have access to the network and you would like to install some packages from CDROM/DVD, please follow the instructions:

First take a backup of /etc/yum.repos.d/ then remove these repo files:
CentOS-Base.repo, CentOS-Debuginfo.repo and CentOS-Media.repo
and add a new file called CentOS_local.repo with the following lines:

[root@localhost yum.repos.d]# cat CentosOS_local.repo
[dvd]
name=Centos DVD
baseurl=file:///media #mount location
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]#

Here baseurl=file:///media is the location of CentOS iso. Now you have to mount your CentOS iso into the media folder:

[root@localhost]# mount /dev/cdrom /media

Once this is done, you can go ahead with yum to install packages from CD/DVD.