cat /tmp/Invoice_tmp.txt | grep -v "affected" | sort | awk '{print}' > /tmp/result.txt 去掉affected那行,排序, 将内容输出到result.txt
服务器之间复制文件:将本地的/var/tmp/cg35690/Invoice.txt 复制到另一个服务器的hdcicgcmola01d 的 这个path 下 /var/tmp/cg35690/
scp local file path id@remoteservername:remotepath
DEMO: scp /var/tmp/cg35690/Invoice.txt cg35690@hdcicgcmola01d:/var/tmp/cg35690/
InvoiceReport_Recon.csh
#!/bin/csh -f set TMPDIR = "/tmp" set PVD1 = "Invoice.txt" set num=`awk '/^$/{print NR}' $TMPDIR/$PVD1`#####以换行符为条件进行获取行号 set tmp=0 set LoopCnt = 0 echo "--------------------------------------" echo "Start to prepare test files: $TMPDIR/$PVD1" if (-e $TMPDIR/$PVD1) then echo "$TMPDIR/$PVD1 exist" echo "num is $num" foreach i ( $num ) @ LoopCnt += 1 echo "Start loop" if ($tmp == 0) then #sed -n '1,7p' $TMPDIR/$PVD1 > $TMPDIR/Invoice_tmp.txt ######打印1-7 行到文件 awk "NR>1 && NR<$i" $TMPDIR/$PVD1 > $TMPDIR/Invoice_tmp.txt ######打印1-i 行到文件 else #sed -n "${tmp},${i}p" $TMPDIR/$PVD1 > $TMPDIR/Invoice_tmp.txt ######打印tmp-i 行到文件 awk "NR>$tmp && NR<${i}" $TMPDIR/$PVD1 > $TMPDIR/Invoice_tmp.txt ######打印tmp-i 行 endif set tmp=${i} # cat /tmp/Invoice_tmp.txt | sed '/rows affected/d' | sort | awk '{print}' > $TMPDIR/Invoice${LoopCnt}.txt cp $TMPDIR/Invoice_tmp.txt $TMPDIR/Invoice${LoopCnt}.txt echo "i is ${i}, temp is $tmp,LoopCnt is ${LoopCnt}" end else echo "$TMPDIR/$PVD1 not exist" endif
SFTP 链接其他server进行文件传输 : sftp id@outservername
sftp newaska@hdcicgcmola01d << EOF cd /home/sb/newaska/share/bin put /home/sb/jesseq/uat/daily_tasks/filerecon/InvoiceReport_Recon.csh EOF
SSH 链接其他server 执行脚本
ssh -t -t newaska@hdcicgcmola01d << EOF chmod +x /home/sb/newaska/share/bin/InvoiceReport_Recon.csh /home/sb/newaska/share/bin/InvoiceReport_Recon.csh EOF