Posts

Showing posts from July, 2018

ypbind - NIS binding process | ypcat -k netgroup | ypcat -k netgroup.byuser

ypbind  finds the server for NIS domains and maintains the NIS binding information ellington % ypcat -k netgroup ellington % ypcat -k netgroup.byhost ellington % ypcat -k netgroup.byuser ypcat passwd" is showing all users passwords in NIS server # /etc/nsswitch.conf # # Example configuration of GNU Name Service Switch functionality. # If you have the `glibc-doc' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. passwd: compat group: compat shadow: compat hosts: files dns mdns networks: files protocols: db files services: db files ethers: db files rpc: db files netgroup: nis There are three types of hosts in an NIS environment: master servers, slave servers, and clients. Servers act as a central repository for host configuration information. Master servers hold the authoritative copy of this information, while sla

ls | lsblk (drives) | lspci | lsusb | lsdev | iostat list drives

ls - list files in the file system. lsblk - list the block devices (i.e. drives) lspci - list the pci devices. lsusb - list the USB devices. lsdev - list all the devices.

What's the difference between eval and exec

eval  will run the arguments as a command in the current shell. In other words  eval foo bar  is the same as just  foo bar . But variables will be expanded before executing, so we can execute commands saved in shell variables exec  does not create a new process. It  replaces  the current process with the new command. If you did this on the command line then it will effectively end your shell session (and maybe log you out or close the terminal window!) $ eval x = 42 $ echo $x 42 $ exec x = 42 bash : exec : x = 42 : not found

hash -r # Reload command path cache. If you ever move a command binary around, you may need to run this to pickup the new location.

hash -r # Reload command path cache. If you ever move a command binary around, you may need to run this to pickup the new location.

xargs

Image

Checking for a null column in a csv file | awk -F '\\|' '$3==""' file.txt

I have a delimited file with the following syntax: A|B|C|D|E How to find the count of records having null (empty) value in their third column in every ro One way: awk -F"|" '{if (length($3) == 0) ++count } END { print count }' yourfile % cat file.txt A|B|C|D|E A|B|C|D|E A|B||D|E % awk -F '\\|' '$3==""' file.txt A|B||D|E

Install your Certificates on Apache (OpenSSL)

How to determine if OpenSSL and mod_ssl are installed on apache2 Usually, when you compile your apache2 server (or install it by packages facility stuff), you can check any directive that're available to be used by tapping this command: ~# $(which httpd) -L | grep SSL # on RHEL/CentOS/Fedora ~# $(which apache2) -L | grep SSL # on Ubuntu/Debian If you don't see any SSL* directive, it means that you don't have apache2 with mod_ssl compiled. For RHEL/CentOS/Fedora: $ httpd -t -D DUMP_MODULES | grep ssl ssl_module (shared) For Ubuntu/Debian $ apache2 -t -D DUMP_MODULES | grep ssl ssl_module (shared) ---------------- Apache SSL Installation Instructions Save the primary and intermediate certificates to a folder on the server with the private key. Open the Apache configuration file in a text editor. Apache configuration files are usually found in /etc/httpd. The main configuration file is usually named httpd.conf. In most cases the <VirtualHost> b

dmesg command is used to display the kernel related messages | dmesg -T | dmesg --level=err,warn

dmesg  command is used to display the kernel related messages on Unix like systems. dmesg stands for “ display message or display driver Display colored messages (dmesg command output) Use  ‘-L’ option in dmesg command if you want to print the colored messages, ~]# dmesg -L Restrict dmesg command output to specific list of levels Following are specific log levels supported by dmesg command, emerg alert crit err warn notice info debug Let’s assume we want to display logs related to error and warning,  then use “–level” option followed by levels like err & warn, example is shown below ~]# dmesg --level=err,warn Enable timestamps in dmesg logs There can be some scenarios where we want to enable timestamps in dmesg, this can be easily achieved by using ‘-T’ option in  dmesg command. ~]# dmesg -T …………………………………………… Wed May  9 12:20:36 2018] rx_data returned 0, expecting 48. Monitor real time dmesg logs using ‘–follow’ option Use ‘–follow’ option in dm

How to monitor process status during process lifetime | strace -f -p $! -o child.txt

strace - trace system calls and signals $ main.exec & $ strace -f -p $! -o child.txt -f Trace child processes as they are created by currently traced processes as a result of the fork(2), vfork(2) and clone(2) system calls. Note that -p PID -f will attach all threads of process PID if it is multi-threaded, not only thread with thread_id = PID

how to get /proc/*/environ | strings /proc/$PID/environ | xargs -n 1 -0 < /proc/pid/environ

1. xargs - n 1 - 0 < / proc / pid / environ 2. strings / proc / $PID / environ

Test Your Server Configuration Before Restarting Unix and Linux Services

A Note About Reloading Servers The syntax is as follows under Linux: /sbin/service SERVICE-NAME [reload|restart] OR /etc/init.d/SERVICE-NAME [reload|restart] OR systemctl reload SERVICE-NAME-HERE The reload option reloads the config file without interrupting pending operations. For example the following command will reload Apache web server after the config file changes: # /sbin/service httpd reload OR # systemctl reload httpd However, most Linux and Unix-like daemon programs sometimes use SIGHUP as a signal to restart themselves, the most frequent reason for this being to re-read a configuration file that has been changed. The syntax is as follows: kill -HUP $(cat /var/run/SERVICE.pid) OR kill -HUP `cat /var/run/SERVICE.pid` Let us see how to test the syntax for various Linux and Unix services. #1: OpenSSH Server You can use the  following syntax to test OpenSSH config file , type: # /usr/sbin/sshd -t && echo $? A sample configuration error session: # usr/sbin/sshd -t

xargs | ls | xargs -t -I {} mv {} {}.old | find . -name "*.sh" -print0 | xargs -0 -I {} mv {} ~/back.scripts

To insert file names into the middle of command lines, type: um@server#ls | xargs  -t  -I  {} mv {} {}.old This command sequence renames all files in the current directory by adding .old to the end of each name. The -I flag tells the xargs command to insert each line of the ls directory listing where {} (braces) appear. If the current directory contains the files chap1, chap2, and chap3, this constructs the following commands: #mv chap1 chap1.old #mv chap2 chap2.old #mv chap3 chap3.old Find all the .mp3 files in the music folder and pass to the ls command, -print0 is required if any filenames contain whitespace.:    find ./music -name "*.mp3" -print0 | xargs -0 ls Find all files in the work folder, pass to grep and search for profit:    find ./work -print | xargs grep "profit" {} as the argument list marker {} is the default argument list marker. You need to use {} this with various command which take more than two arguments at a time. For example mv

jobs and running processes in background | jobs | ctrl+z pause | bg |

(method 1) ALREADY RUNNING PROCESS INTO BACKGROUND Pro:    Puts running process into background Con:   If you quit out of the shell window the process stops Reference:  http://www.unix.com/unix-advanced-expert-users/78975-make-foreground-running-process-run-background-without-hang-up.html 1.  Ctrl-z 2.  jobs or alternate method which lists the PID (note the PID is not the jobnum, the job number is shell specific to the current bash session):  jobs -l 3.  bg %jobnum or alternate method  %jobnum &  for example for the first job  %1 & To place a foreground process in the background: suspend the foreground process (with Ctrl-z) then enter the bg command to move the process into the background. Show the status of all background and suspended jobs: jobs Bring a job back into the foreground: fg %jobnumber Bring a job back into the background: bg %jobnumber (method 2 - my favorite) ALREADY RUNNING PROCESS INTO NOHUP Pro:   Puts runn