Practical UNIX management script

Source: Internet
Author: User
Tags nameserver pkill

Practical UNIX management script 1. Force the login user to be kicked off in Linux 1) view the user logged on to the Machine [root @ sunsyk ~] # W 16:29:02 up 2 days, 5 users, load average: 0.03, 0.05, 0.01 user tty from login @ idle jcpu pcpu what root pts/1: 0.0 Tue15 2 days 0.04 s-bash root pts/2: 0.0 Tue15 46: 42 m 0.05 s 0.05 s bash root pts/3: 0.0 Tue15 2 days 0.02 s 0.02 s bash root pts/4 172.20.52.114 17 58: 48 0.16 s 0.03 s sqlplus root pts/5 172.20.52.114 31 0.00 s 0.03 s 0.00 s w 2) kill pts/1 (only the root permission can be used to kill the user) [root @ sunsyk ~] # Pkill-kill-t pts/1 [root @ sunsyk ~] # Pkill-kill-t pts/2 [root @ sunsyk ~] # Pkill-kill-t pts/3 check whether the kill is kicked off [root @ sunsyk ~] # W 16:34:16 up 2 days, 2 users, load average: 0.00, 0.05, 0.02 user tty from login @ idle jcpu pcpu what root pts/4 172.20.52.114 1: 04 m 0.16 s 0.03 s sqlplus root pts/5 172.20.52.114 31 0.00 s 0.03 s 0.00 s w root can kill other users including themselves 2. how to view the system's Red Hat version number in Linux 1. name-a 2.cat/etc/version 3.cat/etc/issue 4.cat/etc/redhat-release3.Linux to check whether the system is 32-bit or 64-bit 1. getconf LONG_BIT 2. file/bin/ls4.linux sets IP, gateway, DNS, and MAC address 1, IP address, subnet mask: edit/etc/sysconfig/network-script/ifcfg-eth0 DEVICE = eth0 BOOTPROTO = static --- static or dynamic BROADCAST = 192.168.1.255 IPADDR = 192.168.1.35 --- IP address NETMASK = 255.255.255.0 --- subnet mask NETWORK = 192.168.1.0 --- network id onboot = yes 2. Gateway: edit/etc/sysconfig/network NETWORKING = yes HOSTNAME = vmlinux --- host name GATEWAY = 192.168.1.2 --- GATEWAY 3. DNS: edit/etc/resolv. conf nameserver 61.147.37.1 nameserver 61.177.7.1 4. MAC Address edit Nic configuration file/etc/sysconfig/network-script/ifcfg-eth0 Add: HWADDR = 00: AA: BB: CC: DD: EE or: 1) you must first disable the NIC device. Otherwise, the system is reported to be busy and cannot be changed. Command:/sbin/ifconfig eth0 down 2) modify the MAC address. Command:/sbin/ifconfig eth0 hw ether 00 aa bb cc dd ee 3) Enable Nic again command: /sbin/ifconfig eth0 up 4.2 AIX view network ifconfig et0 ifconfig-a netstat 5. linux user name and password change 1. usermod-l new (your new user name should be written) old (write the old user name) then, set the password to replace mysql with pserver usermod-l pserver mysql, and then input passwd for pserver 123456 (your own password). 2. Change the password if you are an ordinary user, change your password. Use passwd to enter your old password and then enter the new password twice. If you are the root user, you can use password username to change the password of username. Simply enter the new password twice without entering the old password. 3. view the user cat/etc/passwd. If the third item is greater than or equal to 500, the user is created. 6. linux modify default language edit/etc/sysconfig/i18n file, the original content is as follows: LANG = "zh_CN.UTF-8" SYSFONT = "latarcyrheb-sun16" SUPPORTED = "zh_CN.UTF-8: zh_CN: zh" modified: LANG = "en_US.UTF-8" SUPPORTED = "en_US.UTF-8: en_US: en" SYSFONT = "latarcyrheb-sun16" restart now! 7. to solve the Chinese version of garbled problem, Chinese display garbled specific solution is: 1, modify the remote linux machine configuration vim/etc/sysconfig/i18n LANG into support for UTF-8 character set such: LANG = "zh_CN.UTF-8" or LANG = "en_US.UTF-8" 2, then change the Secure CRT settings, options-> session options-> appearance-> character encoding-> uft-8 3, exit, then log on again. We found that all utf8 files can be correctly read, and the utf8 file name can also correctly display the full screen SecureCRT. How can we display the menu after SecureCRT? Alt + Enter is the shortcut for converting to full screen or not, or Enter the Alt + V pop-up menu, remove full screen under Red hat/etc/sysconfig/i18n, what does each line mean? LANG = "zh_CN.GB18030" SUPPORTED = "zh_CN.GB18030: zh_CN: zh: en_US.UTF-8: en_US: en "SYSFONT =" latarcyrheb-sun16 "/etc/sysconfig/i18n here stores the system's regional language settings, i18n is the abbreviation of internationalization. the first line of the 18 letters between I and n indicates the language environment variable settings of your current system. The second line of zh_CN.GB18030 indicates that the system has preset language support, language not in the project cannot normally display the third line definition console terminal font, the font displayed when you log on to the text is this latarcyrheb-sun168. add and modify the username and group Root in the Root directory: Execute groupadd dba to add the group named useradd-dba oradb to add the user oradb passwd oradb to change Change the user's oradb password and enter the password twice. usermod-G dba oradb mkdir/u01 # mkdir-p/u01/nihao1/nihao2/nihao3 recursively creates the chown-R directory layer by layer. oradb: dba/u01 Change directory/u01 owner and group #-R recursively modify sub-directory chmod-R 775/u01 recursion (-R) CHANGE/u01 read/write attribute 9. in Linux, modify the usermod-g group loginname of the user group and forcibly set The usermod-G groups loginname of the user group to group (s) usermod-a-G groups loginname adds a user to a group (s) Storage san lun # lsvg rootvgdatavgbackupvg47datav1_147datav%247datavg03 # lsvg -P 47datav1_147datavg01: PV_NAME pv state total PPs FREE DISTRIBUTIONhdisk43 active 3999 2 00 .. 00 .. 00 .. 00 .. 02 # lsvg-l 47datav1_147datavg01: lv name type LPs PPs PVs lv state mount POINTu04 jfs2 3996 3996 1 open/syncd/u04loglv02 jfs2log 1 1 1 open/syncd N/A 10. add hard disk AIX View list: lsdev-Cc disk AIX view output: prtconf fdisk/dev/sdb (hda/hdb) mkfs. ext3-B 4096/dev/hdb1 mount/dev/sdb1/AAAA Modify/etc/fsta File B to automatically mount/etc/fstab/dev/sdb1/www ext3 defaults 0 0 fdisk-l/dev/sdb (hda/hdb) view disk information. mount and detach a remote disk. root @ dev01 # mount test01:/u02/backup/rman/finrman root @ dev01 # umount/finrman root @ dev01 #11. linux mounting iso file command mount-t iso9660-o loop/media/nihao/dvd. iso/mnt/iso 12. linux installation package command rpm-qa libstdc ++-* check whether libstdc ++ Software Package rpm-ivh libstdc ++-* -- force -- nodeps installation name contains libstdc ++ software package -- force installation, -- no Dep check dependency 13. firewall related 1) enable upon restart: chkconfig iptables on Disabled: chkconfig iptables off 2) Enable upon restart: Disable service iptables start disabled: service iptables stop 14. SElinux 1) SELinux-related tools/usr/bin/setenforce modify the real-time running mode of SELinux setenforce 1 Set SELinux to enforcing mode setenforce 0 set SELinux to permissive mode if SELinux needs to be permanently disabled in/etc/ set selinux to 0 in sysconfig/selinux, or in/etc/grub. add this parameter/usr/bin/setstatus-v in conf to check the system status. For output, see SELinux status: enabled SELinuxfs mount:/selinux Current mode: enforcing Policy version: 18 2) Disable selinux without restarting. Solution: run the following command: setenforce 0 in the new version of Red Hat and Fedora, modify the file/etc/sysconfig/selinux: # This file controls the state of SELinux on the system. # SELINUX = can take one of these three values: # enforcing-SELinux security policy is enforced. # permissive-SELinux prints warnings instead of e Nforcing. # disabled-SELinux is fully disabled. SELINUX = enforcing # SELINUXTYPE = type of policy in use. possible values are: # targeted-Only targeted network daemons are protected. # strict-Full SELinux protection. SELINUXTYPE = targeted set SELINUX to disable. After the system is started, SElinux will be stopped. For Linux Kernel parameters (Kernel Parameter), you can add the selinux = 0 (STOP) or selinux = 1 (enable) Parameter file/boot/grub/menu after the core parameters. lst title Fedora Core (2.6.18-1.2798.fc6) root (hd0, 0) kernel/vmlinuz-2.6.18-1.2798.fc6 ro root = LABEL =/rhgb quiet selinux = 0 initrd/initrd-2.6.18-1.2798.fc6.img check current SELinux status 3) you need to know if you are using SELinux: [root @ ebs01 ~] # Getenforce Disabled 15. log to delete the current directory find. -mtime + 5-name "o *. out "-exec rm {} \; find. -mtime + 10-name "CUX *. PDF "-exec rm {}\; find. -mtime + 10-name "CUX *. EXCEL "-exec rm {}\; search for 1 in the/u01/admin_log/out directory for more than five days. The file name starts with o and starts. delete 2 at the end of "out". If the time exceeds 10 days, the file name starts with CUX and starts. delete 3 at the end of the PDF. If the time exceeds 10 days, the file name starts with CUX and starts. delete-mtime n; File's data was last modified n * 24 hours ago. -name pattern; Base of file name (the path With the leading directories removed) matches shell pattern. The metacharac-ters ('*','? ', And' [] ') do not match '. 'At the start of the base name. to ignore a directory and the files under it, use-prune; see an example in the description of-path. -exec command; Execute command; true if 0 status is returned. all following arguments to find are taken to be arguments to the command until an argument consisting of ';' is encountered. the string '{}' is replaced by the current file Name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. both of these constructions might need to be escaped (with a '\') or quoted to protect them from expansion by the shell. the command is executed in the starting directory. 4 cd/u01/admin_log/ora/10.1.3/Apache [appprod @ ap01 Apache] $ du-ms. 6398.76. [Ppprod @ ap01 Apache] $ pwd/u01/admin_log/ora/10.1.3/Apache [appprod @ ap01 Apache] $ rm access_log * [appprod @ ap01 Apache] $ rm error_log * [appprod @ ap01 Apache] $5 cd $ APPLCSF/$ APPLLOG find. -mtime + 30-name "l *. mgr "-exec rm {}\; 5.5 6 cd/u01/admin_log/ora/10.1.3/opmn find. -mtime + 10-name "opmn. log * "-exec rm-rf {}\; regularly checks the directory size of/u01/admin_log/ora/10.1.3/opmn. It is very likely that the OA core overflows and needs to be cleared. 7. Output Log File: (Be careful not to confirm whether the log can be deleted.)/u02/EUT/db/tech_st/11.1.0/appsutil/outbound/EUT_bi02 diagnosis log: /backup/yzz01/db/tech_st/11.1.0/admin/CCTEST01_test01/diag/rdbms/cctest01/CCTEST01/incident 16. remote graphical display 1) client (windows XP) xmanager + server (unix or linux) environment variable 1. Open xterm 2 on client 172.16.3.210, Server ip address 172.16.0.22, edit the environment variable DISPLAY: export DISPLAY = 172.16.3.210: 0.0 in term -- here, 172.16.3.210 is the client machine, and the server ip address is 172.16.0.22 3 and the client (172.16.3.210) Install xmanager and start Xmanager-passive. Wait. 4. Running xclock in xterm on the client will support images. 2) install the vncserver package on the linux end 1. view the current system information redhat enter prise linux 6.1 for a software package similar to tiger vnc server [root @ ip-7-0-168-192 ~] # Cat/etc/issue Red Hat Enterprise Linux Server release 6.0 (Santiago) Kernel \ r on an \ m 2. check whether the system has a secure VNC security package [root @ ip-7-0-168-192 ~] # Rpm-qa | grep vnc libvncserver-0.9.7-4.el6.i686 vnc-4.1.2-14.el5_3.1.i386 tiger-vnc-server-4.1.2-14.el5_3.1.i386 # No VNC security package security 3. configure VncServer to edit vi/etc/sysconfig/vncservers: remove the last two rows of zookeeper and change it to VNCSERVERS = "2: root "VNCSERVERARGS [1] ="-geometry 1024x768-depth 16 "NOTE: You can add multiple users to connect to the vnc server using the vnc client, for example: VNCSERVERS = "1: root 2: oracle" the default ports of VNCServer are 6001, and. Here, "1: root 2: oracle" indicates that 5 is enabled for the System user root. Ports 6001, 5901, and 5802, 1 is the desktop number or terminal number, enabling ports 5902, 6002, and for the System user oracle, 2 is the desktop number, and so on. "1024x768" indicates the screen resolution. For the sake of security, do not set root User Logon here. At the first startup, you need to change the logon password, # vncpasswd 4. start VncServer and use the system startup script to start VncServer: #/etc/rc. d/init. d/vncserver start or # service vncserver start and then use netstat to check whether the corresponding port is listened to. Each terminal listens to three ports 5. to stop a service, check the status of service vncserver stop/status 6. run the following command to close the vnc window: vncserver-kill: 1 to start the vnc window service command: vncserver: 1 7. On the client machine, it is generally windows XP. To start vnvviewer, for example: vnc-4_1_2-x86_win32_viewer.exe18, file list ls-l-t is displayed in chronological order, the default is the new row in front, the following command can be used to change the Ascending Order: ls-lrt latest file The latest ls-lnt files (in ascending order) are listed at the beginning (in descending order) du-k * | sort-nr is entered into the local directory by size 19 and sftp, then, the sftp remote user @ IP address copies all files named 12746 * from the/u01/archive directory of 172.16.0.202 to the/u02/archivelogbackup directory of the Local Machine. 1. log on to the local machine. 2. Go to the directory: cd/u02/archivelogbackup sftp oraprod@172.16.0.202 input yes and password sft> lls, ls, LCD, cd, lpwd, pwd are local commands and remote commands, respectively, get sequence 46 * is used to obtain all objects starting with sequence 46 remotely. 20. kill a process that contains a fixed string in a user process. In some cases, kill all processes that meet a certain condition in linux, killall cannot be used to directly kill all running processes contained in a process name (we may only need to kill a certain type of process or the process that runs the specified parameter command ), in this case, we need to use ps, grep, cut, and kill. OK. The following is a reference: ps-ef | grep LOCAL = NO | grep-v grep | cut-c 9-16 | xargs kill-9 running this command will kill all processes containing the keyword "LOCAL = NO, is it convenient? The following is a brief description of this command: The Pipe operator "|" is used to separate two commands. The output of the command on the left of the pipe operator is used as the input of the command on the right of the pipe operator. "Ps-ef" is the command for viewing all processes in linux. The retrieved process serves as the input of the next command "grep LOCAL = NO. The output result of "grep LOCAL = NO" is that all processes that contain the keyword "LOCAL = NO. "Grep-v grep" is a process that removes the keyword "grep" from the listed processes. "Cut-c 9-15" refers to intercepting 9th to 15th characters of the input line, which is exactly the process id pid. The xargs command in "xargs kill-9" is used to take the output result (PID) of the preceding command as the parameter of the "kill-9" command and execute this command. "Kill-9" will forcibly kill the specified process. In other similar cases, you only need to modify the keyword section in "grep LOCAL = NO. Another method, use the awk ps x | grep gas | grep-v grep | awk '{print $1}' | xargs kill-9 21 decompression and compression command gzip-d file.tar.gz tar xvf file.tar [appprod @ ap02 appl] $ pwd/u01/PROD/apps/apps_st/appl tar-cvf cux20121012.tar cux tar-xvf cux20121012.tar gzip-d file.tar.gz gzip-dc convert | tar-xvf-tar- cvf-apps | gzip>/backup/ap01_backup 'date specified when m1_d1_h1_m'.tar.gz 22 is in all files in the current directory, find the command grep RCVTP * containing a string | more 23 FTP start and stop [root @ ITMS sl2] # service vsftpd status vsftpd stopped [root @ ITMS sl2] # service vsftpd restart is vsftpd start vsftpd: [OK] [root @ ITMS sl2] # service vsftpd status 24 enables command execution in the background, and the terminal can disconnect nohup command &

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.