12月 222015
 
[root@backup data]# cat firewall.sh
#!/bin/bash
#
# Run everyday 04:00 for rsync by harveymei @201511251116
# Open TCP Port 873 and Restart IPTABLES

RuleNum=`service iptables status |grep dpt:873 |awk '{print $1}'`
iptables -R INPUT $RuleNum -p tcp --dport 873 -j ACCEPT
service iptables save; service iptables restart

echo "`date +%Y%m%d_%H:%M` OK" > /data/firewall

# Sleep 1 Hour for Rsync Transfer

sleep 30m;

# Close TCP Port 837 and Restart IPTABLES

RuleNum=`service iptables status |grep dpt:873 |awk '{print $1}'`
iptables -R INPUT $RuleNum -p tcp --dport 873 -j DROP
service iptables save; service iptables restart

echo "`date +%Y%m%d_%H:%M` FINISHED" >> /data/firewall

exit 0;

加入定时任务

[root@backup data]# cat /etc/crontab 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

0 4 * * * root /data/firewall.sh
[root@backup data]#

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据