shell脚本

#!/bin/sh

ipaddress='192.168.1.215:80'
user='admin'
password='hik12345'

if [ $# -lt 1 ];then
    echo "usage:"
    echo $0" [api number]"
    echo -e "\n\napi number desc:"
    echo -e "\t1:get consume template"
    echo -e "\t2:enable consume template"
    echo -e "\t3:disable consume template"
    echo -e "\t4:get consume week plan"
    exit;
fi

function GetConsumeTemplate()
{
	curl  --digest -u ${user}":"${password} "http://"${ipaddress}"/ISAPI/Consume/modePlanTemplate/1?format=json"
	echo -e "\n"
}

function EnableTempalte()
{
        data='{"ModePlanTemplate": {"enabled": true,"templateName": "TemplateName1","weekPlanNo": 1,"holidayGroupNo": [1]}}'
	curl  --digest -u ${user}":"${password} -X "PUT" "http://"${ipaddress}"/ISAPI/Consume/modePlanTemplate/1?format=json" --header 'Content-Type: application/json' --data "${data}"
}

function DisableTempalte()
{
        data='{"ModePlanTemplate": {"enabled": false,"templateName": "TemplateName1","weekPlanNo": 1,"holidayGroupNo": [1]}}'
	curl  --digest -u ${user}":"${password} -X "PUT" "http://"${ipaddress}"/ISAPI/Consume/modePlanTemplate/1?format=json" --header 'Content-Type: application/json' --data "${data}"
}

function GetWeekPlan()
{
	curl  --digest -u ${user}":"${password} "http://"${ipaddress}"/ISAPI/Consume/modeWeekPlan/1?format=json"
	echo -e "\n"
}

cmd=$1

case ${cmd} in 
	1)
	GetConsumeTemplate
	;;
	2)
	EnableTempalte
	;;
	3)
	DisableTempalte
	;;
	4)
	GetWeekPlan
	;;
	*)
  	echo "not support api"
	;;
esac