2016年7月10日 星期日

Lab: 利用SCP指令來抓取其他Sensor的資料

i@f1:~$ cat scplog.sh
#!/bin/bash
for x in t01 sensor05 <宣兩個x, 可以用來抓五個sensor>
do
        echo $x: <呼叫x>
done

<結果>
pi@f1:~$ ./scplog.sh
t01:
sensor05:

pi@f1:~$ cat scplog.sh
#!/bin/bash
for x in sensor05 sensor04
do
        echo $x:
        scp -r pi@$x:~/log ~/log_$x
done


pi@f1:~$ . scplog.sh
sensor05:
2016-07-03_10-54-32_0000.log                    0%    0     0.0KB/s   --:--           2016-07-03_10-54-32_0000.log                   52%   80KB  80.0KB/s   00:00           2016-07-03_10-54-32_0000.log                  100%  151KB 151.1KB/s   00:01         
sensor04:
2016-07-03_10-54-19_0000.log                    0%    0     0.0KB/s   --:--           2016-07-03_10-54-19_0000.log                  100%  151KB 151.2KB/s   00:00   



pi@f1:~$ cat hgetxyz.sh
#!/bin/bash
echo head 30
head -30 $1 |cut -d',' -f 1,2,3,4

echo tail 50
tail -30 $1 |cut -d',' -f 1,2,3,4  <以","為依據,取3 4 欄>

<$1 is 參數filename, >

pi@f1:~$ ./hgetxyz.sh s5log
head 30
2016-07-03 14:17:18.096,0.00054785156250,0.00013671875000,-0.00119995117187
2016-07-03 14:17:18.196,-0.00180688476562,0.00102075195312,-0.00022705078125
2016-07-03 14:17:18.296,0.00166357421875,-0.00298144531250,-0.00257177734375
2016-07-03 14:17:18.396,0.00015454101563,0.00097290039062,0.00122583007813
2016-07-03 14:17:18.496,0.00027270507813,0.00037207031250,-0.00054589843750
2016-07-03 14:17:18.596,-0.00045556640625,0.00213696289062,-0.00403442382812


========================================================================
pi@f1:~$ free -mh <Check Memery free>
             total       used       free     shared    buffers     cached
Mem:          434M       107M       327M       4.4M        10M        66M
-/+ buffers/cache:        30M       403M
Swap:          99M         0B        99M
pi@f1:~$ free -mh | grep Mem:
Mem:          434M       107M       327M       4.4M        10M        66M


pi@f1:~$ free -mh | grep Mem: <只要看Memery的>
Mem:          434M       107M       327M       4.4M        10M        66M

pi@f1:~$ free -mh | grep Mem: | fmt -u <去空白>
Mem: 434M 113M 321M 4.4M 12M 66M

pi@f1:~$ free -mh | grep Mem: | fmt -u | cut -d' ' -f 3,4 <以空白為依據,取3 4 欄>
321M

<<Usage: cut OPTION... [FILE]...
Print selected parts of lines from each FILE to standard output.

Mandatory arguments to long options are mandatory for short options too.
  -b, --bytes=LIST        只顯示指定的位元組
  -c, --characters=LIST   只顯示指定的字元
  -d, --delimiter=DELIM   以 DELIM 字元代替 TAB 作為欄位的分隔符號
  -f, --fields=LIST       只顯示指定的欄位;同時也印出不含分隔符號的
                            每一行,除非配合 -s 選項一起使用>>

$ nano happy.sh
#!/bin/bash
echo $0
echo $1

pi@f1:~$ ./happy.sh test
./happy.sh
test
<pi@f1:~$ ./happy.sh=$0 test=$1 $2 $$4...etc>

========================================================================

pi@f1:~$ cat hget.sh
#!/bin/bash

[ "$2" == "x" ] && pos='2'
[ "$2" == "y" ] && pos='3'
[ "$2" == "z" ] && pos='4'

head -$3 $1 | cut -d',' -f $pos

hget.sh filename x, y or z 軸 看幾筆data

pi@f1:~$ ./hget.sh slog x 10
-0.00039184570312
-0.00317431640625
0.00247192382813
....



pi@f1:~$ head -100 slog | tail -10 <去頭尾,抓91-100筆data>
2016-07-03 10:54:48.798,-0.00109228515625,0.00207202148438,-0.00021655273438,0.02820610687023,-0.16757251908397,-0.00180916030534
2016-07-03 10:54:48.855,-0.00082885742188,-0.00034497070312,-0.00089819335938,-0.00667938931298,0.05465648854961,0.02148091603053
2016-07-03 10:54:48.913,0.00055859375000,-0.00090698242187,0.00018261718750,0.02339694656489,0.02916030534351,-0.01624427480916
2016-07-03 10:54:48.970,-0.00262988281250,-0.00032006835937,0.00132153320312,-0.01912977099237,0.00525954198473,-0.02438167938931
2016-07-03 10:54:49.027,-0.00198242187500,0.00033471679688,0.00016479492187,0.00329770992366,0.00109923664122,-0.13952671755725
2016-07-03 10:54:49.084,0.00193701171875,-0.00085595703125,0.00149121093750,-0.02974045801527,0.00515267175572,0.00488549618321
2016-07-03 10:54:49.142,-0.00072534179688,0.00158789062500,0.00089013671875,0.03358778625954,0.05039694656488,-0.00512213740458
2016-07-03 10:54:49.199,0.00189843750000,0.00152978515625,0.00553100585937,-0.02367938931298,0.16738931297709,0.03446564885496
2016-07-03 10:54:49.256,-0.00298730468750,0.00281347656250,-0.00112719726563,0.04851908396947,0.14975572519083,0.02287786259542
2016-07-03 10:54:49.313,-0.00017529296875,-0.00107983398437,0.00490942382812,-0.07195419847328,-0.01506106870230,0.03915267175572

