Litgu.ru — Литературный Гуру
Linux Command Line and Shell Scripting Bible
Название: Linux Command Line and Shell Scripting Bible
Автор: Richard Blum, Christine Bresnahan
Издательство: W?ley
Год: 2015
Формат: PDF
Размер: 17 Мб
Язык: английский
Linux Command Line and Shell Scripting Bible is your essential Linux guide. With detailed instruction and abundant examples, this book teaches you how to bypass the graphical interface and communicate directly with your computer, saving time and expanding capability. This third edition incorporates thirty pages of new functional examples that are fully updated to align with the latest Linux features. Beginning with command line fundamentals, the book moves into shell scripting and shows you the practical application of commands in automating frequently performed functions. This guide includes useful tutorials, and a desk reference value of numerous examples.
The Linux command line allows you to type specific shell commands directly into the system to manipulate files and query system resources. Command line statements can be combined into short programs called shell scripts, a practice increasing in popularity due to its usefulness in automation. This book is a complete guide providing detailed instruction and expert advice working within this aspect of Linux.
Write simple script utilities to automate tasks
Understand the shell, and create shell scripts
Produce database, e-mail, and web scripts
Study scripting examples ranging from basic to advanced
Whether used as a tutorial or as a quick reference, this book contains information that every Linux user should know. Why not learn to use the system to its utmost capability? Linux is a robust system with tremendous potential, and Linux Command Line and Shell Scripting Bible opens the door to new possibilities.
Источник
Linux commands in shell scripting bible
Twenty-three chapters: Use Database
MySQL database
MySQL client interface
mysql command-line arguments
parameter | description |
-A | Disable automatic rebuild the hash table |
-b | beep sound is disabled after an error |
-B | Do not use history file |
-C | Compressing all the messages sent between client and the server |
-D | Specify the use of database |
-e | Executes the specified statement and exit |
-E | The vertical direction of the display query output, each row of data field |
-f | If you have SQL error occurs, continue |
-G | Enable named commands use |
-h | Specifies the MySQL server host name (the default is localhost) |
-H | Display query output with HTML code |
-i | It ignores spaces after function names |
-N | The results are not displayed in the column name |
-o | Ignore statements except statements on the command line named default database |
-p | Enter the command prompt for a user account |
-P | Specify a network connection to TCP port number |
-q | Do not cache each query result |
-r | Column output display, not escaping |
-s | Use Quiet mode |
-S | Designated as a local socket (localhost) connected |
-t | Output in table format, |
-T | When the program exits debugging display, memory, and CPU statistics |
-u | Specifies the user login name |
-U | Allow only specified keys UPDATE and DELETE statements |
-v | Use verbose mode |
-w | If the connection is not completed, wait and try again |
-X | XHTML code displays query output |
mysql command without any parameters, Linux login server connect to local MySQL will be used.
Use specified user name -u, -p tells the mysql prompt output corresponding password
mysql using two different types of commands:
1. Special mysql command
2. Standard SQL statements
command | Shorthand command | description |
? | \? | help information |
clear | \c | Clear command |
connect | \r | And connect to the database server |
delimiter | \d | Set SQL statement separator |
edit | \e | Command-line editor command |
ego | \G | MySQL server sends a command to display the results of the vertical and |
exit | \q | Exit mysql program |
go | \g | Send commands to the MySQL server |
help | \h | Displays help information |
nopaper | \n | Disable Output tab and send output to STDOUT |
note | \t | Do not send the output to the output file |
paper | \P | The paging command to the specified program (default is more) |
\p | Print command | |
prompt | \R | Modify the mysql command prompt |
quit | \q | Exit mysql program (same exit) |
rehash | \# | Rebuild command completion hash table |
source | \. | Executes the specified SQL script file |
status | \s | Information extracted from the MySQL server status |
system | \! | Execute shell commands on the system |
tee | \T | All output will be appended to the specified file |
use | \u | Use another database |
charset | \C | Switch to another character set |
warnings | \W | Display a warning message after each statement |
nowarnings | \w | Do not display a warning message after each statement |
SHOW can view the database information, such as:
You can also view information in a database table
Inside the mysql database command is not case sensitive, but the convention is to use uppercase letters
Create a MySQL database objects
Create a database:
CREATE DATABASES + library name
Creating a user account
mysql> GRANT SELECT,INSERT,UPDATE,DELETE ON test.* TO test_user IDENTIFIED by ‘pwd’;
GRANT SELECT, INSERT, UPDATE, DELETE may be described database CRUD
ON test. * In all tables specify the role of the above test database (format database.table)
TO test_user IDENTIFIED by ‘pwd’ specified accounts for the test_user, if test_user account does not exist, it is created automatically, IDENTIFIED by default allows you to set a password, where password is pwd
Then you can use the new account login
PostgreSQL database
PostgreSQL Command Line Interface
psql command line arguments
Abbreviated name | Full name | description |
-a | —echo-all | Show all rows SQL script file is executed in the output |
-A | —no-align | The unaligned mode is set to the output format, or format data not shown in Table |
-c | —command | Executes the specified SQL statement and exit |
-d | —dbname | Specify the database to connect to |
-e | —echo-queries | The output of all queries to the screen |
-E | —echo-hidden | The hidden psql meta-command output to the screen |
-f | —file | Execute SQL commands in the specified file and exit |
-F | —field-separator | The specified character data in a separate list unaligned mode. The default is a comma |
-h | —host | Specifies the remote PostgreSQL server’s IP address or host name |
-l | —list | Display a list of existing database on the server and exit |
-o | —output | The query output redirected to the specified file |
-p | —post | Specifies the PostgreSQL server to connect to TCP port |
-P | —pset | Table print options to the specified value |
-q | —quiet | Quiet mode, the output message is displayed |
-R | —record-separator | The specified character as a data line separator. The default is a newline |
-s | —single-step | Tip continue or quit after each SQL query |
-S | —single-line | Specifies the enter key instead of a semicolon to end a SQL query |
-t | —tuples-only | Disabling the output column in the table header and trailer |
-T | —table-attr | HTML tags specified in an HTML table mode |
-U | —username | Use specified user name connected PostgreSQL server |
-v | —variable | The specified variable is set to a specified value |
-V | —version | Psql displays the version number and exits |
-W | —password | Forced Command Prompt |
-x | —expanded | Enabling the extended table to display additional information about the data output line |
-X | —nopsqlrc | Do not run psql startup file |
-? | —help | Psql display command line help information and exit |
PostgreSQL administrator account to postgres, rather than root
If the current Linux login account is not postgres, you will need to use sudo to run psql postgres account
# Prompt as an administrator logs indicate has psql.
psql using two different types of commands:
1.Postgre metacommands
2. Standard SQL statements
Postgre meta-command can easily access the exact information database environment, but also has set function psql session.
Yuan command marked with a backslash.
Yuan commonly used commands:
\ L: lists the existing database
\ C: connect to the database
\ Dt: listed in the database table
\ Du lists the user’s Postgre
\ Z: lists the permissions on the table
\ ?: Lists all available commands yuan
\ H: Lists all available SQL commands
\ Q: Quit database
Create a PostgreSQL database objects
CREATE DATABASE + library name
Connected to the database when the test, the psql prompt changed, displays the name of the database connection
Description: PostgreSQL database adds a control layer, called pattern (schema).
The database may have a plurality of patterns, each pattern comprising a plurality of tables.
By default, each database has a field called public model. Used in the above example is the public mode.
PostgreSQL user account called login roles (Login Role). PostgreSQL will login role and Linux user accounts to match.
So there are two common ways to create a shell script to run the login role access to PostgreSQL database:
1. Create a special Linux and PostgreSQL login account corresponding to the role to run all shell scripts
2. For each need to run the shell script to access the database PostgreSQL Linux user account creation account
CREATE ROLE + Name
This establishes a role, If you do not use the login parameters, then allowed to log on to the PostgreSQL server, but can be granted a number of privileges. This role type is called character group (group role).
PostgreSQL does not allow all the permissions assigned to all database objects matching table level, need to grant permission for each new table.
Use Data Sheet
Create a data table
Ensure that the administrator user account before creating a new table (root user in MySQL, postgres user in PostgreSQL) login to create tables
MySQL and PostgreSQL data types
type of data | description |
char | Fixed-length string values |
varchar | Variable-length string values |
int | Integer value |
float | Floating-point values |
Boolean | Boolean true / false value |
Date | Date values YYYY-MM-DD format |
Time | HH: mm: ss format time value |
Timestamp | A combination of a date and time value |
Text | Length string values |
BLOB | Large binary value |
Creating tables using the CREATE TABLE
In psql also need to assign permissions table level.
Log in to postgres role to perform, and connect to the test database, and must specify the schema name.
Insert and delete data
About SQL part, do not make detailed notes.
Query data
Using the database in the script
Connect to the database
When a script executes, mysql will stop to ask the user to enter a password, this problem can be avoided.
Below is a bad way, directly to the password in plain text in the script:
-p password are closely linked.
mysql use $ HOME / .my.cnf file to read the special startup commands and settings.
If it does not, we ourselves can build a
Now and then execute mysql_connection you will not be asked to enter your password
Send commands to the server
1. Send a command and exits
2. Send multiple commands
For mysql, you can use the -e option:
For psql, you can use the -c option
Send multiple commands can be used to redirect, Note: The last line of EOF where there are not other strings.
The results returned are the raw data, not before the border.
No separator between the results of multiple commands
For psql also applies, but the result is the return of the border.
Formatted data
The result set is assigned to the variable:
-B which indicates mysql using batch mode (disables Formatting symbols )
-s (silent) so that the column headings is prohibited out
Use formatting tags
psql mysql use -H and displays the results in HTML format
mysql can also display the results in XML format
Please keep the following link posted
Источник