Posts

Showing posts from 2011

Webmin configuration for LDAP

We cannot add or delete users by default so we have to do below changes in LDAP module in GUI mode only. Configuring the module The most complex part of using this module is configuring it to talk to your LDAP server. By default, it will attempt to auto-detect the settings by looking at the LDAP client settings on your system, documented on the LDAPClient page. However, if this fails (perhaps because the LDAP server is not one of its own clients), you will need to configure the module manually as follows : On the module's main page, click on the Module Config link. In the LDAP server host field, enter the hostname of your LDAP server. If it is running on the same machine, enter localhost. If the LDAP server is using encryption, change the LDAP server uses TLS? option to Yes. In the Bind to LDAP server as field, enter the full DN of the administrative user for your LDAP server. This might be something like cn=Manager,dc=my-domain,dc=com. In the Credentials for bind name above field,

ldap client create home directory automatically at first login time

I have added this session required pam_mkhomedir.so skel=/etc/skel/ umask=0077 in /etc/pam.d/system-auth file

change DATE on system by CLI mode

date -s "2 Nov 20011 20:30:00" or use --set in place of -s

trcshcsh shell for change password

[root@LDAP-Server openldap]# trcshcsh [root@LDAP-Server openldap]# foreach user (`cat users.list`) foreach? echo $user foreach? end [pankaj@LDAP-Server openldap]# foreach user ( `cat users.list` ) foreach? echo "============== Changing password for $user ===================" foreach? ldappasswd -s welcome -x -W -D "cn=Manager,dc=IBMISL" "uid=,ou=People,dc=IBMISL"=$user2ibm -x -W -D "cn=Manager,dc=IBMISL" "uid=$user,ou=People,dc=IBMISL" foreach? end

wget with username & password

wget https://axa.com/dl.php?file=/redhat/release_cds/RHEL-6. 1-RC-3/Server/ppc64/iso/RHEL6.1-20110510.1-Server-ppc64-DVD1.iso --user=davinder --password=P@ssw0rd123

Set default browser

http://support.mozilla.com/en-US/kb/How%20to%20make%20Firefox%20the%20default%20browser

Unable to create filesystem "getting error mkfs.ext3: inode_size (128) * inodes_count (0) too big for "

mkfs.ext3: inode_size (128) * inodes_count (0) too big for After you ran sudo fdisk /dev/sdb1 , and deleted the existing partitions by hitting the d key and creating a new one by hitting n, did you choose 'p' (primary) or 'e' (extended). If you chose 'e', re-run the command and choose 'p' instead. That should solve your problem.

Scan the LUNS

for HOST in `ls /sys/class/scsi_host/`; do echo "- - -" > /sys/class/scsi_host/$HOST/scan; done;

sdiff command rather than diff command

sdiff will give you more clear picture than diff command.

How to Rebuild RPM Database

Follow these steps Take the backup of /var/lib/rpm Directory 1) tar zcvf /var/lib/rpm.backup.tar.gz /var/lib/rpm Verify Integrity 2) cd /var/lib/rpm 3) rm –f __db* 4) /usr/lib/rpm/rpmdb_verify Packages Dump & Load Package 5) mv Packages packages.backup 6) /usr/lib/rpm/rpmdb_dump Packages.backup | /usr/lib/rpm/rpmdb_load Packages 7) /usr/lib/rpm/rpmdb_verify Packages 8) rpm –qa Final Step to rebuild database 9) rpm –vv –rebuilddb

How to Rebuild RPM Database

Follow these steps Take the backup of /var/lib/rpm Directory 1) tar zcvf /var/lib/rpm.backup.tar.gz /var/lib/rpm Verify Integrity 2) cd /var/lib/rpm 3) rm –f __db* 4) /usr/lib/rpm/rpmdb_verify Packages Dump & Load Package 5) mv Packages packages.backup 6) /usr/lib/rpm/rpmdb_dump Packages.backup | /usr/lib/rpm/rpmdb_load Packages 7) /usr/lib/rpm/rpmdb_verify Packages 8) rpm –qa Final Step to rebuild database 9) rpm –vv –rebuilddb

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

Script--Color & hide charaters

$ ls -A .bash_history .bash_logout .bash_profile .bashrc archive check-orders.sh orders.txt The filenames can be printed in color to show the kind of file they are.The colors are defined in a file /etc/DIR_COLORS.You can customize the colors using a .dir_colors file in your own directory.The format of the file is described in the /etc/DIR_COLORS file. To display the files without color and with symbols instead, use the --color and --classify (or -F) switches. (On most Linux distributions, this feature is turned on using aliases.) $ ls --color=never --classify archive/ check-orders.sh* orders.txt The –classify symbols are directories (/), programs (*), symbolic links (@), pipes (|), and Unix domain socket files (=).These symbols are not a part of the name:They are hints as to the type of file. In this example, archive is a directory and check-orders.sh is a program. Another very important switch is --hide-control-chars (or -q). Linux filenames can contain any character, even control cha

Save Efforts while extracting

We can extract our tar archived file to our required destination with using copy and all in single shot. cd /to/where/archived/file.gz tar -xzf filename.gz -C /destnation/dir/ ; cd /destination/dir/ it will extract the file in the path given like /destination/dir/ and cd will change your dir to that dir. e.g cd Downloads tar -xzf zabbix-2.6.gz -C /opt/ ; cd /opt/zabbix-2.6/ pwd /opt/zabbix-2.6

Command chaining Or multiple commands at same time

