Posts

Showing posts from February, 2011

grep multiple strings

bash-3.2$ grep 'pujapr\|jayag\|mohanbn\|mshakti' src/gem/raw/passwd pujapr:$1$vP4gxDwy$hdNlWdCYkvprTXiv6UJUi/:51692:100:Puja Priya:/home/pujapr:/bin/bash jayag:$1$VcnkwPKx$noVX0HZBiUT1HPv7./gup.:56408:100:Jayaprada Gunturi:/home/jayag:/bin/bash mshakti:$1$IJL3IVaE$Cbeeef8v61BB5QzYfXkIN/:58885:100:Sakthi Murugan Subramani:/home/mshakti:/bin/bash mohanbn:$1$5qWwhwXu$5Ptf5w3IBW35fuXAbk4H60:25807:100:Mohan Babu N:/home/mohanbn:/bin/bash

mount clntudp_create: RPC: Program not registered

[root@lobbynet-38 ~]# showmount -e 172.16.188.10 mount clntudp_create: RPC: Program not registered just restart the nfs service again [root@lobbynet-38 ~]# /etc/init.d/nfs restart Shutting down NFS mountd: [FAILED] Shutting down NFS daemon: [FAILED] Shutting down NFS quotas: [FAILED] Shutting down NFS services: [ OK ] Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS daemon: [ OK ] Starting NFS mountd: [ OK ]

Script: Count how many positional paramers Given

#!/bin/bash echo $# ---> This will calculate the number of arugents given at command prompt seq $1 $2 --> $1 will be first argument & $2 will be second argument [root@noisecover-dr Scripts]# ./pospar.sh 2 7 9 10 --> I have given 4 arguments 4 --> total number of arguments 2 3 4 5 6 7

declare arrays1

See all the arrays at same time [root@test1 ~]# echo "${PROD[*]} " items motels teen [root@test1 ~]# printf "%s\n" "${PROD[*]} " items motels teen

declare arrays

[root@test1 ~]# declare -a PROD[0]="items" PROD[1]="motels" PROD[2]="teen" [root@test1 ~]# echo "${PROD[1]} " motels [root@test1 ~]# echo "${PROD[2]} " teen [root@test1 ~]# echo "${PROD[1]} " motels [root@test1 ~]# echo "${PROD[0]} " items [root@test1 ~]# echo $PROD --> by default showing array[0] items

declare readonly variable

declare -r name=davinder echo $name davinder name=davi -bash: declare: name: readonly variable now i am unable to revert it back....

declare examples & clarifications

[root@test1 ~]# declare -i number=15 --declare the integer value 15 ...i means integer [root@test1 ~]# echo $number 15 [root@test1 ~]# printf "%d\n" "$number" 15 [root@test1 ~]# declare -i number="davinder" [root@test1 ~]# echo $number ---> "davinder" is not the integer 0 [root@test1 ~]# printf "%d\n" "$number" 0 [root@test1 ~]# printf "%s\n" "$number" 0 [root@test1 ~]# declare number="davinder" [root@test1 ~]# printf "%s\n" "$number" 0 [root@test1 ~]# echo $number 0 [root@test1 ~]# declare -p number --> show the number variable status declare -i number="0" [root@test1 ~]# declare +i number -->+i reverse the integer [root@test1 ~]# echo $number 0 [root@test1 ~]# echo $number 0 [root@test1 ~]# declare -p number declare -- number="0" [root@test1 ~]# printf "%s\n" "$number" 0 [root@test1 ~]# declare -i number="davinder"

Printf example with %q

[root@test1 scripts]# printf "%q %q\n" "Alpha System corp" "MG Road, Bangalore" >company.txt [root@test1 scripts]# read company location < company.txt [root@test1 scripts]# printf company company[root@test1 scripts]# printf $company Alpha[root@test1 scripts]# printf %q $company AlphaSystemcorp[root@test1 scripts]# printf %q "$company" Alpha\ System\ corp[root@test1 scripts]# printf %q\n "$company" Alpha\ System\ corpn[root@test1 scripts]# printf "%q\n" "$company" Alpha\ System\ corp [root@test1 scripts]# cat company.txt Alpha\ System\ corp MG\ Road\,\ Bangalore --> "\" is because of %q if u gave %s it will read only first coming space. [root@test1 scripts]# printf "%q\n" "$location" MG\ Road\,\ Bangalore [root@test1 scripts]# printf "%s\n" "$location" MG Road, Bangalore [root@test1 scripts]# printf "%s\n" "$company" Alpha System corp

printf formatting code

printf Formatting Codes n %b—Expands backslash sequences n %c—Displays a single character n %d—Displays a signed number n %e—Displays a floating-point number, exponential (also called scientific) notation n %f—Displays a floating-point number n %g—Uses %f or %e depending on the value n %i—Same as %d n %o—Displays an n %q—Quotes the n %s—Displays an n %u—Displays an n %x—Displays an n %X—Displays an n %%—Displays a percent sign octal number string so it can be read properly by a shell script unquoted string unsigned number unsigned hexadecimal number, using lowercase letters unsigned hexadecimal number, using uppercase letters printf Backslash Codes n \b—Backspace n \f—Form feed (that is, eject a page on a printer) Reference Section 47 48 Chapter 3 Files, Users, and Shell Customization n \n—Start a new line n \r—Carriage return n \t—Tab n \v—Vertical tab n \’—Single quote character (for compatibility with C) n \\—Backslash n \0n—n is an octal number representing an 8-bit ASCII character

check the running process

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

Quick tricks

Here i am sharing a few tricks 1. {} used to run commands in current shell 2. () use single quotes to execute commands in subshell ( cd /var/run/mysqld/ && rm -rf mysqld.pid ) && /etc/init.d/mysqld & It will change dir to /var/lib/mysql if its successful it will remove mysql pid file and now if exit status of that whole is 0 it will start mysql 3. {} use curly brackets to enclose a variable to avoid any errors. 4 ulimit -a list all the limit restrictions in current shell We can always change these limits both hard and soft in /etc/security/limit.conf file 5. How to change a particular thing in multiple files in multiple directories find /dirname -iname "file name" -exec sed 's/search/ /replace/g' {} \;

Screen cool way to troubleshoot with peers

Here i am going to explain a little bit about screen utility. And i am sure , you will definitely like to explore other options of it. Screen is basically a way to share your command prompt, i.e once you are in a screen session you will all able to see what other is doing on his console as well as others can see what you are typing or doing on your console in real time. #screen -S india here india is a symboic name to the screen session you can give yours own. #screen -x india to connect with same screen session Note:- user name with which you are logged in should be same of all who want to connect with screen session. #screen -t indian you can given your own title to your screen session. #screen -d india to detach from screen session without closing screen session There are so many features which you can explore using screen --help or man screen #screen -r india to reconnect to same session