9/07/2018

Ubuntu :: Ubuntu Bash Shell Script Get Data From Other Server By ssh.

Ubuntu :: Ubuntu Bash Shell Script Get Data From Other Server By ssh.
1. Install sshpass สำหรับ Run คำสั่ง ssh แบบใส่รหัสในคำสั่ง
  1. apt-get install sshpass


2. ตัวอย่าง Code อ่านค่าพื้นที่ HDD สร้าง script.sh
  1. nano script.sh

Insert Code
  1. #!/bin/bash
  2. sshpass -p 'PASSWORD' ssh user@IPSERVER REMOTE 'df -h /dev/sda1 &> /home/sa/output.txt'

ได้ไฟล์ Text ไปใช้งานต่อ

3. อ่านขนาดไฟล์จากเครื่อง QNAP
  1. #!/bin/bash
  2. sshpass -p 'PASSWORD' ssh user@IP QNAP 'cd /share/CACHEDEV1_DATA/backup/; ls -lah *.gz > output.txt'

ได้ข้อมูลใน File Text ไปใช้งานต่อ

หรือตั้ง Crontab ที่ QNAP หรือ Server เครื่องอื่น ๆ ให้ส่งค่าไป
  1. #!/bin/bash
  2. Days=`date +%Y%m%d`;
  3.  
  4. cd /share/CACHEDEV1_DATA/backup/
  5. rm *output.txt
  6. ls -s -h *.gz > $Days.output.txt
  7. scp $Days.output.txt sa@192.168.2.101:/www/intranet/sci/CheckServer/
  8. mkdir $Days
  9. mv *.gz $Days


  1. crontab -e
  1. 0 6 * * * bash /share/CACHEDEV1_DATA/backup/CheckFile.sh


4. SCP จาก Qnap ไปที่ Intranet แบบไม่ต้องใส่รหัส Set authorized_keys
https://intranet.sci.com/blog.php?u=3&b=961
ทำที่ User admin ได้เลย แล้วเอาคีย์ของ adminไป authorized_keys ที่เครื่อง intranet

5. อ่านค่าและส่งค่าไฟล์ Text ไปที่เครื่อง Intranet เพื่อตัดหรือแบ่งนำเข้า PHPmyadmin
php อ่านค่า จาก txt แล้ว นำเข้า DB
  1. <?php
  2. ob_start();
  3. error_reporting (E_ALL ^ E_NOTICE);
  4. header("Cache-Control: no-cache, must-revalidate");
  5. ////////////////////////////////////////////////////
  6. define('IN_PHPBB', true);
  7. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../../';
  8. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  9. include($phpbb_root_path . 'common.' . $phpEx);
  10. ////////////////////////////////////////////////////
  11. // Start session management
  12. $user->session_begin();
  13. $auth->acl($user->data);
  14. $user->setup();
  15. ////////////////////////////////////////////////////
  16. include($phpbb_root_path ."sci/include/config.php");
  17. include($phpbb_root_path ."sci/include/db.php");
  18. include($phpbb_root_path ."sci/include/functions.php");
  19. ////////////////////////////////////////////////////
  20. $EmpID  = ldapEmpId($user->data['username']);
  21.  
  22. $myDB   = new MysqlDB($Host,$User,$Password,$DB,$ShowError);
  23. $SQL ="SELECT * FROM sci._employees ";
  24. $SQL.=" LEFT JOIN sci._positions ON sci._positions.PositionCode=sci._employees.PositionCode";
  25. $SQL.=" LEFT JOIN sci._sections ON sci._sections.SectionId=sci._positions.SectionId";
  26. $SQL.=" WHERE sci._employees.EmpID='".$EmpID."'";
  27. $NumRows    = $myDB->Query($SQL);
  28. $Row        = $myDB->GetRow();
  29.  
  30. $EmpSection = tis2utf8($Row["SectionCalled"]);
  31.  
  32. if($EmpSection != "งทส.") {  
  33.     echo js_alert(tis2utf8("Menu นี้เข้าใช้งานได้เฉพาะ งทส."));
  34.     echo js_close();
  35.     exit;
  36. }
  37. $DateFileName = date("Ymd");
  38. $DateNowInsert = date("Y-m-d");
  39. //Check File
  40. if($myFile = fopen($DateFileName.".output.txt", "r")) {
  41.  
  42.     //Output one line until end-of-file
  43.     while(!feof($myFile)) {
  44.         //echo fgets($myFile) . "<br>";
  45.         list($Size, $Name) = split(" ", trim(fgets($myFile)));   
  46.        echo $Size."::".$Name."<br>";
  47.        
  48.         if(preg_match('/alfresco_file/', $Name)) {  
  49.             echo "Alfresco File"."|".$Size."<br>";
  50.             $AlfrescoFile = $Size;
  51.         } elseif(preg_match('/alfresco_db/', $Name)){
  52.             echo "Alfresco DB"."|".$Size."<br>";   
  53.             $AlfrescoDB = $Size;
  54.         } elseif(preg_match('/Intranet_file/', $Name)){
  55.             echo "Intranet File"."|".$Size."<br>"; 
  56.             $IntranetFile = $Size;
  57.         } elseif(preg_match('/Intranet_db/', $Name)){
  58.             echo "Intranet DB"."|".$Size."<br>";   
  59.             $IntranetDB = $Size;
  60.         }            
  61.  
  62.         }//Close if.
  63.  
  64.     }//Close While.
  65.    
  66.     //Insert Data To Table
  67.     $SQL_UP = " INSERT INTO sci_CheckServer.CheckData (CheckDate ,AlfrescoFile, AlfrescoDB, IntranetFile, IntranetDB)";
  68.     $SQL_UP .= " VALUES ('$DateNowInsert', '$AlfrescoFile', '$AlfrescoDB', '$IntranetFile', '$IntranetDB')";
  69.     $myDB->Update(utf2tis($SQL_UP));
  70.                    
  71.     //Close open file.
  72.     //fclose($myfile);
  73.     //Delete File.
  74.            
  75. } else {
  76.     echo js_alert("Unable to open file!"); 
  77. }
  78.  
  79. ob_end_flush();
  80. ?>


