2. In some software installation processes, you need to create an independent user and then run some installation operations such as gitolite installation, create a git user and execute the installation.
Method 1:sudo -u user ...
Sudo-u Git-H <-codels ~ CAT test # other cmdscode
Subsequent commands will be executed by users after switching before code.
Method 2:su
Su command
#!/bin/sh echo ~/ su - test <<HERE echo ~/ ls -al HERE echo ~/sudo su - user1echo #HOMEecho `ls -ltr`
You can use the sudo command. Its function is "excute a command as another user". By default, it is the root user. You can use-u to specify the user name (assuming that you want to execute the prog program as a user ):sudo -u user prog
You can.
Another command, Su, is to run the shell with another identity, and then run the specified program with the new shell (Su can only run in the shell terminal, although the command can be written as [Su-C user prog] Like sudo, its implementation principle is actually to first run a shell and then run other programs through the shell ).
Http://www.shareup.me/metadocs/11197
In Shell, EOF and <are used in combination to indicate that subsequent input is used as the input of sub-commands or sub-shells until EOF is encountered, and then return to the main shell. As follows:
Export nls_lang = 'simplified chinese_china.zhs16gbk'
Sqlplus $ userid @ $ out_file <EOF
Exit
EOF
When you place this code in shell, the SQL plus command prompt status is automatically exited after the shell script is executed.
<EOF
(Content)
EOF
You can replace EOF with other things, which means to pass the content to the program as a standard input. Here, we will briefly review the usage of <. When s h e l sees <, it will know that the next word is a separator. The content after the Delimiter is treated as input until s h e l sees that the Delimiter is in a separate line ). This delimiter can be any string you define. Tip: it is best to leave no space at the beginning of the line.
Method 1. Automatically log on to MySQL (root: Root, passwd: 123456) and query the user = AA records in the test database and test1 table.
#! /Bin/sh
Mysql-uroot-p123456 <EOF
Use test;
Select * From testaa while a = 10000; ### 1000 not USR single quote Mark, because a is int
# Type, only char type need single quote Mark.
Exit
EOF
In shell: $0: get the name of the current script $ #: number of parameters passed to the script $: Process Number of the shell script $1, $2, $3...: script program parameters
Method 2: Use CT scripts
Secondary CT usage: Reference http://www.cnblogs.com/iloveyoucc/archive/2012/05/11/2496433.html
You can put the script in the RC. Local directory in the/etc/rc. d directory.