###################################### Unix notes which works!! 12/06/2007 Chanka Perera - chanka [at] gmail [dot] com ###################################### - find larger files find / -size +2000 -exec ls -s {} \; | sort -nr | more - list and delte core files find / -type f -name core -exec ls -l {} \; find / -type f -name core -exec rm {} \; - working on ksh erase what you have typed and set vi as editor ksh - erase - stty erase ^? set editor - set -o vi - Global search and replace on vi :1,$ s/old/new/g - check full listning of processesn use bsd ps /usr/ucb/ps -auxww PID - check arguments of java process - some tools to check tcp/ip works nmap / sinfp / hping3 / traceroute / dig - good free tool to run multiple OS VirtualBox-1.6.0-Win_x86.msi - Apache2 which come with Solaris 10 sucks use coolstack and install CSKamp_sparc.pkg.bz2 make sure you use index.php # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # DirectoryIndex index.html index.php - extend filesystemn LVM on AIX 5.1.3 but you'll not able to decrease #chfs -a size=3G /soft - phpinfo script to check php working PHP Test - befor install any core sun patch back up your package DB if currupts re-install your system ;) backup your /var/sadm - Bourne Shell built-ins: which not make a new process id when exe() which is very helpfull when you have to troubleshoot a system which is overloaded if you can't make a new process id due to all the processes are full you can pass an arguments using echo 32 > /proc/ file and then use your shell to work on .. cool ah!! break, cd, continue, eval, exec, exit, export, getopts, hash, pwd, readonly, return, set, shift, test, [, times, trap, umask and unset. · - Bash built-in commands: alias, bind, builtin, command, declare, echo, enable, help, let, local, logout, printf, read, shopt, type, typeset, ulimit and unalias. Special built-in commands: - check the files in Sun Package # pkgchk -v SUNWdhcm /usr /usr/sadm /usr/sadm/admin /usr/sadm/admin/bin /usr/sadm/admin/bin/dhcpmgr /usr/sadm/admin/dhcpmgr /usr/sadm/admin/dhcpmgr/SUNWfiles.jar /usr/sadm/admin/dhcpmgr/SUNWnisplus.jar - when adding solaris package to host with Zone make sure you add with '-G' option else package will install in to all the zones you have on the host - find a dir which contains very large number of files find / -type d -size +5 -print - lsof is a cool tool which you may have to check out - small perl code to rename pipeline files in endeca $prefix = $ARGV[0]; $new_prefix = "\@\@PROJECT_NAME\@\@"; opendir(DIR, ".") || die "can't opendir $dir: $!"; @files = readdir(DIR); closedir DIR; foreach $file (@files) { if ($file !~ /^\./ && $file =~ /^$prefix/) { $new_file_name = $file; $new_file_name =~ s/^$prefix/$new_prefix/; $cmd = "mv $file $new_file_name"; print "renaming $file to $new_file_name" . "\n"; `$cmd`; } } - pargs to check the arguments used in a java process # pargs 11165 11165: /opt/software/OpenDeploy/OpenDeployNG/jre/bin/java -Xss2m -Xms32m -Xmx256m -cla argv[0]: /opt/software/OpenDeploy/OpenDeployNG/jre/bin/java argv[1]: -Xss2m argv[2]: -Xms32m argv[3]: -Xmx256m argv[4]: -classpath argv[5]: /opt/softare/OpenDeploy/OpenDeployNG/lib/odcomboint.jar:/opt/software/OpenDeploy/OpenDeployNG/lib/ddcombo.jar:/opt/software/OpenDeploy/OpenDeployNG/lib/odapi_svr100.jar:/opt/software/OpenDeploy/OpenDeployNG/lib/odapi_cl100.jar:/opt/software/OpenDeploy/OpenDeployNG/lib/odng.jar:/opt/software/OpenDeploy/OpenDeployNG/lib/version.jar:/opt/software/OpenDeploy/OpenDeployNG/lib/hsqldb.jar:/opt/software/OpenDeploy/OpenDeployNG/jre/lib/sparc:/opt/software/OpenDeploy/OpenDeployNG/lib/odcombo.jar:/opt/software/OpenDeploy/OpenDeployNG/websvc/lib/wasp_combo.jar argv[6]: -Djava.library.path=/opt/software/OpenDeploy/OpenDeployNG/lib:/opt/software/OpenDeploy/OpenDeployNG/jre/lib/sparc:/usr/lib argv[7]: -Djava.rmi.server.codebase=file:///opt/software/OpenDeploy/OpenDeployNG/lib/odapi_cl100.jar file:///opt/software/OpenDeploy/OpenDeployNG/openjms/lib/openjms-client-0.7.6.1.jar argv[8]: -Djava.rmi.server.useCodebaseOnly=true argv[9]: -Djava.security.manager argv[10]: -Djava.security.policy=/opt/software/OpenDeploy/OpenDeployNG/lib/deployapi.policy argv[11]: -Dod.home=/opt/software/OpenDeploy/OpenDeployNG argv[12]: -Dod.inst.name=initial argv[13]: com.interwoven.deploy.cdmain.IWCDBoot argv[14]: /opt/software/OpenDeploy/OpenDeployNG/etc/deploy.cfg - check process tree # ptree 9445 9278 /opt/software/zeus/zxtm/bin/zeus.zxtm 9445 /usr/bin/java -server -classpath /opt/software/zeus/zxtm/lib/zeus.java.jar:/opt - check solaris zone utilization prstat -Z - process memory allocation use 'pmap' and calculate read allocation on virtulized env - steps to do RBAC Solaris 1) create a user - useradd -d /export/home/rbactest -m rbactest 2) create a role - roleadd -d /export/home/rbacrole -m rbacrole 3) chek role was added, grep rbacrole /etc/user_attr >> rbacrole::::type=role;profiles=All 4) assign password for both user and role to unlock accounts 5) assign role to user usermod -R rbacrole rbactest 6) check role was added to user grep rbactest /etc/user_attr >> rbactest::::type=normal;roles=rbacrole 7) create profile edit /etc/security/prof_attr OD:::start and stop OD 8) create execute attribute /etc/security/exec_attr add following at the end >> OD:suser:cmd:::/cms-share/rbactest.sh:uid=0 9) assign profile to role rolemod -P "OD,All" rbacrole 10) check profile has added to role grep rbacrole /etc/user_attr >> rbacrole::::profiles=OD,All;type=role 11) to test login as rbactest ; su to rbacrole and run the command specified at /etc/security?exec_attr which would run the script in pfksh shell on RBAC mode - how to colect data to do perf test Solaris date > TIMESTAMP vmstat 3 600 > ./vmstat-3 & mpstat 3 600 > ./mpstat-3 & iostat -xcnz 7 86 > ./iostat-xcnz-7 & netstat -i 3 600 > ./netstat-3 & prstat -c -n 50 7 86 > ./prstat-7 & prstat -c -m -n 50 7 86 > ./prstat-7-m & prstat -c -mL -n 50 7 86 > ./prstat-7-mL & - playing with sun metadisks disks - create one mta device with differnt disks d40 -r c2t8d0s0 c2t9d0s0 c2t10d0s0 c2t11d0s0 -k -i 32b - create one meta device strip # metainit d101 1 1 c2t12d0s0 d101: Concat/Stripe is setup # metainit d102 1 1 c2t13d0s0 d102: Concat/Stripe is setup - Mirror setup # metainit d100 -m d101 d102 # metastat d40 d40: RAID State: Initializing Initialization in progress: 16.2% done Interlace: 32 blocks Size: 429396672 blocks (204 GB) Original device: Size: 429405792 blocks (204 GB) Device Start Block Dbase State Reloc Hot Spare c2t8d0s0 10506 No Initializing Yes c2t9d0s0 10506 No Initializing Yes c2t10d0s0 10506 No Initializing Yes c2t11d0s0 10506 No Initializing Yes Device Relocation Information: Device Reloc Device ID c2t8d0 Yes id1,sd@SSEAGATE_ST373454LSUN72G_1472NRE7____________3KP2NRE7 c2t9d0 Yes id1,sd@SSEAGATE_ST373454LSUN72G_1472NQ5J____________3KP2NQ5J c2t10d0 Yes id1,sd@SSEAGATE_ST373454LSUN72G_1472NRKL____________3KP2NRKL c2t11d0 Yes id1,sd@SSEAGATE_ST373454LSUN72G_1272LT2G____________3KP2LT2G - format new meta disks # newfs /dev/md/rdsk/d105 newfs: construct a new file system /dev/md/rdsk/d105: (y/n)? y Warning: 4096 sector(s) in last cylinder unallocated /dev/md/rdsk/d105: 71303168 sectors in 11606 cylinders of 48 tracks, 128 sectors 34816.0MB in 726 cyl groups (16 c/g, 48.00MB/g, 5824 i/g) super-block backups (for fsck -F ufs -o b=#) at: 32, 98464, 196896, 295328, 393760, 492192, 590624, 689056, 787488, 885920, Initializing cylinder groups: .............. super-block backups for last 10 cylinder groups at: 70387232, 70485664, 70584096, 70682528, 70780960, 70879392, 70977824, 71076256, 71174688, 71273120 - extend filesystem using grwoFS #metattach d30 4g # growfs -M /zone_new /dev/md/rdsk/d30 Warning: 2048 sector(s) in last cylinder unallocated /dev/md/rdsk/d30: 60817408 sectors in 9899 cylinders of 48 tracks, 128 sectors 29696.0MB in 619 cyl groups (16 c/g, 48.00MB/g, 5824 i/g) super-block backups (for fsck -F ufs -o b=#) at: 32, 98464, 196896, 295328, 393760, 492192, 590624, 689056, 787488, 885920, Initializing cylinder groups: ............ super-block backups for last 10 cylinder groups at: 59871392, 59969824, 60068256, 60166688, 60265120, 60363552, 60461984, 60560416, 60658848, 60757280 - with NFS version 3 you can keep you application process alive for 3min which, we have tested !! - Solaris cpushare global # zonecfg -z MDEXzone zonecfg:zonename> add rctl zonecfg:zonemame:rctl> set name=zone.cpu-shares zonecfg:zonename:rctl> add value (priv=privileged, limit=100, action=none) zonecfg:zonename:rctl> end zonecfg:zonename> exit - How to remove cpu-shares allocated or edit the values - zonecfg -z zone03 zonecfg:zone03> zonecfg:zone03> select rctl name=zone.cpu-shares zonecfg:zone03:rctl> remove value (priv=privileged,limit=4,action=none) zonecfg:zone03:rctl> add value (priv=privileged,limit=3,action=none) zonecfg:zone03:rctl> end zonecfg:zone03> exit zonecfg:zone03> remove rctl name=zone.cpu-shares commit end - To set the CPU share on running process global# prctl -r zone.cpu-shares -v 50 -i process $$ - To set it permanent add to rc scripts and set after reboot. global # /etc/init.d global # vi zoneshares #!/sbin/sh /usr/bin/prctl -r zone.cpu-shares -v 50 -i process $$ exit 0 - The amount of cpu consumed inside zone is controlled by project.cpu-share resource control. # prctl -n project.cpu-shares -r -v 20 -i project endeca_prod # prctl -n project.cpu-shares -r -v 10 -i project endeca_virtual - Procedure to create SMF based service - Create a Start/Stop method script. Create a manifest xml file and place under /var/svc/manifest/application// #svccfg validate /var/svc/manifest/application//appsname.xml #svccfg import /var/svc/manifest/application//appsname.xml #svcs appsname #svcadm enable svc:/application//appsname (this command will makes changes permanently. For temporary change #svcadm enable -t svc:/application//appsname) #svcs -x appsname - quick start with mysql after you install mysql on solaris run following commands #export PATH=/opt/coolstack/mysql_32bit/bin:$PATH # /opt/coolstack/mysql/bin/mysql_install_db # groupadd mysql # useradd -c "MySQL Server" -g mysql mysql #chown -R mysql:mysql /opt/coolstack/mysql_32bit #cp /opt/coolstack/mysql_32bit/share/mysql/my-large.cnf /etc/my.cnf #su – mysql $ /opt/coolstack/mysql_32bit/bin/mysqld_safe & $ /opt/coolstack/mysql_32bit/bin/mysqladmin -u root password SOMEPASSWORD $ /opt/coolstack/mysql/bin/mysqladmin -u root -h ‘yourhostname’ password SOMEPASSWORD bash-3.00$ mysqladmin --user=root create cacti mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)' bash-3.00$ mysqladmin --user=root create cacti -p Enter password: bash-3.00$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 26 Server version: 5.0.33-standard-log Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | cacti | | mysql | | test | +--------------------+ 4 rows in set (0.01 sec) # to get just your ip curl http://checkip.dyndns.com/ 2> /dev/null |tr -d '[eaieCurren IP CeckieeaCurren IP Aress: ]'