Study Notes(18)

1. Functions can be edited in interactive mode and executed by function name, func1 () { echo function1; }

  If the function name conflicts with the command name, in the interactive execution, the function definition priority is higher than the alias priority, try not to let the function name conflict with the command name, such as prefix: func_

2.declare -f func1 to view created function definitions (declare -f to view all function definitions)

3.unset function name delete function definition

4.cmd1 || (cmd2;exit;) Exit the subshell without exiting the script

   cmd1 || { cmd2; exit; } exit the script

   Exit the function itself, use the return keyword, return the number, the number returned by the return in the function is stored in $?, which can be used as a judgment condition

5. The scope of the variables defined inside the function is the current shell, func1() { name=mage; echo "func1:$name"; } This function can affect the variables defined in the current shell

   If the variable is only valid internally, you can use the local keyword to prevent modifying the variable with the same name in the current shell func1() { local name=mage; echo "func1:$name"; }

   Global variables (export is valid in the current shell and subshell), local variables (name=mage is valid in the current shell), local variables (local name=mage is only valid within the current function)

   When declare is used inside a function, the local feature is only valid in the function, not in the current shell, func1 () { declare -i num=100; echo "func1:$num"; } 

   If declare -ig num=100 is used globally, the scope is the current shell (declare -g option is only available in centos7)

   The function is defined first and then used. Pay attention to the order. The function is called first, and the declaration will report an error after the declaration.

   help return View help for the return keyword

   The reference function can use the source file name (or. file name) (eg: /etc/init.d/functions) to call the function in the file to the current shell

   export -f func1 makes func1 available globally, including in subshells

   export -f shows all global functions

   help test can view the available judgment parameters in shell scripts, such as -f, -e, -s and other parameter descriptions

6. . functions calls the function files that can be called in the script

   action "command successful" /bin/false

   action "command successful" /bin/true 

   action is a function defined in functions

7. Modify the kernel parameters, you can directly specify the run level, no longer read the /etc/inittab file to start, in Centos6, if you enter the a key to specify 1 or 5

8.ntsysv (the tool modified is actually the initial letter of the file name) The default startup with * can be modified to start or modify the boot service, or you can set whether to start the boot or not by modifying the initial letter of the file

  ntsysv --level=3 can specify which level of startup service to modify

  chkconfig --list atd Check whether the atd service is started

  chkconfig --level 35 atd off Set the atd service to not start automatically at run levels 3 and 5 by default

  chkconfig atd off atd Modify whether the server at level 2345 is started (if --level is not specified, the default is 2345 run level)

  ls /var/lock/subsys judges whether the service is started by judging whether the file exists (defined in the startup script), and judges the service when the service is started

  The scripts under /etc/rc3.d/ have dependencies, so the order has a sequential relationship, and the numerical serial number is the order of startup

  chkconfig --add testsrv Add a custom service script (the script must have execute permission)

  chkconfig --del testsrv removed from the service, the script file still exists

  /etc/rc.local can also make a boot-up self-starting service (no need to use the special line of the service script), you need to manually add the execution permission in centos7

  service --status-all View the status of all services

  yum install telnet-server since xinetd (as needed to determine the service), chkconfig --list 

  Telnet is based on the super daemon to manage services that are not frequently used. It is started as needed when needed, but the services that need to be started are set to the on state so that the xinetd daemon can wake up.

  chkconfig telnet on Modify the /etc/xinited/telnet file to restart the service to take effect configuration file

  xinetd is responsible for activating the telnet service, pay attention to use chkconfig telnet on to enable xinetd to activate the service (you can use the service ps command to view the process observation difference before the connection and after the connection, before the connection is xinetd to monitor port 23, and there is a link when there is a connection. real telnet to respond to requests)

  mingetty is the login interface, because the respawn option means regeneration, so mingetty cannot be killed (kill -9)

  The above refers to redhat5, (the principle of centos 6 is the same, but the configuration file is independent)


  Service script:

  # chkconfig: 345 95 5 345: run level, 95 is the default open 95 order, 5 is the must-have line in the closed order script

    - means all services are off chkconfg: - 95 5

  Repair grub, grub-install /dev/sda, need to root chroot /mnt/sysimage/ in rescue mode Repair all stages (stage 1, stage 1.5, stage 2)

  In the boot menu, selinux=0 can not start selinux at startup

  hd0,0 The first disk, the first partition / Whether the partition where the boot is located is the first disk

  The file under /boot/grub is the backup file stage Repair all stages

  After the repair, if the stage template file is deleted and restarted, an error will be reported. If the stage template file is deleted before the repair, it will not affect the system startup.


  kernel (hd0,0)/vmlinuz-..  root=/dev/sda2

  When the root file system is loaded, the driver is required, and the initramfs file is required, because the driver is in the initramfs

  rhgb: is to load the operating system boot process graphically  

  quiet: do not display kernel loading information

  Note the order of initrd and kernel

  default=0 default is the first title

  password magedu

  grub-md5-crypt md5 generates encrypted password

  password --md5 encrypted password

  grub-crypt generates sha512 encrypted password

  password --encrypted followed by sha512 encrypted password


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326745035&siteId=291194637