Another imagination:
You have 100 servers.Now you’ve got a task.The boss needs to create a directory under /root and put some files under it.
What would you do next?Just be honestly and sincerely and start log in ssh then use mkdir to create directory,then use sftp or even ftp to put the files under the directory?
That would tire you so much,sour you hands and mind.Now let one line bash shell script to help you.
Here goes the general idea about the solution:
1.Write a bash script with multiple parameters.Each two of the parameters match the ip address and password to your ssh root account.
2.Now the script runs.It auto get the two parameters as a pair,and use expect to auto answer to interactive output of ssh command(‘yes’ to ‘Are you sure you want to continue connecting (yes/no)?’,and your password parameter to ‘[email protected]’s password:’).
3.After log in the remote server using ssh,the script download a script from url you designate.Like http://yourblog.com/mkdir_and_put_files_in_it.sh.After the download,use ‘sh ./mkdir_and_put_files_in_it.sh’ to run it which has command ‘mkdir’ and ftp get in it. Read more…
Imagine you have control over 10 mail servers(postfix or qmail,or sendmail if you prefer).Now you want to know the mail servers’ status by getting their unsent mail lists.
You may log in the ssh client,and use command ‘mailq’ or ‘qmail-qstat’ to respectively see the status of postfix and qmail.Two times a day,logging into the server tires you so much.Is there anything better you can do to relieve you out of this boring manually typing the very same words?
Definitely,yes.Use cron to take over this and free you. Read more…
The so called multi-processing,means at the very same moment,multi processes are handled by the cpu.In bash shell and other shells(ksh,csh,etc.),mark & has a special simulation of multi-processing except for the widely known running background feature.The below shell snippets is an example for a explanation purpose.It’s very funny,try it!(file name as if.sh and use sh if.sh to run it)
#!/bin/bash #multi-processing
for ((i=0;i<5;i++));do
{
sleep 3;echo 1>>aa && echo “done!”
#you may of course use other more complicated operations here
} &
done
wait
cat aa|wc -l
rm aa
Ok.Now let’s use time command to test the execution time of the script:
time bash if.sh
done!
done!
done!
done!
done!
5
real 0m3.108s #here,5 loop of `sleep 3` costs 3 and some little more time
user 0m0.056s
sys 0m0.092s
What about we ignore the & ?Let’s just try it! Read more…
1.telnet to send mail from command line
telnet xxx.xxx.xxx.xxx 25 #xxx.xxx.xxx.xxx stands for your mail server ip,same of the rest of the article
ehlo localhost
AUTH LOGIN #here we assume that account of your mail is [email protected],password iloveyou
c2VydmljZUB5b3VyZG9tYWluLnRsZA== #After the server has responded,type in the encoded username by base64 arithmetic.Method:echo -n ‘[email protected]’|base64
aWxvdmV5b3U= #type in the encoded password by base64 arithmetic.Method:echo -n ‘iloveyou’|base64
mail from: username #if username here has space,using quotation marks to enclose it,like “user name”
rcpt to: [email protected] #receiver
data
Subjet: My first mail on Postfix
Hi,
Are you there?
regards,
Admin
.
quit
OK!Now the customer of yours is expected to get your mail.(If not,please check your mail server’s configurations,such as whether your mail server has a reverse DNS,and your mail server cannot be a open relay MTA,for many MTA refuse to receive letter from a open relay MTA.)
2.telnet to receive & read mail from command line Read more…
The needs as follows:
1.rotate the apache and nginx log files(access log,error log),by day and compress the log file;
2.keep last 5 days’ log files,the others throw away automatically;
3.using the date as the suffix of the log file.
The implementation as follows:
In apache:
#/bin/bash
#by doxer.org
echo -E ‘/usr/local/httpd/logs/*.log {
daily
rotate 5
compress
notifempty
dateext
lastaction
/usr/local/httpd/bin/apachectl -k graceful
endscript
}’ > /etc/logrotate.d/httpd_log
/etc/init.d/crond restart
In nginx: Read more…
First of all,modify /etc/postfix/main.cf ,append the following line to the end of it:
header_checks = regexp:/etc/postfix/header_checks
body_checks = regexp:/etc/postfix/body_checks
To add an item to the blacklist:
For example,you want to filter away coming mails that contain words ‘A funny game’ in the subject,and to reject the mail to the sender,then do as the follows:
Type in /etc/postfix/header_checks:
/^Subject:.*A funny game/ REJECT drop header deny
List of actions:
REJECT : return the mail to the sender;
WARN : receive the letter,and log the information of the matter;
DISCARD : discard the mail,and give no reflection to the sender.
Then,using postmap to test the configuration:
postmap -q – regexp:/etc/postfix/header_checks < /etc/postfix/header_checks
Then reload postfix if no errors prompts:
postfix reload
To test the theory,I send a mail using my gmail account,in which the subject of the mail is ‘anotherhi,A funny game’.If it works,the mail should be rejected by the mail server.After I’ve sent the mail,I can get the response of the mail server:
tail -f /var/log/mail.info:
Oct 21 04:52:14 newserver6484 postfix/smtpd[27138]: connect from mail-qy0-f170.google.com[209.85.216.170]
Oct 21 04:52:15 newserver6484 postfix/smtpd[27138]: 0B8077529A5: client=mail-qy0-f170.google.com[209.85.216.170]
Oct 21 04:52:15 newserver6484 postfix/cleanup[27142]: 0B8077529A5: reject: header Subject: anotherhi,A funny game from mail-qy0-f170.google.com[209.85.216.170]; from= to= proto=ESMTP helo=: 5.7.1 drop header deny
#notice here,the mail is rejected by the mail server
Oct 21 04:52:15 newserver6484 postfix/smtpd[27138]: disconnect from mail-qy0-f170.google.com[209.85.216.170]
In my gmail account,I get a undelivered mail report as follows:
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 550 550 5.7.1 drop header deny (state 18).
#notice the phrase here :’drop header deny’.
OK,success!Next we’re going to add an item to the whitelist.
To add an item into the whitelist:
1.modify /etc/postfix/main.cf
Locate ‘smtpd_recipient_restrictions’ and type in the following content next to it:
check_recipient_access hash:/etc/postfix/to_white_list, #don’t lose the comma
Then :
touch /etc/postfix/to_white_list
The content of the file to_white_list is the items of your whitelist,for example:
[email protected] OK
2.postmap /etc/postfix/to_white_list
postfix reload
After the above operations,[email protected] is then OK to send mail to your mail server.