Regularly obtain screenshots of the target machine in CentOS

Source: Internet
Author: User

Regularly obtain the screen of the target machine in CentOS

1. Add a scheduled task

Crontab-l

[Plain] view plaincopy
  1. */1 ***** sh/home/aaron/run. sh>/home/aaron/cron. log2> & 1

2. cat/home/aaron/run. sh

[Plain] view plaincopy
  1. #! /Bin/sh
  2. # Cd/home/aaron
  3. # CLASSPATH = $ CLASSPATH:/home/aaron/. gradle/cache/com. google. zxing/core/jars/core-3.2.1.jar
  4. # CLASSPATH = $ CLASSPATH:/home/aaron/. gradle/cache/com. google. zxing/javase/jars/javase-3.2.1.jar
  5. # CLASSPATH = $ CLASSPATH:/home/aaron/. gradle/cache/commons-lang/jars/commons-lang-2.6.jar
  6. # CLASSPATH = $ CLASSPATH:/home/aaron/. gradle/cache/joda-time/jars/joda-time-1.6.2.jar
  7. # ExportCLASSPATH
  8. # ExportDISPLAY =: 0
  9. # Java =/home/aaron/soft/jdk1.8.0/bin/java
  10. # $ Javacom/aaron/my/resources/Test
  11. ImageDir =/tmp/images
  12. Pre_check (){
  13. If [! -D "$ imageDir"]; then
  14. Mkdir-p "$ imageDir"
  15. Fi
  16. }
  17. Pre_check
  18. # CommandStr = "/tmp/tool/client. sh; cd $ imageDir; ls"
  19. # Destination ssh host $ commandStr> t.txt
  20. #Forxin((catt.txt)
  21. # Do
  22. # Scpuser @ host:/tmp/images/$ x/tmp/images
  23. # Ssh target host "rm $ imageDir/$ x"
  24. # Done

3. Place the following information on the target machine

Cat/tmp/tool/client. sh

[Plain] view plaincopy
  1. #! /Bin/sh
  2. ImageDir =/tmp/images
  3. BaseDir =$ (cd $ (dirname $0); pwd)
  4. Pre_check (){
  5. If [! -D "$ imageDir"]; then
  6. Mkdir-p "$ imageDir"
  7. Fi
  8. }
  9. Pre_check
  10. CLASSPATH = $ CLASSPATH: $ baseDir/core-3.2.1.jar
  11. CLASSPATH = $ CLASSPATH: $ baseDir/javase-3.2.1.jar
  12. CLASSPATH = $ CLASSPATH: $ baseDir/commons-lang-2.6.jar
  13. CLASSPATH = $ CLASSPATH: $ baseDir/joda-time-1.6.2.jar
  14. ExportCLASSPATH
  15. ExportDISPLAY =: 0
  16. Cd $ baseDir
  17. Java =/home/aaron/soft/jdk1.8.0/bin/java
  18. $ Javacom/aaron/my/resources/Test

For cat Test. java, refer to the snapshot method.

