check_axis.sh 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. box=$1
  3. port=$2
  4. usr=$3
  5. pass=$4
  6. if [ ! "$#" == "4" ]; then
  7. echo -e "\nYou did not supply enough command line arguments. \nUsage: ./check_axis.sh <host> <port> <username> <password> \n \nCheck_axis.sh checks the status of LPT ports on Axis print servers. \nIt was written by Tom De Blende (tom.deblende@village.uunet.be) in 2002. \n" && exit "3"
  8. fi
  9. tempfile=/tmp/status-$box.tmp
  10. exit="3"
  11. ftp -in $box &>/dev/null <<EOF
  12. user $usr $pass
  13. passive
  14. prompt off
  15. lcd /tmp
  16. ascii
  17. get status $tempfile
  18. EOF
  19. if [ ! -e "$tempfile" ]; then
  20. stdio="Status file could not be transferred from the Axis box." && rm -f $tempfile && echo $stdio && exit 2;
  21. fi
  22. lines=`cat $tempfile | grep -i $port`
  23. status=`echo $lines | awk '{ print $3 }'`
  24. if [ "$status" == "Printing" ]; then
  25. bytes=`echo $lines | awk '{ print $4 }'`;
  26. comments=`echo $lines | tr -d "
  27. " | awk '{ print $5 " " $6 }'`;
  28. else
  29. comments=`echo $lines | tr -d "
  30. " | awk '{ print $4 " " $5 }'`;
  31. fi
  32. comma=`echo $comments | grep , | wc -l`
  33. if [ "$comma" -eq "1" ]; then
  34. comments=`echo $comments | cut -d, -f1`
  35. fi
  36. if [ "$status" == "Available" ]; then
  37. if [ "$comments" == "Paper out" ]; then
  38. exit="1" && stdio="WARNING - Out of paper.";
  39. elif [ "$comments" == " " ]; then
  40. exit="0" && stdio="OK - Printer is available but returns no comments.";
  41. elif [ "$comments" == "No error" ]; then
  42. exit="0" && stdio="OK - No error.";
  43. elif [ "$comments" == "Ready " ]; then
  44. exit="0" && stdio="OK - Ready.";
  45. elif [ "$comments" == "Off line" ]; then
  46. exit="1" && stdio="WARNING - Printer is off line.";
  47. elif [ "$comments" == "Out of" ]; then
  48. exit="1" && stdio="WARNING - Out of paper.";
  49. elif [ "$comments" == "Busy Out" ]; then
  50. exit="1" && stdio="WARNING - Busy, out of paper.";
  51. elif [ "$comments" == "Printer off-line" ]; then
  52. exit="1" && stdio="WARNING - Printer is off line.";
  53. elif [ "$comments" == "Printer fault" ]; then
  54. exit="2" && stdio="CRITICAL - Printer fault.";
  55. else
  56. exit="3" && stdio="Comments: $comments";
  57. fi
  58. elif [ "$status" == "Printing" ]; then
  59. if [ "$comments" == "Printer busy" ]; then
  60. exit="0" && stdio="OK - PRINTING. Bytes printed: $bytes.";
  61. elif [ "$comments" == "No error" ]; then
  62. exit="0" && stdio="OK - PRINTING. Bytes printed: $bytes.";
  63. elif [ "$comments" == "Paper out" ]; then
  64. exit="1" && stdio="WARNING - PRINTING. Out of paper.";
  65. elif [ "$comments" == "Out of" ]; then
  66. exit="1" && stdio="WARNING - PRINTING. Out of paper. Bytes printed: $bytes.";
  67. elif [ "$comments" == "Busy Out" ]; then
  68. exit="1" && stdio="WARNING - Busy, out of paper.";
  69. elif [ "$comments" == "Ready " ]; then
  70. exit="0" && stdio="OK - PRINTING. Bytes printed: $bytes.";
  71. elif [ "$comments" == "Printer off-line" ]; then
  72. exit="1" && stdio="WARNING - PRINTING. Printer is off line.";
  73. elif [ "$comments" == "Busy " ]; then
  74. exit="0" && stdio="OK - PRINTING. Busy. Bytes printed: $bytes.";
  75. elif [ "$comments" == "Off line" ]; then
  76. exit="1" && stdio="WARNING - PRINTING. Printer is off line.";
  77. elif [ "$comments" == "Printer fault" ]; then
  78. exit="2" && stdio="CRITICAL - PRINTING. Printer fault. Bytes printed: $bytes.";
  79. else
  80. exit="3" && stdio="Comments: $comments.";
  81. fi
  82. fi
  83. rm -f $tempfile
  84. echo $stdio
  85. exit $exit