#pwd;echo "Hello World" [davsingh@noisecover-dr Scripts]$ ls -l && pwd ---> If first run then second will execute otherwise it will not work total 16 -rw-r--r-- 1 davsingh users 0 Jan 21 12:52 a -rw-r--r-- 1 davsingh users 0 Jan 20 14:18 ABC.txt.txt -rw-r--r-- 1 davsingh users 0 Jan 21 12:52 b -rw-r--r-- 1 davsingh users 0 Jan 21 12:52 c -rw-r--r-- 1 davsingh users 0 Jan 20 11:29 junk1.data.txt.txt -r--r--r-- 1 davsingh users 5956 Jan 20 11:29 passwd.txt.txt drwxr-xr-x 2 davsingh users 4096 Jan 21 12:58 test -rwxr-xr-x 1 davsingh users 166 Jan 20 14:21 upper-lower.sh.txt /home/davsingh/Scripts [davsingh@noisecover-dr Scripts]$ cat abc && pwd ----> first fails so second command not work cat: abc: No such file or directory [davsingh@noisecover-dr Scripts]$ cat abc || pwd --> If first fails then second runs cat: abc: No such file or directory /home/davsingh/Scripts

Exit Status

#cd /tmp #echo $? 0 --> it means successful we have 0-255 exit codes where "0" is only for successful. [root@noisecover-dr ~]# pzw -bash: pzw: command not found [root@noisecover-dr ~]# echo $? 127 --> it is reserved for command not found. 126--> permission issue

unalias

#alias df='df -TH' [root@noisecover-dr ~]# df Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/sys-root ext3 241G 31G 198G 14% / /dev/sda1 ext3 104M 19M 80M 19% /boot tmpfs tmpfs 2.1G 0 2.1G 0% /dev/shm /home/davsingh/Desktop/rhel-server-5.5-i386-dvd.iso iso9660 3.2G 3.2G 0 100% /rhel5.5/ISO #unalias df [root@noisecover-dr ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/sys-root 234410632 29446100 192864948 14% / /dev/sda1 101086 18176 77691 19% /boot tmpfs 2022912 0 2022912 0% /dev/shm /home/davsingh/Desktop/rhel-server-5.5-i386-dvd.iso 3038672 3038672 0 100% /rhel5.5/ISO

Create alias permanently

# vi /etc/bashrc alias df='df -TH' --> paste at last for user specific setting add in /home/username/.bashrc

How to create/delete multiple files

[davsingh@noisecover-dr test]$ touch test{1,2,3} {a,b,c} [davsingh@noisecover-dr test]$ ls a b c test1 test2 test3 [davsingh@noisecover-dr test]$ rm -rf test* [davsingh@noisecover-dr test]$ rm -rf {a,b,c} [davsingh@noisecover-dr test]$ touch test{1,2,3}{a,b,c} [davsingh@noisecover-dr test]$ ls test1a test1b test1c test2a test2b test2c test3a test3b test3c

Remove the variable value in memory --unset command

#answer=ind [davsingh@noisecover-dr Scripts]$ set | grep -e "answer" -e "lastname" answer=ind lastname=singh #use the unset command [davsingh@noisecover-dr Scripts]$ unset answer [davsingh@noisecover-dr Scripts]$ set | grep -e "answer" -e "lastname" lastname=singh [davsingh@noisecover-dr Scripts]$ set | grep answer [davsingh@noisecover-dr Scripts]$

GREP command to search multiple strings

[davsingh@noisecover-dr Scripts]$ set | grep -e "answer" -e "lastname" answer=ind lastname=singh For not equal to [davsingh@noisecover-dr Scripts]$ seq 10 | grep -v -e "1" -e "5" 2 3 4 6 7 8 9

Scripts examples with read command

[davsingh@noisecover-dr Scripts]$ read test davinder singh [davsingh@noisecover-dr Scripts]$ echo $test davinder singh [davsingh@noisecover-dr Scripts]$ read firstname lastname davinder singh [davsingh@noisecover-dr Scripts]$ echo $firstname davinder [davsingh@noisecover-dr Scripts]$ echo $lastname singh [davsingh@noisecover-dr Scripts]$ echo $firstname $lastname davinder singh

Script to convert upper to lower characters

#script to change charaters from upper to lower #!/bin/bash echo $0; for i in `ls -A` do newname= echo $i|tr A-Z a-z echo $i $newname mv $i $i.txt done ~

why #!/bin/bash is required

It is called the Shebang rotation #which bash /bin/bash #sh script_name.sh ---> here we no need to mention !/bin/bash line in script but we want to give as below then we reuired the line so that it can understand it will be bash #./script_name more details check the below URL http://en.wikipedia.org/wiki/Shebang_%28Unix%29

Hello World

#!/bin/bash echo "Hello World"

Example sort, cut & uniq command

cut -f1 -d: passwd |sort|uniq it will cut the first field in passwd file & sort with according to alphabets & only show the unique names. cut -f3 -d: passwd |sort -n|uniq it will cut the 3rd field in passwd file & sort according to the numeric numbers & show the unique numbers only.

how to find the current shell

echo $0 for example [davsingh@noisecover-dr Scripts]$ ksh $ echo $0 ksh $ exit [davsingh@noisecover-dr Scripts]$ echo $0 -bash

How to mount the ISO image

mount -o loop /home/davsingh/Desktop/rhel-server-5.5-i386-dvd.iso /rhel5.5/ISO/

Split a file in to multiple files

If we have a file with 1-300 lines are there & need to create separate files for 20 lines... means need to create 15 files to separate the 20 lines in each file. mkdir test cd test split -l 20 ../server.txt bash-3.2$ ls -l total 128 -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xaa -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xab -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xac -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xad -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xae -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xaf -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xag -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xah -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xai -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xaj -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xak -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xal -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xam -rw-r--r-- 1 davsingh staff 500 Jan 10 15:21 xan -rw-r--r-- 1 davsingh staff 500