========================================================================<20160710>

2016-07-10 11:17:51.429,-0.00079760742188,-0.00181811523437,0.00048510742189,0.0                                                                             6098473282445,-0.04567938931297,0.01094656488551
2016-07-10 11:17:51.527,0.00232592773437,-0.00061181640625,-0.00099560546873,0.0                                                                             2479389312979,0.02551145038169,0.01803053435116
^CTraceback (most recent call last): <Pause/Break Hold住>
  File "udpserver-31500.py", line 14, in <module>
KeyboardInterrupt
pi@f2:~$ python udpserver-31500.pyc <不能再run python>
2016-07-10 11:18:13.227,-0.00114746093750,0.00103979492188,0.00010009765627,0.02514503816796,-0.02649618320610,-0.00702290076334
2016-07-10 11:18:13.327,0.00427099609375,-0.00095947265625,-0.00217041015623,0.02548854961834,-0.01490076335877,-0.01181679389312
2016-07-10 11:18:13.427,0.00395996093750,0.00142041015625,-0.00017382812498,-0.02041984732823,0.07106106870230,0.02712213740459
2016-07-10 11:18:13.527,-0.00140039062500,0.00150683593750,-0.00091845703123,-0.02818320610685,0.00194656488550,0.03390076335879
2016-07-10 11:18:13.627,0.00058569335937,-0.00225341796875,-0.00426855468748,0.02360305343513,-0.04029007633587,-0.02203053435113
2016-07-10 11:18:13.727,0.00040820312500,0.00221728515625,0.00067846679689,0.03146564885498,0.03880916030535,0.07345038167940
2016-07-10 11:18:13.827,-0.00057128906250,-0.00056274414062,0.00236718750002,-0.05786259541983,0.01812213740459,0.01145801526719
2016-07-10 11:18:13.927,-0.00266284179688,-0.00056250000000,0.00105346679689,-0.01245801526716,-0.03738931297709,-0.04892366412212
2016-07-10 11:18:14.027,-0.00137426757813,-0.00089746093750,-0.00007177734373,-0.00997709923662,0.07964885496184,0.01810687022902
2016-07-10 11:18:14.127,-0.00000244140625,0.00146606445313,0.00356005859377,-0.01176335877861,-0.07436641221373,-0.00686259541983
2016-07-10 11:18:14.241,-0.00203076171875,-0.00160766601562,-0.00125390624998,-0.01373282442746,0.01701526717558,-0.02551908396945
2016-07-10 11:18:14.327,-0.00383081054688,0.00154394531250,0.00333105468752,0.00656488549620,-0.02378625954198,0.02474045801528
2016-07-10 11:18:14.427,0.00041870117187,-0.00128198242187,-0.00051879882811,-0.02067938931296,-0.02874045801526,0.00209160305345
2016-07-10 11:18:14.527,0.00194580078125,-0.00213330078125,-0.00163452148436,-0.01911450381677,0.04043511450382,-0.00919083969464
2016-07-10 11:18:14.627,-0.00011596679688,-0.00053417968750,-0.00098754882811,0.01910687022903,-0.04928244274808,0.03093129770994
2016-07-10 11:18:14.727,-0.00079785156250,-0.00130029296875,0.00090625000002,0.04080152671758,-0.00109160305343,-0.00676335877861
2016-07-10 11:18:14.827,0.00193798828125,0.00142358398438,-0.00251708984373,-0.03312977099235,0.04287022900764,-0.01983206106869
2016-07-10 11:18:14.927,0.00292260742187,0.00003540039063,-0.00014086914061,0.00106870229009,-0.02904580152671,-0.05447328244273
2016-07-10 11:18:15.027,-0.00287597656250,0.00041064453125,-0.00179418945311,-0.00735114503815,0.01086259541985,-0.00489312977098
2016-07-10 11:18:15.127,0.00320825195312,-0.00087524414062,0.00015112304689,-0.00666412213739,0.02646564885497,-0.01343511450380
2016-07-10 11:18:15.227,-0.00009814453125,-0.00151171875000,0.00049121093752,-0.00761068702288,-0.05738167938931,0.00277862595421
^Z
[1]+  Stopped                 python udpserver-31500.pyc
pi@f2:~$ python udpserver-31500.pyc
Traceback (most recent call last):
  File "udpserver-31500.py", line 11, in <module>
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
pi@f2:~$ fg <回到前景>

沒有留言:

張貼留言

check_systemv1.1

 check_systemv1.1.bat 可用於電腦資產盤點 @echo off REM 後續命令使用的是:UTF-8編碼 chcp 65001 echo ***Thanks for your cooperation*** echo ***感謝你的合作*** timeout 1...