IBM supervessel power云平台 之 crontab定时任务篇,supervesselcrontab


声明 : 此文档只做学习交流使用,请勿用作其他商业用途
author : 朝阳_tony
E-mail : linzhaolover@163.com
Create Date: 2015-3-10 23:09:52 Tuesday
Last Change: 2015-3-11 00:02:37 Wednesday
转载请注明出处:http://blog.csdn.net/linzhaolover

摘要

朝弟,为了测试网络性能,我们需要每个小时测试一次,然后是将测试数据保存下来下来,回头分析一下

程序测试平台
IBM supervessel power云平台 https://ptopenlab.com/cloudlab/index.html

目录

      • 摘要
      • 目录
      • 准备工具
        • contab
        • ping
        • testsh
      • 运行结果
      • 总结

准备工具

contab

说到linux下的定时任务,第一个想到的应该就是它了

$> cat /etc/crontab

# 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

每分,每小时,每日,每月,每星期, 运行的命令
假设每周1到周5,每小时运行一次程序,那么就这样写,

#编辑配置文件
vim mycrontab.conf
0 */1 * * 1-5 /root/test.sh >> /tmp/test.log  2>&1

#导入配置到crontab服务
crontab mycrontab.conf

#查看
crontab -l
0 */1 * * 1-5 /root/test.sh >> /tmp/test.log  2>&1

注意 crontab 中一定要写全路径,否则执行的时候会报错

ping

网络连通测试,就用ping,用它看看是否能够ping通我在IBM supervessel power云平台申请的虚拟机172.16.10.110

test.sh

#!/bin/bash
function vpnc_connect()
{
    /usr/sbin/vpnc-connect  /etc/vpnc/Power_vpn.conf
    if [ $? != 0 ];then
        echo "vpn auto connect failed!"
        exit 1
    fi
}

function pingtest ()
{
    ip=$1
    ping $ip  -c 2  -w 5
    if [ $? != 0 ];then
        echo " test ping $ip error"
    else
        echo "test ping $ip OK"
    fi
}

###start here###
vpnc_connect
sleep 1  
pingtest 172.16.10.110
/usr/sbin/vpnc-disconnect

echo "Done"

运行结果

~# cat /tmp/test.log
VPNC started in background (pid: 26251)...
PING 172.16.10.110 (172.16.10.110) 56(84) bytes of data.
64 bytes from 172.16.10.110: icmp_seq=1 ttl=62 time=9.62 ms
64 bytes from 172.16.10.110: icmp_seq=2 ttl=62 time=8.15 ms

--- 172.16.10.110 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 8.155/8.889/9.623/0.734 ms
 test ping 172.16.10.110 OK
Terminating vpnc daemon (pid: 26251)
Done

总结:

简单而重复的工作就让机器去做吧;睡觉、睡觉……(~﹃~)~zZ

相关内容