6. Select ค่าจาก PHP แสดงหน้า Web ตามที่ต้องการ

Axapta :: Axapta Finde Onhand Of Item As Of Date

Axapta :: Axapta Finde Onhand Of Item As Of Date

  1.    InventSumFinancial      inventSumFinancial;
  2.     InventDimParm           inventDimParm;
  3.     InventDim               inventDim;
  4. ;
  5.  
  6.     //Set Dimensions.
  7.     inventDimParm.InventLocationIdFlag  =  NoYes::No;
  8.     inventDimParm.WMSLocationIdFlag     =  NoYes::No;
  9.     inventDimParm.WMSPalletIdFlag       =  NoYes::No;
  10.     inventDimParm.InventBatchIdFlag     =  NoYes::No;
  11.     inventDimParm.InventSerialIdFlag    =  NoYes::No;
  12.     inventDimParm.ConfigIdFlag          =  NoYes::No;
  13.     inventDimParm.ItemIdFlag            =  NoYes::No;
  14.     inventDimParm.ClosedFlag            =  NoYes::No;
  15.     inventDimParm.InventColorIdFlag     =  NoYes::No;
  16.     inventDimParm.InventSizeIdFlag      =  NoYes::No;
  17.  
  18. inventSumFinancial = new InventSumFinancial(str2date(strfmt("31/12/%1", YearText -1), 123), ItemIdSelect, inventDim, inventDimParm);
  19. info(inventSumFinancial.qty());

8/17/2018

Home Assistant :: Home Assistant Send Mail Gmail SMTP

Home Assistant :: Home Assistant Send Mail Gmail SMTP
1. Config configuration.yaml
  1. cd /home/homeassistant/.homeassistant
  1. nano configuration.yaml


2. Insert code notification and set Gmail user password
  1. notify:
  2.   - name: "SendMail"
  3.     platform: smtp
  4.     server: smtp.gmail.com
  5.     port: 587
  6.     timeout: 15
  7.     sender: scivalve.suwit@gmail.com
  8.     encryption: starttls
  9.     username: scivalve.suwit@gmail.com
  10.     password: Password Gmail
  11.     recipient:
  12.       - suwit.jph@gmail.com
  13.       - komkid@gmail.com
  14.       - seksan.kamt56@gmail.com
  15.     sender_name: My Home Assistant
  16.  


3. Test Send mail select service menu and select service we create on stab 2.
insert Service Data Optional And click CALL SERVICE check mail.
  1. {"message":"Test mail"}

4. Set Automation for send mail when track device ping down.
  1. nano automations.yaml

Add this code.
  1. - id: '1534491838266'
  2.   alias: CheckPingDown
  3.   trigger:
  4.   - entity_id: device_tracker.sonoff
  5.     platform: state
  6.   condition:
  7.   - after: '8:00'
  8.     before: '18:00'
  9.     condition: time
  10.   - condition: state
  11.     entity_id: device_tracker.sonoff
  12.     state: not_home
  13.   action:
  14.   - data:
  15.       message: Can't connect sonoff Garden. Please Check WIFI Or Sonoff.
  16.     service: notify.sendmail


https://www.home-assistant.io/components/notify.smtp/

Firefox :: Firefox ถามรหัส Proxy บ่อย ๆ

Firefox :: Firefox ถามรหัส Proxy บ่อย ๆ ใส่ไปแล้วสักพักขึ้นมาถามอีก ทั้ง ๆ ที่ใส่ Username และ Password ถูก
https://kb.globalscape.com/KnowledgebaseArticle10522.aspx

Firefox repeatedly prompts for proxy authentication

THE INFORMATION IN THIS ARTICLE APPLIES TO:
EFT Server (All versions)

SYMPTOM
When using Firefox through an ISA server, Firefox repeatedly prompts for proxy authentication, even though the correct credentials have been entered and applied.

RESOLUTION

To resolve this issue:

1. Open Firefox.
2. In the address bar, type about:config. A warning appears.

3. Click I'll be careful. I promise! A variety of configuration options appears.
4. In the Filter box, type network.negotiate.
5. Double-click network.negotiate-auth.allow-proxies to toggle between true and false. The option must be set to false. (It seems counterintuitive, but you set it to false to make it work with the ISA proxy.)

6. Click the Home icon to close the configuration window.

Pi-Hole :: Pi-hole Update Version

Pi-Hole :: Pi-hole Update Version
1. Back Up Snapshots On Vmware
2. Run Command
  1. pihole -up