shell_scripts.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. case "$1" in
  3. mkrcdir)
  4. mkdir -p /var/spool/asterisk/monitor/${2}
  5. mkdir -p /var/spool/asterisk/monitor/${2}/${3}
  6. ;;
  7. sysinfo)
  8. #waninfo=`/usr/bin/ifconfig eth0`
  9. wanip=`/usr/bin/ifconfig eth0 | grep 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
  10. wanmac=`/usr/bin/ifconfig eth0 | grep 'HWaddr' | awk '{print $5}'|tr '[a-f]' '[A-Z]'`
  11. #laninfo=`/usr/bin/ifconfig eth1`
  12. lanip=`/usr/bin/ifconfig eth1 | grep 'inet addr:'| cut -d: -f2 | awk '{print $1}'`
  13. lanmac=`/usr/bin/ifconfig eth1 | grep 'HWaddr' | awk '{print $5}'|tr '[a-f]' '[A-Z]'`
  14. uptime=`uptime`
  15. if [ -z "`echo $uptime | grep 'day'`" ];then
  16. uptime=`echo $uptime | cut -d, -f1|awk '{print $3,$4}'`
  17. else
  18. uptime=`echo $uptime | cut -d, -f1,2|awk '{print $3,$4,$5,$6}'`
  19. fi
  20. echo "{\"wanip\":\"$wanip\", \"wanmac\":\"$wanmac\",\"lanip\":\"$lanip\",\"lanmac\":\"$lanmac\",\"uptime\":\"$uptime\"}"
  21. ;;
  22. handleinfo)
  23. ###CPUinfo
  24. CPULOG_1=$(awk '/cpu /{print $2" "$3" "$4" "$5" "$6" "$7" "$8}' /proc/stat)
  25. SYS_IDLE_1=$(echo $CPULOG_1 | awk '{print $4}')
  26. Total_1=$(echo $CPULOG_1 | awk '{print $1+$2+$3+$4+$5+$6+$7}')
  27. sleep 3
  28. CPULOG_2=$(awk '/cpu /{print $2" "$3" "$4" "$5" "$6" "$7" "$8}' /proc/stat)
  29. SYS_IDLE_2=$(echo $CPULOG_2 | awk '{print $4}')
  30. Total_2=$(echo $CPULOG_2 | awk '{print $1+$2+$3+$4+$5+$6+$7}')
  31. SYS_IDLE=`expr $SYS_IDLE_2 - $SYS_IDLE_1`
  32. Total=`expr $Total_2 - $Total_1`
  33. Used=`expr $Total - $SYS_IDLE`
  34. ###MEMinfo
  35. memtotal=`cat /proc/meminfo|grep MemTotal|awk '{print $2}'`
  36. memfree=`cat /proc/meminfo|grep MemAvailable|awk '{print $2}'`
  37. memused=`expr $memtotal - $memfree`
  38. ###system time
  39. currenttime=`date "+%s"`
  40. echo "{\"cputotal\":\"$Total\", \"cpuused\":\"$Used\",\"memtotal\":\"$memtotal\",\"memused\":\"$memused\",\"currenttime\":\"$currenttime\"}"
  41. ;;
  42. esac