Quote:
Originally Posted by Turbocapitalist
It was not printing the message because it did not loop and went through the conditional just once while Tor was working.
Code:
#!/bin/sh
PATH=/usr/bin:/bin
url='http://checkip.amazonaws.com/'
echo "Start"
while true
do
var=$(torify 2> /dev/null wget $url -O - -o /dev/null)
if test -n "$var"
then
echo "Running"
apt update -q -y
apt upgrade -q -y --download-only
else
echo "Restarting"
systemctl restart tor
fi
sleep 900
done
See "man sh" or https://www.learnshell.org/
|
Hello,
Thank you so much for your reply.
I created a script file like below:
Code:
#!/bin/bash
VAR=$(torify 2> /dev/null wget http://checkip.amazonaws.com/ -O - -o /dev/null | cut -d" " -f6 | sed 's/<\/body><\/html>//');
while :
do
if [[ $VAR ]]
then
echo "OK";
break
else
echo "Restart";
/usr/bin/systemctl restart tor
sleep 3600;
VAR=$(torify 2> /dev/null wget http://checkip.amazonaws.com/ -O - -o /dev/null | cut -d" " -f6 | sed 's/<\/body><\/html>//');
fi
done
This script verifies that Tor is working properly (connected to a node). I have written a crontab as follows:
Code:
0 22 * * * root /usr/bin/bash /etc/Script.sh
But:
Code:
# ss -tupln | grep 9050
tcp LISTEN 0 4096 172.20.2.54:9050 0.0.0.0:* users:(("tor",pid=524735,fd=6))
#
# httping -x 172.20.2.54:9050 -5 -g http://www.google.com
PING www.google.com:80 (/):
socks5connect: command reply receive failure
Does my script not run long enough to connect the Tor to a node?