1
0

add scpt cron

This commit is contained in:
syui 2024-02-17 17:35:49 +09:00
parent 51c41897e2
commit 2c22e95941
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
5 changed files with 37 additions and 21 deletions

View File

@ -96,3 +96,11 @@ $ cp -rf ~/.config/ai ./.config/
$ docker compose up
```
### cron
```sh
$ sudo pacman -S fcron
$ fcrontab -e
* * * * * $HOME/bot/test/ai.zsh c
```

View File

@ -8,11 +8,13 @@ case $OSTYPE in
;;
esac
d=${0:a:h}
source $d/env
source $d/refresh.zsh
source $d/token.zsh
source $d/reply.zsh
source $d/notify.zsh
source $d/cron.zsh
case $1 in
refresh|r)
@ -27,4 +29,7 @@ case $1 in
notify|n)
notify
;;
cron|c)
cron
;;
esac

7
test/cron.zsh Normal file
View File

@ -0,0 +1,7 @@
function cron() {
t=`docker ps |grep "ai bot"`
if [ -z "$t" ];then
docker compose up -d
fi
exit
}

View File

@ -1,26 +1,10 @@
cfg=~/.config/ai/test.json
if [ ! -f $cfg ] || ! cat $cfg|jq . || [ "`cat $cfg|jq .host`" = "null" ] || [ -z "`cat $cfg`" ];then
mkdir -p ~/.config/ai
echo server:
read host
echo password:
read pass
echo handle:
read handle
echo "{ \"host\":\"$host\", \"password\":\"$pass\", \"handle\":\"$handle\" }" >> $cfg
fi
host=`cat $cfg|jq -r .host`
handle=`cat $cfg|jq -r .handle`
pass=`cat $cfg|jq -r .password`
date=`date --iso-8601=seconds`
if [ ! -f $cfg.t ];then
$d/token.zsh
if [ -f $cfg ];then
host=`cat $cfg|jq -r .host`
handle=`cat $cfg|jq -r .handle`
pass=`cat $cfg|jq -r .password`
date=`date --iso-8601=seconds`
fi
if [ -f $cfg.t ];then

View File

@ -1,4 +1,16 @@
function token() {
mkdir -p ~/.config/ai
echo server:
read host
echo password:
read pass
echo handle:
read handle
echo "{ \"host\":\"$host\", \"password\":\"$pass\", \"handle\":\"$handle\" }" >> $cfg
url=https://$host/xrpc/com.atproto.server.createSession
j=`curl -sL -X POST -H "Content-Type: application/json" -d "{\"identifier\":\"$handle\",\"password\":\"$pass\"}" $url`
echo $j