LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 720|回复: 4

请教大家一个shell中的流程问题

[复制链接]
发表于 2010-6-16 12:30:22 | 显示全部楼层 |阅读模式
我需要定期使用curl判断我的服务器的状态:


  1. curl -w "%{http_code}"  http://www.myserver.com/ | grep -o 200$ | wc -l
复制代码


如果正常就返回1,如果不正常,就返回0

请问我怎样把这个加入到一个if-else-fi中去,如果正常的时候,不进行操作,如果不正常,就发一封邮件给我。

主要想知道怎么使用一个命令的结果,作为另一个if中的条件。

谢谢!

我查了很多资料,可能是基础不好,还没搞明白,希望大侠们指教。因为很紧急

祝论坛上的朋友们端午节快乐!
 楼主| 发表于 2010-6-16 13:09:37 | 显示全部楼层

  1.   if [ $(curl -w "%{http_code}"  http://wwwserver.com/ | grep -o 200$ | wc -l) -gt 0 ]
  2.   then
  3.     echo "success"
  4.   else
  5.     echo "fail"
  6.   fi       
复制代码


呵呵,终于解决了,不知道大家有没有更好的方法
回复 支持 反对

使用道具 举报

发表于 2010-6-17 12:50:25 | 显示全部楼层
curl -w "%{http_code}"  http://wwwserver.com/ | grep -o 200$ | wc -l && echo 'success' || echo 'fail'
回复 支持 反对

使用道具 举报

发表于 2010-6-19 10:08:31 | 显示全部楼层
The Battered-Body Trick
  This is a story from Three Kingdoms that happened before the Battle of Chibi. One night, Zhou Yu was thinking hard in his tent about how to defeat Cao Cao's army, when Huang Gai came in . He suggested attacking with fire. “Well, it's exactly what I mean to do.” Said Zhou Yu. “That's why I'm keeping those two spies: to convey false information to Cao's camp. But I need a man to play the same game for us.” Huang Gai said he was willing to do it. They decided to carry out the trick of being flogged to win the enemy's confidence.
replica sunglasses,
  the next day Zhou Yu convened a general assembly of his commanders outside his tent.replica sunglasses He ordered the commanders to take three months's rations and prepare to defend their line. Huang Gai came forward and said: “We don't need three months. If not, we'd better throw down our weapons and sue for peace.”
aoc gold,
  Zhou Yu exploded in fury.aoc gold “Ibear our lord's mandate,” he cried, “to lead our troops to destroy Cao Cao. How dare you weaken our morale? Remove him and execute him!”
  Huang Gai proudly, “I have served the Southland through three successive reigns. Where do the likes of you come from?”
age of conan power leveling,
  the entire assembly got on their knees to intercede for Huang Gai.age of conan power leveling Zhou Yu said at last: “In consideration for the commanders' views, I shall not kill you. Give him one hundred strokes across the back!”
aion gold,
  Huang Gai was forced facedown to the ground. Not yet at fifty blows of the rod,aion gold his skin was broken and his oozing flesh was crossed with welts. He fainted several times.
maple story mesos,
  Zhou Yu let Kan Ze,maple story mesos Huang Gai's friend, to deliver the letter of surrender to Cao Cao, which Huang Gai had prepared. Before long, Cao Cao received a letter from the two spies, saying “Look for a boat with a blue-GREen flag at the bow. That will be Huang Gai.” In Huang Gai's boat there were combustibles. In this way, Huang Gai was able to set fire to Cao Cao's camp. When the red current of fire passed through the surface of the river, Cao Cao's ships, linked with chains,dog clothes turned into ashes.
dog clothes,
回复 支持 反对

使用道具 举报

发表于 2010-6-21 14:36:14 | 显示全部楼层
弱弱的文句 ”grep -o 200$“

200后面的$是干什么用的?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表