mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
20150409-1 选题
This commit is contained in:
parent
df021e44da
commit
1a8f2a2592
@ -0,0 +1,261 @@
|
||||
4 Tools Send Email with Subject, Body and Attachment in Linux
|
||||
================================================================================
|
||||
In today's article we will cover a few ways you can use to send emails with attachments from the command line interface on Linux. It can have quite a few uses, for example to send an archive with an application from an application server to email or you can use the commands in scripts to automate some process. For our examples,we will use the file foo.tar.gz as our attachment.
|
||||
|
||||
There are various ways to send emails from command line using different mail clients but here I am sharing few mail client utility used by most users like mailx, mutt and swaks.
|
||||
|
||||
All the tools we will present to you are very popular and present in the repositories of most Linux distributions, you can install them using the following commands:
|
||||
|
||||
For **Debian / Ubuntu** systems
|
||||
|
||||
apt-get install mutt
|
||||
apt-get install swaks
|
||||
apt-get install mailx
|
||||
apt-get install sharutils
|
||||
|
||||
For Red Hat based systems like **CentOS** or **Fedora**
|
||||
|
||||
yum install mutt
|
||||
yum install swaks
|
||||
yum install mailx
|
||||
yum install sharutils
|
||||
|
||||
### 1) Using mail / mailx ###
|
||||
|
||||
The mailx utility found as the default mailer application in most Linux distributions now includes the support to attach file. If it is not available you can easily install using the following commands please take note that this may not be supported in older versions, to check this you can use the command:
|
||||
|
||||
$ man mail
|
||||
|
||||
And the first line should look like this:
|
||||
|
||||
mailx [-BDdEFintv~] [-s subject] [-a attachment ] [-c cc-addr] [-b bcc-addr] [-r from-addr] [-h hops] [-A account] [-S variable[=value]] to-addr . . .
|
||||
|
||||
As you can see it supports the -a attribute to add a file to the email and -s attribute to subject to the email. Use few of below examples to send mails.
|
||||
|
||||
**a) Simple Mail**
|
||||
|
||||
Run the mail command, and then mailx would wait for you to enter the message of the email. You can hit enter for new lines. When done typing the message, press Ctrl+D and mailx would display EOT.
|
||||
|
||||
After than mailx automatically delivers the email to the destination.
|
||||
|
||||
$ mail user@example.com
|
||||
|
||||
HI,
|
||||
Good Morning
|
||||
How are you
|
||||
EOT
|
||||
|
||||
**b) To send email with subject**
|
||||
|
||||
$ echo "Email text" | mail -s "Test Subject" user@example.com
|
||||
|
||||
-s is used for defining subject for email.
|
||||
|
||||
**c) To send message from a file**
|
||||
|
||||
$ mail -s "message send from file" user@example.com < /path/to/file
|
||||
|
||||
**d) To send message piped using the echo command**
|
||||
|
||||
$ echo "This is message body" | mail -s "This is Subject" user@example.com
|
||||
|
||||
**e) To send email with attachment**
|
||||
|
||||
$ echo “Body with attachment "| mail -a foo.tar.gz -s "attached file" user@example.com
|
||||
|
||||
-a is used for attachments
|
||||
|
||||
### 2) mutt ###
|
||||
|
||||
Mutt is a text-based email client for Unix-like systems. It was developed over 20 years ago and it's an important part of Linux history, one of the first clients to support scoring and threading capabilities. Use few of below examples to send email.
|
||||
|
||||
**a) Send email with subject & body message from a file**
|
||||
|
||||
$ mutt -s "Testing from mutt" user@example.com < /tmp/message.txt
|
||||
|
||||
**b) To send body message piped using the echo command**
|
||||
|
||||
$ echo "This is the body" | mutt -s "Testing mutt" user@example.com
|
||||
|
||||
**c) To send email with attachment**
|
||||
|
||||
$ echo "This is the body" | mutt -s "Testing mutt" user@example.com -a /tmp/foo.tar.gz
|
||||
|
||||
**d) To send email with multiple attachments**
|
||||
|
||||
$ echo "This is the body" | mutt -s "Testing" user@example.com -a foo.tar.gz –a bar.tar.gz
|
||||
|
||||
### 3) swaks ###
|
||||
|
||||
Swaks stands for Swiss Army Knife for SMTP and it is a featureful, flexible, scriptable, transaction-oriented SMTP test tool written and maintained by John Jetmore. You can use the following syntax to send an email with attachment:
|
||||
|
||||
$ swaks -t "foo@bar.com" --header "Subject: Subject" --body "Email Text" --attach foo.tar.gz
|
||||
|
||||
The important thing about Swaks is that it will also debug the full mail transaction for you, so it is a very useful tool if you also wish to debug the mail sending process:
|
||||
|
||||
As you can see it gives you full details about the sending process including what capabilities the receiving mail server supports, each step of the transaction between the 2 servers.
|
||||
|
||||
### 4) uuencode ###
|
||||
|
||||
Email transport systems were originally designed to transmit characters with a seven-bit encoding -- like ASCII. This meant they could send messages with plain text but not "binary" text, such as program files or image files that used all of an eight-bit byte. The program is used to solve this limitation is “uuencode”( "UNIX to UNIX encoding") which encode the mail from binary format to text format that is safe to transmit & program is used to decode the data is called “uudecode”
|
||||
|
||||
We can easily send binary text such as a program files or image files using uuencode with mailx or mutt email client is shown by following example:
|
||||
|
||||
$ uuencode example.jpeg example.jpeg | mail user@example.com
|
||||
|
||||
### Shell Script : Explain how to send email ###
|
||||
|
||||
#!/bin/bash
|
||||
|
||||
FROM=""
|
||||
SUBJECT=""
|
||||
ATTACHMENTS=""
|
||||
TO=""
|
||||
BODY=""
|
||||
|
||||
# Function to check if entered file names are really files
|
||||
function check_files()
|
||||
{
|
||||
output_files=""
|
||||
for file in $1
|
||||
do
|
||||
if [ -s $file ]
|
||||
then
|
||||
output_files="${output_files}${file} "
|
||||
fi
|
||||
done
|
||||
echo $output_files
|
||||
}
|
||||
|
||||
echo "*********************"
|
||||
echo "E-mail sending script."
|
||||
echo "*********************"
|
||||
echo
|
||||
|
||||
# Getting the From address from user
|
||||
while [ 1 ]
|
||||
do
|
||||
if [ ! $FROM ]
|
||||
then
|
||||
echo -n -e "Enter the e-mail address you wish to send mail from:\n[Enter] "
|
||||
else
|
||||
echo -n -e "The address you provided is not valid:\n[Enter] "
|
||||
fi
|
||||
|
||||
read FROM
|
||||
echo $FROM | grep -E '^.+@.+$' > /dev/null
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
# Getting the To address from user
|
||||
while [ 1 ]
|
||||
do
|
||||
if [ ! $TO ]
|
||||
then
|
||||
echo -n -e "Enter the e-mail address you wish to send mail to:\n[Enter] "
|
||||
else
|
||||
echo -n -e "The address you provided is not valid:\n[Enter] "
|
||||
fi
|
||||
|
||||
read TO
|
||||
echo $TO | grep -E '^.+@.+$' > /dev/null
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
# Getting the Subject from user
|
||||
echo -n -e "Enter e-mail subject:\n[Enter] "
|
||||
read SUBJECT
|
||||
|
||||
echo
|
||||
|
||||
if [ "$SUBJECT" == "" ]
|
||||
then
|
||||
echo "Proceeding without the subject..."
|
||||
fi
|
||||
|
||||
# Getting the file names to attach
|
||||
echo -e "Provide the list of attachments. Separate names by space.
|
||||
If there are spaces in file name, quote file name with \"."
|
||||
read att
|
||||
|
||||
echo
|
||||
|
||||
# Making sure file names are poiting to real files
|
||||
attachments=$(check_files "$att")
|
||||
echo "Attachments: $attachments"
|
||||
|
||||
for attachment in $attachments
|
||||
do
|
||||
ATTACHMENTS="$ATTACHMENTS-a $attachment "
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
# Composing body of the message
|
||||
echo "Enter message. To mark the end of message type ;; in new line."
|
||||
read line
|
||||
|
||||
while [ "$line" != ";;" ]
|
||||
do
|
||||
BODY="$BODY$line\n"
|
||||
read line
|
||||
done
|
||||
|
||||
SENDMAILCMD="mutt -e \"set from=$FROM\" -s \"$SUBJECT\" \
|
||||
$ATTACHMENTS -- \"$TO\" <<< \"$BODY\""
|
||||
echo $SENDMAILCMD
|
||||
|
||||
mutt -e "set from=$FROM" -s "$SUBJECT" $ATTACHMENTS -- $TO <<< $BODY
|
||||
|
||||
**Script Output**
|
||||
|
||||
$ bash send_mail.sh
|
||||
*********************
|
||||
E-mail sending script.
|
||||
*********************
|
||||
|
||||
Enter the e-mail address you wish to send mail from:
|
||||
[Enter] test@gmail.com
|
||||
|
||||
Enter the e-mail address you wish to send mail to:
|
||||
[Enter] test@gmail.com
|
||||
|
||||
Enter e-mail subject:
|
||||
[Enter] Message subject
|
||||
|
||||
Provide the list of attachments. Separate names by space.
|
||||
If there are spaces in file name, quote file name with ".
|
||||
send_mail.sh
|
||||
|
||||
Attachments: send_mail.sh
|
||||
|
||||
Enter message. To mark the end of message type ;; in new line.
|
||||
This is a message
|
||||
text
|
||||
;;
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
There are many ways of send emails from command line / shell script but here we have shared 4 tools available for unix / linux based distros. Hope you enjoyed reading our article and please provide your valuable comments and also let us know if you know about any new tools.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-shell-script/send-email-subject-body-attachment-linux/
|
||||
|
||||
作者:[Bobbin Zachariah][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/bobbin/
|
@ -0,0 +1,78 @@
|
||||
How to Run GUI Apps in a Docker Container
|
||||
================================================================================
|
||||
Hi everyone, today we'll learn how we can run GUI Applications inside a [Docker][1] Container. We can easily run most of the common GUI apps without getting into trouble inside a Docker Container. Docker is an Open Source project that provides an open platform to pack, ship and run any application as a lightweight container. It has no boundaries of Language support, Frameworks or packaging system and can be run anywhere, anytime from a small home computers to high-end servers. It makes them great building blocks for deploying and scaling web apps, databases, and back-end services without depending on a particular stack or provider.
|
||||
|
||||
Here are the quick and easy steps on how we can run a GUI App in a Docker Container. In this tutorial, we'll take Firefox for the example.
|
||||
|
||||
### 1. Installing Docker ###
|
||||
|
||||
First of all, before we start, we must ensure that we have Docker installed in our host Linux Operating System. Here, we are running CentOS 7 as host so, we'll be running yum manager to install docker using the below command.
|
||||
|
||||
# yum install docker
|
||||
|
||||
![](http://blog.linoxide.com/wp-content/uploads/2015/03/installing-docker.png)
|
||||
|
||||
# systemctl restart docker.service
|
||||
|
||||
### 2. Creating Dockerfile ###
|
||||
|
||||
Now, as our Docker Daemon is running, we'll now prepare to create our Firefox Docker Container. We'll create a Dockerfile where we'll enter the required configuration to create a working Firefox Container. We'll fetch latest version of CentOS for our Docker Image. To do so, we'll create a file named Dockerfile using our favorite text editor.
|
||||
|
||||
# nano Dockerfile
|
||||
|
||||
Then, we'll add the following lines of configuration into Dockerfile and then save it.
|
||||
|
||||
#!/bin/bash
|
||||
FROM centos:7
|
||||
RUN yum install -y firefox
|
||||
# Replace 0 with your user / group id
|
||||
RUN export uid=0 gid=0
|
||||
RUN mkdir -p /home/developer
|
||||
RUN echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd
|
||||
RUN echo "developer:x:${uid}:" >> /etc/group
|
||||
RUN echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers
|
||||
RUN chmod 0440 /etc/sudoers
|
||||
RUN chown ${uid}:${gid} -R /home/developer
|
||||
|
||||
USER developer
|
||||
ENV HOME /home/developer
|
||||
CMD /usr/bin/firefox
|
||||
|
||||
![](http://blog.linoxide.com/wp-content/uploads/2015/03/Dockerfile-GUI.png)
|
||||
|
||||
**Note: Please replace 0 with your user and group id in 4th line of the configuration. We can get the uid and gid of current user by running the following command in a shell or a terminal.**
|
||||
|
||||
# id $USER
|
||||
|
||||
![](http://blog.linoxide.com/wp-content/uploads/2015/03/user-id.png)
|
||||
|
||||
### 3. Building Docker Container ###
|
||||
|
||||
We'll now build the container which will work according to the above Dockerfile. It will install firefox web browser and its required packages. It will then set user permission to make it work. Here, the image name is set as firefox, you can name it as your desire.
|
||||
|
||||
# docker build --rm -t firefox .
|
||||
|
||||
![](http://blog.linoxide.com/wp-content/uploads/2015/03/building-firefox-docker.png)
|
||||
|
||||
### 4. Running Docker Container ###
|
||||
|
||||
Now, finally, if everything went cool, we'll be able to run our GUI App ie Mozilla Firefox Browser from inside our firefox Docker Container running in a CentOS 7 Image.
|
||||
|
||||
# docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
Running GUI Apps in a Docker Container is really an awesome experience which will never harm/use your host Filesystem. It is fully dependent on your Docker Container. In this tutorial, we tried Firefox in our CentOS 7 Docker Image with Firefox installed. We can use many more GUI Apps with this technology. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents. Thank you ! Enjoy :-)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-how-to/run-gui-apps-docker-container/
|
||||
|
||||
作者:[Arun Pyasi][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/arunp/
|
||||
[1]:http://docker.io/
|
@ -0,0 +1,95 @@
|
||||
Install Inkscape - Open Source Vector Graphic Editor
|
||||
================================================================================
|
||||
Inkscape is an open source vector graphic editing tool which uses Scalable Vector Graphics (SVG) and that makes it different from its competitors like Xara X, Corel Draw and Adobe Illustrator etc. SVG is a widely-deployed royalty-free graphics format developed and maintained by the W3C SVG Working Group. It is a cross platform tool which runs fine on Linux, Windows and Mac OS.
|
||||
|
||||
Inkscape development was started in 2003, Inkscape's bug tracking system was hosted on Sourceforge initially but it was migrated to Launchpad afterwards. Its current latest stable version is 0.91. It is under continuous development and bug fixes and we will be reviewing its prominent features and installing process in the article.
|
||||
|
||||
### Salient Features ###
|
||||
|
||||
Lets review the outstanding features of this application categorically.
|
||||
|
||||
#### Creating Objects ####
|
||||
|
||||
- Drawing different colored sized and shaped freehand lines through pencil tool, straight lines and curves through Bezier (pen) tool, applying freehand calligraphic strokes through calligraphic tool etc
|
||||
- Creating, selecting, editing and formatting text through text tool. Manipulating text in plain text boxes, on paths or in shapes
|
||||
- Helps draw various shapes like rectangles, ellipses, circles, arcs, polygons, stars, spirals etc and then resize, rotate and modify (turn sharp edges round) them
|
||||
- Create and embed bitmaps with simple commands
|
||||
|
||||
#### Object manipulation ####
|
||||
|
||||
- Skewing, moving, scaling, rotating objects through interactive manipulations and pacifying the numeric values
|
||||
- Performing raising and lowering Z-order operations
|
||||
- Grouping and ungrouping objects to create a virtual scope for editing or manipulation
|
||||
- Layers form a hierarchal tree and can be locked or rearranged for various manipulations
|
||||
- Distribution and alignment commands
|
||||
|
||||
#### Fill and Stroke ####
|
||||
|
||||
- Copy/paste styles
|
||||
- Pick Color tool
|
||||
- Selecting colors on a continuous plot based on vectors of RGB, HSL, CMS, CMYK and color wheel
|
||||
- Gradient editor helps creating and managing multi-stop gradients
|
||||
- Define an image or selection and use it to pattern fill
|
||||
- Dashed Strokes can be used with few predefined dashed patterns
|
||||
- Beginning, middle and ending marks through path markers
|
||||
|
||||
#### Operation on Paths ####
|
||||
|
||||
- Node Editing: Moving nodes and Bezier handles, node alignment and distribution etc
|
||||
- Boolean operations like yes or no conditions
|
||||
- Simplifying paths with variable levels or thresholds
|
||||
- Path insetting and outsetting along with link and offset objects
|
||||
- Converting bitmap images into paths (color and monochrome paths) through path tracing
|
||||
|
||||
#### Text manipulation ####
|
||||
|
||||
- All installed outlined fonts can be used even for right to left align objects
|
||||
- Formatting text, letter spacing, line spacing or kerning
|
||||
- Text on path and on shapes where both text and path or shapes can be edited or modified
|
||||
|
||||
#### Rendering ####
|
||||
|
||||
- Inkscape fully support anti-aliased display which is a technique that reduces or eliminates aliasing by shading the pixels along the border.
|
||||
- Support for alpha transparency display and PNG export
|
||||
|
||||
### Install Inkscape on Ubuntu 14.04 and 14.10 ###
|
||||
|
||||
In order to install Inkscape on Ubuntu, we will need to first [add its stable Personal Package Archive][1] (PPA) to Advanced Package Tool (APT) repository. Launch the terminal and run following command to add its PPA.
|
||||
|
||||
sudo add-apt-repository ppa:inkscape.dev/stable
|
||||
|
||||
![PPA Inkscape](http://blog.linoxide.com/wp-content/uploads/2015/03/PPA-Inkscape.png)
|
||||
|
||||
Once the PPA has been added to the APT repository we need to update it using following command.
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
![Update APT](http://blog.linoxide.com/wp-content/uploads/2015/03/Update-APT2.png)
|
||||
|
||||
After updating the repository we are ready to install inkscape which is accomplished using the following command.
|
||||
|
||||
sudo apt-get install inkscape
|
||||
|
||||
![Install Inkscape](http://blog.linoxide.com/wp-content/uploads/2015/03/Install-Inkscape.png)
|
||||
|
||||
Congratulation, Inkscape has been installed now and all set for image editing and making full use of feature rich application.
|
||||
|
||||
![Inkscape Main](http://blog.linoxide.com/wp-content/uploads/2015/03/Inkscape-Main1.png)
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
Inkscape is a feature rich graphic editing tool which empowers its user with state of the art capabilities. It is an open source application which is freely available for installation and customizations and supports wide range of file formats including but not limited to JPEG, PNG, GIF and PDF. Visit its [official website][2] for more news and updates regarding this application.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/tools/install-inkscape-open-source-vector-graphic-editor/
|
||||
|
||||
作者:[Aun Raza][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/arunrz/
|
||||
[1]:https://launchpad.net/~inkscape.dev/+archive/ubuntu/stable
|
||||
[2]:https://inkscape.org/en/
|
Loading…
Reference in New Issue
Block a user