444 Chapter 9 ■ Writing Scripts, Configuring Email, and Using Database dịch - 444 Chapter 9 ■ Writing Scripts, Configuring Email, and Using Database Việt làm thế nào để nói

444 Chapter 9 ■ Writing Scripts, Co

444 Chapter 9 ■ Writing Scripts, Configuring Email, and Using Databases
If you enter Listing 9.6 and call it safercp, you can use it like this, assuming the file
original.txtexists and dest.txtdoesn’t:
$ ./safercp original.txt dest.txt
$ ./safercp original.txt dest.txt
Target file exists! Exiting!
The first run of the command succeeded because dest.txtdidn’t exist. When the command was run a second time, though, the destination file did exist, so the program terminated with the error message.
Note that the functions aren’t run directly and in the order in which they appear in the
script. They’re run only when called in the main body of the script (which in Listing 9.6
consists of just two lines, each corresponding to one function call).
Shell scripts are useful tools, and creating them requires practice. Exercise 9.2 begins
your exploration of shell scripts, but in the long run you’ll need to learn to design your
own shell scripts by doing more than copying examples from a book.
EXERCISE 9.2
Creating a Simple Script
This exercise presents a shell script that gives you the option of using lessto read every
text file (with a name ending in .txt) in the current directory. To begin with this script, follow these steps:
1. Log into the Linux system as a normal user.
2.Launch an xtermfrom the desktop environment’s menu system, if you used a GUI login
method.
3. Start an editor, and tell it to edit a file called testscript.
4. Type the following lines into the editor:
#!/bin/bash
for file in `ls *.txt` ; do
echo -n “Display $file? “
read answer
if [ $answer == ‘y’ ]
then
less $file
fi
done
Be sure you’ve typed every character correctly; any mistake may cause the script to misbehave. One common error is mistyping the back-tick characters (`) on the second line
as ordinary single-quote characters (‘).
5. Save the file, and exit the editor.
Managing Email 445
6.Type chmod a+x testscriptto add the executable bit to the file’s permissions.
7.Type ./testscriptto run the script. If there are no text (*.txt) files in your current
directory, the script displays a no such file or directoryerror message; but if any
text files are present, the script gives you the option of viewing each one in turn via less.
This example script is extremely limited, but it illustrates several important script features,
such as variable assignment and use, forloops, and if/thenconditional expressions.
Managing Email
Email is one of the most important network services. What’s more, Linux relies on email
even in a completely non-networked environment—certain Linux subsystems, such as cron
(described in Chapter 7), may use email to notify you of activities. For this reason, most
Linux distributions ship with email server software installed and configured for basic activities, and you should have a basic understanding of how to use these servers to accomplish
various tasks. You should understand the basics of email and be able to identify the specific
email server package your system is running. You should also be able to set up email aliases
(alternate names for users) and forwarding (to send mail for a user to another destination).
Finally, you should understand the security implications of email so that you can prevent
problems or identify them when they occur.
Understanding Email
Several protocols exist to manage email. The most common of these is the Simple Mail
Transfer Protocol (SMTP), which is designed as a push mail protocol, meaning that the
sending system initiates the transfer. This design is good for sending data, so SMTP is used
through most of a mail delivery system. The final stage, though, often employs a pull mail
protocol, such as the Post Of fice Protocol(POP) or the Internet Message Access Protocol
(IMAP). With these protocols, the receiving system initiates the transfer. This is useful
when the receiving system is an end user’s workstation, which may not be powered on at all
times or able to receive incoming connections.
SMTP was designed to enable a message to be relayed through an arbitrary number of
computers. For instance, an end user may compose a message, which is sent to the local
SMTP server. (SMTP servers are also known as mail transfer agents, or MTAs.) This server
looks up a recipient system using the Domain Name System (DNS) and sends the message
to that computer. This system may use its own internal routing table to redirect the message to another local computer, from which the message may be read, either directly or via
a POP or IMAP server. This arrangement is illustrated in Figure 9.1. Bear in mind that the
number of links in this chain is variable and depends on how each system is configured. In
the simplest case, local email stays on just one system. In theory, an arbitrarily large number of computers can be involved in an email exchange, although in practice it’s rare to see
email pass through more than half a dozen systems.
446 Chapter 9 ■ Writing Scripts, Configuring Email, and Using Databases
At each step in a relay chain, email is altered. Most important, each server adds a header
to the email, which is a line that provides information about the message. In particular,
mail servers add Received:headers to document the path the mail has taken. In theory,
this enables you to trace the email back to its source. Unfortunately, spammers and other
email abusers have learned to forge email headers, which greatly complicates such analysis.
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
444 Chapter 9 ■ Writing Scripts, Configuring Email, and Using DatabasesIf you enter Listing 9.6 and call it safercp, you can use it like this, assuming the file original.txtexists and dest.txtdoesn’t:$ ./safercp original.txt dest.txt$ ./safercp original.txt dest.txtTarget file exists! Exiting!The first run of the command succeeded because dest.txtdidn’t exist. When the command was run a second time, though, the destination file did exist, so the program terminated with the error message.Note that the functions aren’t run directly and in the order in which they appear in the script. They’re run only when called in the main body of the script (which in Listing 9.6 consists of just two lines, each corresponding to one function call).Shell scripts are useful tools, and creating them requires practice. Exercise 9.2 begins your exploration of shell scripts, but in the long run you’ll need to learn to design your own shell scripts by doing more than copying examples from a book.EXERCISE 9.2Creating a Simple ScriptThis exercise presents a shell script that gives you the option of using lessto read every text file (with a name ending in .txt) in the current directory. To begin with this script, follow these steps:1. Log into the Linux system as a normal user.2.Launch an xtermfrom the desktop environment’s menu system, if you used a GUI login method.3. Start an editor, and tell it to edit a file called testscript.4. Type the following lines into the editor:#!/bin/bashfor file in `ls *.txt` ; doecho -n “Display $file? “read answerif [ $answer == ‘y’ ]thenless $filefidoneBe sure you’ve typed every character correctly; any mistake may cause the script to misbehave. One common error is mistyping the back-tick characters (`) on the second line as ordinary single-quote characters (‘).5. Save the file, and exit the editor.Managing Email 4456.Type chmod a+x testscriptto add the executable bit to the file’s permissions.7.Type ./testscriptto run the script. If there are no text (*.txt) files in your current directory, the script displays a no such file or directoryerror message; but if any text files are present, the script gives you the option of viewing each one in turn via less.This example script is extremely limited, but it illustrates several important script features, such as variable assignment and use, forloops, and if/thenconditional expressions.Managing EmailEmail is one of the most important network services. What’s more, Linux relies on email even in a completely non-networked environment—certain Linux subsystems, such as cron(described in Chapter 7), may use email to notify you of activities. For this reason, most Linux distributions ship with email server software installed and configured for basic activities, and you should have a basic understanding of how to use these servers to accomplish various tasks. You should understand the basics of email and be able to identify the specific email server package your system is running. You should also be able to set up email aliases (alternate names for users) and forwarding (to send mail for a user to another destination). Finally, you should understand the security implications of email so that you can prevent problems or identify them when they occur.Understanding EmailSeveral protocols exist to manage email. The most common of these is the Simple Mail Transfer Protocol (SMTP), which is designed as a push mail protocol, meaning that the sending system initiates the transfer. This design is good for sending data, so SMTP is used through most of a mail delivery system. The final stage, though, often employs a pull mail protocol, such as the Post Of fice Protocol(POP) or the Internet Message Access Protocol(IMAP). With these protocols, the receiving system initiates the transfer. This is useful when the receiving system is an end user’s workstation, which may not be powered on at all times or able to receive incoming connections.SMTP was designed to enable a message to be relayed through an arbitrary number of computers. For instance, an end user may compose a message, which is sent to the local SMTP server. (SMTP servers are also known as mail transfer agents, or MTAs.) This server looks up a recipient system using the Domain Name System (DNS) and sends the message to that computer. This system may use its own internal routing table to redirect the message to another local computer, from which the message may be read, either directly or via
a POP or IMAP server. This arrangement is illustrated in Figure 9.1. Bear in mind that the
number of links in this chain is variable and depends on how each system is configured. In
the simplest case, local email stays on just one system. In theory, an arbitrarily large number of computers can be involved in an email exchange, although in practice it’s rare to see
email pass through more than half a dozen systems.
446 Chapter 9 ■ Writing Scripts, Configuring Email, and Using Databases
At each step in a relay chain, email is altered. Most important, each server adds a header
to the email, which is a line that provides information about the message. In particular,
mail servers add Received:headers to document the path the mail has taken. In theory,
this enables you to trace the email back to its source. Unfortunately, spammers and other
email abusers have learned to forge email headers, which greatly complicates such analysis.
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
444 Chương 9 ■ Scripts Viết, Cấu hình Email, và sử dụng cơ sở dữ liệu
Nếu bạn nhập Listing 9.6 và gọi nó safercp, bạn có thể sử dụng nó như thế này, giả sử tập tin
original.txtexists và dest.txtdoesn't:
$ ./safercp original.txt dest.txt
$ ./safercp original.txt dest.txt
tập tin mục tiêu tồn tại! Thoát khỏi!
Việc chạy đầu tiên của lệnh thành công vì dest.txtdidn't tồn tại. Khi lệnh được chạy một lần thứ hai, mặc dù, các tập tin đích đã tồn tại, vì vậy chương trình chấm dứt với các thông báo lỗi.
Lưu ý rằng chức năng này không chạy trực tiếp và theo thứ tự mà chúng xuất hiện trong
kịch bản. Họ đang chạy chỉ khi gọi trong cơ thể chính của kịch bản (mà trong Ví dụ 9.6
chỉ gồm hai dòng, mỗi dòng tương ứng với một chức năng gọi).
Kịch bản Shell là công cụ hữu ích, và tạo ra chúng đòi hỏi phải thực hành. Tập thể dục 9.2 bắt đầu
hành trình khám phá của kịch bản shell, nhưng về lâu dài, bạn sẽ cần phải tìm hiểu để thiết kế của bạn
kịch bản shell riêng bằng cách làm nhiều hơn việc sao chép các ví dụ từ một cuốn sách.
Bài tập 9.2
Tạo một Script đơn giản
Bài tập này trình bày một kịch bản cung cấp cho bạn tùy chọn sử dụng lessto đọc từng
tập tin văn bản (với một tên kết thúc bằng .txt) trong thư mục hiện hành. Để bắt đầu với kịch bản này, hãy làm theo các bước sau:
1. Đăng nhập vào hệ thống Linux như một người sử dụng bình thường.
2.Launch một xtermfrom hệ thống menu môi trường máy tính để bàn, nếu bạn sử dụng một giao diện đăng nhập của
phương pháp.
3. Bắt đầu một biên tập viên, và nói với nó để chỉnh sửa một tập tin gọi là testscript.
4. Gõ các dòng sau vào trình soạn thảo:
# / bin / bash!
For file in `ls * .txt`; làm
echo -n "Display $ file? "Đọc câu trả lời nếu [$ câu trả lời == 'y'] sau đó ít $ file fi thực hiện Hãy chắc chắn rằng bạn đã gõ từng ký tự một cách chính xác; bất kỳ sai lầm có thể gây ra các kịch bản để hoạt động sai. Một lỗi phổ biến được đánh nhầm các ký tự lại dấu tick (`) trên dòng thứ hai là nhân vật duy nhất-báo bình thường ('). 5. Lưu tập tin, và thoát khỏi trình soạn thảo. Quản lý Email 445 6.Chọn chmod a + x testscriptto thêm các bit thực thi để các quyền của tập tin. 7.Type ./testscriptto chạy script. Nếu không có văn bản (* .txt) các tập tin trong hiện tại của bạn thư mục, các tập lệnh sẽ hiển thị một không có tập tin hoặc directoryerror nhắn; nhưng nếu bất kỳ tập tin văn bản, có mặt, các kịch bản cung cấp cho bạn tùy chọn xem mỗi một lần lượt qua ít. kịch bản Ví dụ này là rất hạn chế, nhưng nó minh họa một số tính năng kịch bản quan trọng, chẳng hạn như giao biến và sử dụng, forloops, và nếu / biểu thenconditional. Quản lý Email Email là một trong những dịch vụ mạng quan trọng nhất. Hơn nữa, Linux dựa trên email ngay cả trong một hoàn toàn không nối mạng hệ thống con Linux với môi trường nhất định, chẳng hạn như cron (mô tả trong Chương 7), có thể sử dụng email để thông báo cho bạn về những hoạt động này. Vì lý do này, hầu hết các Linux tàu phân phối với các phần mềm máy chủ email được cài đặt và cấu hình cho các hoạt động cơ bản, và bạn cần phải có một sự hiểu biết cơ bản về cách sử dụng các máy chủ để thực hiện các nhiệm vụ khác nhau. Bạn nên hiểu những điều cơ bản của thư điện tử và có thể xác định cụ thể các gói máy chủ email hệ thống của bạn đang chạy. Bạn cũng có thể thiết lập bí danh email (tên thay thế cho người sử dụng) và chuyển tiếp (để gửi thư cho một người dùng đến đích khác). Cuối cùng, bạn nên hiểu rõ những vấn đề bảo mật của email để bạn có thể ngăn chặn các vấn đề hoặc nhận ra chúng khi chúng xảy ra. Hiểu Email Một số giao thức tồn tại để quản lý email. Phổ biến nhất trong số này là Simple Mail Transfer Protocol (SMTP), được thiết kế như là một giao thức push mail, có nghĩa là hệ thống gửi khởi chuyển. Thiết kế này là tốt cho việc gửi dữ liệu, vì vậy SMTP được sử dụng thông qua hầu hết của một hệ thống chuyển phát thư. Giai đoạn cuối cùng, mặc dù, thường sử dụng một thư pull giao thức, như: Bưu Of fice Protocol (POP) hoặc Internet Message Access Protocol (IMAP). Với các giao thức này, hệ thống tiếp nhận khởi chuyển. Điều này rất hữu ích khi hệ thống tiếp nhận là máy trạm của người dùng cuối, mà có thể không được cung cấp trên ở tất cả các lần hoặc có thể nhận được kết nối đến. SMTP được thiết kế để cho phép một tin nhắn sẽ được chuyển tiếp qua một số tùy ý của máy tính. Ví dụ, một người dùng có thể soạn tin nhắn, được gửi đến các địa phương máy chủ SMTP. (Máy chủ SMTP cũng được biết đến như là các đại lý chuyển thư, hoặc MTA.) Máy chủ này nhìn lên một hệ thống nhận bằng cách sử dụng hệ thống tên miền (DNS) và gửi tin nhắn đến máy tính đó. Hệ thống này có thể sử dụng bảng định tuyến nội bộ riêng của mình để chuyển hướng các thông điệp tới một máy tính khác ở địa phương, từ đó các tin nhắn có thể được đọc, hoặc trực tiếp hoặc thông qua một máy chủ POP hoặc IMAP. Sự sắp xếp này được minh họa trong hình 9.1. Hãy nhớ rằng số lượng các liên kết trong chuỗi này là khác nhau tùy thuộc vào cách mỗi hệ thống được cấu hình. Trong trường hợp đơn giản, email địa phương nằm trên chỉ là một hệ thống. Về lý thuyết, một số tùy tiện lớn các máy tính có thể được tham gia vào một cuộc trao đổi email, mặc dù trong thực tế nó hiếm khi thấy email đi qua hơn nửa tá các hệ thống. 446 Chương 9 ■ Scripts Viết, Cấu hình Email, và sử dụng cơ sở dữ liệu Tại mỗi bước trong một chuỗi relay, email bị thay đổi. Quan trọng nhất, mỗi máy chủ cho biết thêm một tiêu đề cho email, mà là một dòng cung cấp thông tin về tin nhắn. Cụ thể, máy chủ mail add nhận: tiêu đề tài liệu đường dẫn thư đã thực hiện. Về lý thuyết, điều này cho phép bạn theo dõi các email trở lại nguồn gốc của nó. Thật không may, kẻ gửi thư rác và khác người lạm dụng email đã học được để giả mạo tiêu đề email, mà rất nhiều phức tạp phân tích như vậy.

















































đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2024 I Love Translation. All reserved.

E-mail: