自动更新ss配置文件

Vanabel/ 8月 2, 2018/ 互联网/ 1 comments

将如下脚本保存为~/freess.sh

#!/bin/bash
lines=$(curl -s https://freess.pw | grep 'class="ss"' | sed 's/<div class="ss" value="\(.*\)@\(.*\)"><\/div>/\1:\2/')
echo $lines
set -f
serverlists=($lines)
for i in "${!serverlists[@]}"
do
  line=${serverlists[i]}
  echo $line
  array=(${line//:/ })
  #for i in "${!array[@]}"
  #do
  #  echo ${array[i]}
  #done
  if [ $i -eq 0 ]
  then
    cat >/cygdrive/d/gui-config.json<<EOL
{
  "configs" : [
    {
      "remarks" : "freess",
      "server" : "${array[2]}"
      "server_port" : ${array[3]},
      "password" : "${array[1]}",
      "method" : "${array[0]}",
      "enable" : true,
    },
EOL
  else
  cat >>/cygdrive/d/gui-config.json<<EOL
    {
      "remarks" : "freess",
      "server" : "${array[2]}"
      "server_port" : ${array[3]},
      "password" : "${array[1]}",
      "method" : "${array[0]}",
      "enable" : true,
    },
EOL
  fi
done

cat >> /cygdrive/d/gui-config.json<<EOL
  ],
  "random" : true,
  "autoBan" : true,
  "proxyRuleMode" : 2,
  "sysProxyMode" : 2,
  "proxyType" : 0,
  "dns_server" : "119.29.29.29",
  "randomAlgorithm" : 3,
}
EOL

cat /cygdrive/d/gui-config.json

# restart ss
ps -W | awk '/ShadowsocksR-dotnet4.0.exe/,NF=1' | xargs kill -f
cygstart.exe '/cygdrive/d/ShadowsocksR-dotnet4.0.exe'

然后利用windows的计划任务, 可以实现自动更新配置文件。 具体配置如下图所示:

Share this Post

1 Comment

  1. 如果脚本另外用到了python脚本产生的字符串, 可以这样将其加入到配置文件中:

    pushd /cygdrive/e/cygwin64/home/van/
    io_freess_today=$(/usr/bin/python3 ssqrdecoder.py 2>&1) 
    popd
    cat >> /cygdrive/d/gui-config.json<
    

Leave a Comment

您的电子邮箱地址不会被公开。 必填项已用*标注

*
*

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据