7 changed files with 184 additions and 10 deletions
@ -0,0 +1,46 @@ |
|||||
|
#! /bin/bash |
||||
|
# 监视目录 |
||||
|
webroot="/root/demo" |
||||
|
|
||||
|
|
||||
|
cp /dev/null rsync_file |
||||
|
# 判断是否存在 |
||||
|
if [ !-f file.x01 ];then |
||||
|
find $webroot -type f -exec md5sum {} \; >>file.x01 |
||||
|
else |
||||
|
# 新文件 |
||||
|
for newfile in $(find $webroot -type f) |
||||
|
do |
||||
|
grep $newfile file.x01 >/dev/null 2>&1 |
||||
|
if [ $? -gt 0 ];then |
||||
|
mdval = $(md5sum $newfile) |
||||
|
# mdval = md5sum $newfile >> file.md5 |
||||
|
# 拼装POST json |
||||
|
# ret = curl --location 'http://192.168.66.180/api/notify' --header 'Content-Type:application/json' -data '{"filename":"$newfile","filehash":"$mdval"}' |
||||
|
|
||||
|
# echo "$newfile" |
||||
|
echo "$ret\r\n" |
||||
|
fi |
||||
|
done |
||||
|
fi |
||||
|
|
||||
|
|
||||
|
#!/bin/bash |
||||
|
|
||||
|
A="a a" |
||||
|
B="bb" |
||||
|
|
||||
|
read -r -d '' PAYLOAD <<-EOM |
||||
|
{ |
||||
|
"A": "${A}", |
||||
|
"B": "${B}" |
||||
|
} |
||||
|
EOM |
||||
|
|
||||
|
#PAYLOAD=$(echo $PAYLOAD | jq -c .) |
||||
|
PAYLOAD=$(jq -c . <<<${PAYLOAD}) |
||||
|
|
||||
|
|
||||
|
CMD="curl --noproxy '*' -d '${PAYLOAD}' http://localhost:8080/path/url" |
||||
|
echo ${CMD} |
||||
|
eval ${CMD} |
||||
@ -0,0 +1,53 @@ |
|||||
|
package io.xtfs.jwebfs.api; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
||||
|
import io.xtfs.jwebfs.service.WbFileService; |
||||
|
import io.xtfs.jwebfs.utils.AjaxResult; |
||||
|
import org.apache.commons.lang.StringUtils; |
||||
|
import org.apache.commons.logging.Log; |
||||
|
import org.apache.commons.logging.LogFactory; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/api") |
||||
|
public class ApWbFileController { |
||||
|
private static final Log log = LogFactory.getLog(ApWbFileController.class); |
||||
|
@Autowired |
||||
|
private WbFileService wbFileService; |
||||
|
|
||||
|
/** |
||||
|
* 提醒JSON |
||||
|
* @param reqstr |
||||
|
* @return |
||||
|
*/ |
||||
|
@PostMapping("/notify") |
||||
|
public int notify(@RequestBody String reqstr){ |
||||
|
if(StringUtils.isNotBlank(reqstr)){ |
||||
|
log.info("post string:"+reqstr); |
||||
|
Map rtmap = new HashMap(); |
||||
|
JSONObject json = JSONObject.parseObject(reqstr); |
||||
|
log.info("your json :"+json); |
||||
|
return 1; |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* help |
||||
|
* @return |
||||
|
*/ |
||||
|
@RequestMapping("/help") |
||||
|
public JSONObject help(){ |
||||
|
Map rmap = new HashMap(); |
||||
|
rmap.put("curts",System.currentTimeMillis()); |
||||
|
return AjaxResult.success("success",rmap); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
package io.xtfs.jwebfs.utils; |
||||
|
|
||||
|
import java.io.File; |
||||
|
import java.util.List; |
||||
|
|
||||
|
public class FsUtils { |
||||
|
/** |
||||
|
* 遍历文件 |
||||
|
// * @param wpath
|
||||
|
* @return |
||||
|
*/ |
||||
|
// public static List foldWalk(String wpath){
|
||||
|
// if(wpath){
|
||||
|
//
|
||||
|
// }
|
||||
|
// }
|
||||
|
|
||||
|
/** |
||||
|
* 遍历文件 |
||||
|
* @param dir |
||||
|
*/ |
||||
|
public static void ListFiles(File dir){ |
||||
|
if(!dir.exists()||!dir.isDirectory())return; |
||||
|
|
||||
|
String []files = dir.list();//通过初始化数组列表遍历
|
||||
|
for(int i=0; i<files.length; i++){ |
||||
|
File file = new File(dir , files[i]); |
||||
|
if(file.isFile()) { |
||||
|
System.out.println( |
||||
|
dir + "\\" + file.getName() + "\t" + file.length() |
||||
|
); |
||||
|
} else{ |
||||
|
System.out.println( |
||||
|
dir + "\\" + file.getName() + "\t<dir>" |
||||
|
); |
||||
|
ListFiles(file);//对于子目录,进行递归调用。
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
package io.xtfs.jwebfs; |
||||
|
|
||||
|
import io.xtfs.jwebfs.utils.FsUtils; |
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
|
||||
|
import java.io.File; |
||||
|
|
||||
|
@SpringBootTest |
||||
|
@RunWith(SpringJUnit4ClassRunner.class) |
||||
|
public class Fstest { |
||||
|
@Test |
||||
|
public void dirloop(){ |
||||
|
File dir = new File("D:\\xworks\\boyu"); |
||||
|
FsUtils.ListFiles(dir); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue