Professional Documents
Culture Documents
Linux Advanced Ssssion 1 2 3 4
Linux Advanced Ssssion 1 2 3 4
PROGRAMA DE CERTIFICACIN
PROFESIONAL
Linux
Advanced
case $ans in
y|yes) echo "Displaying all (really) files"
ls -a ;;
n|no) echo "Display all non-hidden files..."
ls ;;
q) exit 0 ;;
for i in 1 2 3 4 5
do
echo $i
done
Constructs simple menu from word list
Allows user to enter a number instead of a word
User enters sequence number corresponding to the word
Syntax:
select WORD in LIST
do
RESPECTIVE-COMMANDS
done
Loops until end of input, i.e. ^d (or ^c)
Interrupt for, while or until loop
The break statement
transfer control to the statement AFTER the done statement
terminate execution of the loop
The continue statement
transfer control to the statement TO the done statement
skip the test statements for the current iteration
continues execution of the loop
Functions :
- A shell function is similar to a shell script
stores a series of commands for execution later
shell stores functions in memory
shell executes a shell function in the same shell that called it
- must be defined before they can be referenced usually placed at
the beginning of the script
- Variables defined within functions are global,
i.e. their values are known throughout the entire shell program
- keyword local inside a function definition makes referenced
variables local to that function
Syntax:
function-name () {
statements
}
Eg:
#!/bin/bash
hello () {
echo Hello World function called."
}
#function call
hello
Debugging is troubleshooting errors that may occur during the execution of a program/script
The following two commands can help you debug a bash shell script:
echo
use explicit output statements to trace execution
Set
The set command is a shell built-in command
has options to allow flow of execution
v option prints each line as it is read
x option displays the command and its arguments
n checks for syntax errors
options can turned on or of
To turn on the option: set -xv
To turn of the options: set +xv
Options can also be set via she-bang line
#! /bin/bash -xv
MySQL
- MySQL is a relational database management system
(RDBMS)
- Installation : yum install mysql-server mysql
Server mysqld
Clients - mysql, mysqladmin
- Set root password
mysqladmin u root password the_password
- Login to mysql database using root user
mysql uroot -p
- Display Databases show databases;
mysql database provides information about mysql users
- Use database named mysql - use mysql;
- Create a database named customer
create database customer;
- Create table amount in a database customer
create table customer.amount (id INT(8) NOT NULL, name
VARCHAR(16) NOT NULL, price INT(8) NOT NULL, type
VARCHAR(16) NOT NULL, email VARCHAR(20) NOT NULL);
or (if inside the database customer) use customer;
create table amount (id INT(8) NOT NULL, name VARCHAR(16)
NOT NULL, price INT(8) NOT NULL, type VARCHAR(16) NOT NULL , email
VARCHAR(20) NOT NULL);
- Display table show tables;
- Insert values into the tables fields(id, name, price, type, email)
INSERT INTO amount (id,name,price,type,email)
VALUES(1,jose",55,liquid,jose@microsoft.com");
- Display the table amount field values
SELECT * FROM amount; (Display all the table field values)
SELECT * FROM amount WHERE id=1; (Display all the table
values where the field (id) value matches 1)
SELECT name FROM amount WHERE id=1; (Display the name field
value from the table values where the field (id) value matches 1)
- Describe information about the table amount in the customer database
describe customer.amount;
- Create an user(jose) in mysql, which has access from
system with IP address 192.168.1.2
CREATE USER jose@l192.168.1.2 IDENTFIFIED BY
the_password;
Verify
SELECT user,host FROM mysql.user;
- Provide full access permission on the database customer to
the user jose from system with IP 192.168.1.2
GRANT ALL PRIVILEGES ON customer.* TO
jose@l192.168.1.2;
- Updating table(amount) fields, replace name jose with marco
UPDATE amount SET name=marco WHERE name=jose;
- Delete the entry from the table(amount) , where name field matches marco
DELETE FROM amount WHERE name=marco;
- Sort values, sort values in ascending order based on field price from the
table amount
SELECT * FROM amount ORDER BY price asc;
- Group values, group values based on the field type
SELECT * FROM amount GROUP BY type;
- Joins (Join two tables based on a common identifier)
Left join (Join table amount_1(right) to table amount(left)
based of common identifier id
SELECT * FROM amount LEFT JOIN amount_1 ON
amount.id=amount_1.id;
- export the database amount to a file mysql_amount.dump
mysqldump uroot p amount > mysql_amount.dump
- export the database amount to a file mysql_amount.dump
mysqldump uroot p amount > mysql_amount.dump
- Import the database amount from the file mysql_amount.dump
mysqldump uroot p amount < mysql_amount.dump
Note : the database amount must exist