Sendmail Linux Examples
Sendmail on the command line:
$ sendmail emailaddress write body of message CTRL-D
The CTRL-D is a end of message code for standard-in.
Example :
From: your-email@example.com
To: email@example.com
enter body of message
This message is missing a useful TO:line as well as a subject. To create these you need to create a file or use a script.
$ vim email.txt
date: todays-date // not required
to: user-email@example.com
subject: subject
from: your-email@example.com
Body of message goes here
Then call sendmail with that file as an input:
$ sendmail -t user-email@example.com < email.txt
Or you can use the -toption to to tell sendmail to read the header of the message to figure out who to send it to.
$ sendmail -t < mail.txt
This will process the To: and CC: lines for you and send the mail to the correct addresses.
Or call from a script:
#!/usr/bin/perl
use Time::localtime;
open (OUT,”|/usr/sbin/sendmail -t”);
print OUT “From: your-email\@domain.com\n”; ## don’t forget to escape the @
print(OUT “Date: “.ctime().”\n”);
print(OUT “To: $email\n”);
print(OUT “Subject: $subject\n”);
print(OUT “\n”);
print(OUT “$body\n”);
close(OUT);
Create tar and copy to another server using tar
Just a note
Code:
tar -cvf – test | ssh -l username domain.com “cd /home1/username && tar -xvf -”
Delete / remove old / order files in linux automatically
find /tmp/test -ctime +60 -delete
The above command will delete any files created over 60 days ago in the /tmp/test folder (and all subfolders).
You can add this to a cron job and it will be automatic daily, weekly, monthly
Kill and Logout Users From linux
Open a terminal, and then type the following commands.
Login as root su – or sudo su – and entering the root password. Type the skill command as below:
# w
to show who is log in to your system and then :
# skill -STOP -u username
The skill command sends a terminate command (or another specified signal) to a specified set of processes.
Task: Resume Halted User Called username
Send CONT single to user username, type the following command:
# skill -CONT -u username
Task: Kill and Logout a User Called username
You can send KILL single, type the following command:
# skill -KILL -u username
Task: Kill and Logout All Users
Tto kill and logout all users is as follows:
# skill -KILL -v /dev/pts/*
pkill command
To halt or stop a user called username, enter:
# pkill -STOP -u username
To resume a user called username, enter:
# pkill -CONT -u username
To kill all php-cgi process owned by username user, enter:
# pkill -KILL -u username php-cgi
How to search or find within a file in linux
type the below command and change the below criteria to suite to your search :
- find /ENTER/PATH -type f -print0 | xargs -0 grep -i ENTER_TEXT_TO_SEARCH