[Java] view plaincopy
  1. Packagecom. aaron. my. resources;
  2. Importjava. awt .*;
  3. Importjava. awt. Dimension;
  4. Importjava. awt. image. BufferedImage;
  5. Importjava. io. File;
  6. Importjava. io. IOException;
  7. Importjava. nio. file. FileSystems;
  8. Importjava. nio. file. Path;
  9. Importjava. util. HashMap;
  10. Importjava. util. Map;
  11. Importjavax. imageio. ImageIO;
  12. Importcom. google. gson. Gson;
  13. Importcom. google. zxing .*;
  14. Importcom. google. zxing. client. j2se. BufferedImageLuminanceSource;
  15. Importcom. google. zxing. client. j2se. MatrixToImageWriter;
  16. Importcom. google. zxing. common. BitMatrix;
  17. Importcom. google. zxing. common. HybridBinarizer;
  18. Importorg. apache. commons. codec. binary. Base64;
  19. Importorg. apache. commons. lang. StringUtils;
  20. Importorg. joda. time. DateTime;
  21. PublicclassTest {
  22. PrivatestaticfinalStringfromDir = "/tmp/images ";
  23. PrivatestaticfinalStringtoDir = "/mnt/shared/processedQRCodes ";
  24. PrivatestaticfinalStringPNG = ". png ";
  25. PrivatestaticfinalintPNG_SIZE_HEIGHT = 200;
  26. PrivatestaticfinalintPNG_SIZE_WIDTH = 200;
  27. Publicstaticvoidmain (String [] args ){
  28. Snapshot ();
  29. // Filedir = newFile (fromDir );
  30. // If (dir. exists () & dir. isDirectory ()){
  31. // File [] files = dir. listFiles ();
  32. // For (Filef: files ){
  33. // If (f. isFile () & f. getName (). toLowerCase (). endsWith (PNG )){
  34. // Stringres = decode (f );
  35. /// System. out. println (res );
  36. // If (StringUtils. isNotBlank (res )){
  37. //// Movetoprocesseddir
  38. // Booleanmoved = move (f, newFile (toDir + File. separator + f. getName (). substring (0, f. getName (). indexOf (". ") +" _ "+ res + PNG ));
  39. // System. out. println (moved = true? "Movedtoprocesseddir.": "Can 'tmovefile:" + f. getAbsolutePath ());
  40. //}
  41. //}
  42. //}
  43. //}
  44. Stringres = decode (newFile ("/mnt/shared/qrcodes/B .png "));
  45. // Encode ("http://baike.baidu.com/link? Url = BP7l08ZZZa7HBLL0g4RCuVsN3BlNbuokYRKCuUk8ZexPDjxSVNMXQq_08WI1xz5EUAjVrce4qgSisos9K-mq-q ");
  46. }
  47. Privatestaticbooleanmove (Filef, FiletoDir ){
  48. Returnf. renameTo (toDir );
  49. }
  50. /**
  51. * Parse Images
  52. */
  53. PublicstaticStringdecode (Filefile ){
  54. BufferedImageimage;
  55. Stringres = null;
  56. Try {
  57. Image = ImageIO. read (file );
  58. LuminanceSourcesource = newBufferedImageLuminanceSource (image );
  59. Binarizerbinarizer = newHybridBinarizer (source );
  60. BinaryBitmapbinaryBitmap = newBinaryBitmap (binarizer );
  61. Map <DecodeHintType, Object> hints = newHashMap <DecodeHintType, Object> ();
  62. // Hints. put (DecodeHintType. CHARACTER_SET, "UTF-8 ");
  63. Resultresult = newMultiFormatReader (). decode (binaryBitmap, hints); // decode the image
  64. StringresultStr = result. getText ();
  65. // System. out. println (resultStr );
  66. Stringt = resultStr. substring (resultStr. indexOf ("? ") + 3, resultStr. length ());
  67. Stringbase64 = newString (Base64.decodeBase64 (t ));
  68. // System. out. println (t );
  69. System. out. print (base64 + "---> ");
  70. DecodeResultdecodeResult = newGson (). fromJson (base64, DecodeResult. class );
  71. Res = decodeResult. getD ();
  72. } Catch (effectione ){
  73. // Movetoprocesseddir
  74. Booleanmoved = move (file, newFile (toDir + File. separator + file. getName (). substring (0, file. getName (). indexOf (". ") + (res = null? "": "_" + Res) + PNG ));
  75. System. out. println (moved = true? "Exceptionhappenedandmovedtoprocesseddir.": "Can 'tmovefile:" + file. getAbsolutePath ());
  76. // E. printStackTrace ();
  77. }
  78. Returnres;
  79. }
  80. Publicstaticvoidsnapshot (){
  81. StringfileName = newDateTime (). toString ("yyyyMMddHHmmss ");
  82. Dimensionscreensize = Toolkit. getdefatooltoolkit (). getScreenSize ();
  83. Doubleh = screensize. getHeight ();
  84. Doublew = screensize. getWidth ();
  85. Try {
  86. Robotrobot = newRobot ();
  87. // BufferedImagebi = robot. createScreenCapture (newRectangle (Double. valueOf (w-PNG_SIZE_WIDTH)/2 ). intValue (), Double. valueOf (h-PNG_SIZE_HEIGHT)/2 ). intValue (), PNG_SIZE_WIDTH, PNG_SIZE_HEIGHT); // capture the screen according to the specified area
  88. BufferedImagebi = robot. createScreenCapture (newRectangle (screensize); // capture the Screen Based on the specified area
  89. ImageIO. write (bi, "png", newFile (fromDir + File. separator + fileName + PNG ));
  90. } Catch (AWTExceptione ){
  91. E. printStackTrace ();
  92. } Catch (io1_tione ){
  93. E. printStackTrace ();
  94. }
  95. }
  96. Publicstaticvoidencode (Stringcontent ){
  97. Intwidth = 400; // Image Width
  98. Intheight = 400; // Image Height
  99. Stringformat = "png"; // image type
  100. Map <EncodeHintType, Object> hints = newHashMap <EncodeHintType, Object> ();
  101. Hints. put (EncodeHintType. CHARACTER_SET, "UTF-8 ");
  102. Try {
  103. BitMatrixbitMatrix = newMultiFormatWriter (). encode (content,
  104. BarcodeFormat. QR_CODE, width, height, hints); // generate a Matrix
  105. Pathpath = FileSystems. getDefault (). getPath (toDir, "code.png ");
  106. MatrixToImageWriter. writeToPath (bitMatrix, format, path); // output the image
  107. } Catch (effectione ){
  108. E. printStackTrace ();
  109. }
  110. }
  111. }
  112. ClassDecodeResult {
  113. PrivateStringa;
  114. PrivateStringb;
  115. PrivateStringc;
  116. PrivateStringd;
  117. PrivateStringv;
  118. PublicStringgetA (){
  119. Returna;
  120. }
  121. PublicvoidsetA (Stringa ){
  122. This. a =;
  123. }
  124. PublicStringgetB (){
  125. Returnb;
  126. }
  127. PublicvoidsetB (Stringb ){
  128. This. B = B;
  129. }
  130. PublicStringgetC (){
  131. Returnc;
  132. }
  133. PublicvoidsetC (Stringc ){
  134. This. c = c;
  135. }
  136. PublicStringgetD (){
  137. Returnd;
  138. }
  139. PublicvoidsetD (Stringd ){
  140. This. d = d;
  141. }
  142. PublicStringgetV (){
  143. Returnv;
  144. }
  145. PublicvoidsetV (Stringv ){
  146. This. v = v;
  147. }
  148. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.