Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
fuss:tor [2023/03/03 03:48] – [Monitoring Tor Instances with Monit] officefuss:tor [2024/03/30 16:31] (current) – [Monitoring tor Instances using Expect] office
Line 315: Line 315:
 </code> </code>
 that will restart tor in case a circuit is not built within two minutes (60 seconds standard monit check time and times two for one more retry). that will restart tor in case a circuit is not built within two minutes (60 seconds standard monit check time and times two for one more retry).
 +
 +====== Monitoring tor Instances using Expect ======
 +
 +A more versatile variation of the [[/fuss/tor#monitoring_tor_instances_with_monit|monit tor monitoring system]] is to use good old "expect" in order to make sure that tor has an established circuit and to take action.
 +
 +<code>
 +#!/usr/bin/expect -f
 +###########################################################################
 +##  Copyright (C) Wizardry and Steamworks 2024 - License: MIT            ##
 +###########################################################################
 +# This is an "expect" script that checks whether tor has established a    #
 +# circuit and sets the return status depending on whether it has or not.  #
 +#                                                                         #
 +# In other words, iff. the script returns 0, then tor has an established  #
 +# circuit; otherwise no circuit has been established.                     #
 +#                                                                         #
 +# Requirements:                                                           #
 +#   * expect (TCL program)                                                #
 +#   * tor must expose a control port and must have a control password     #
 +#                                                                         #
 +# In order to generate a control password, issue: tor --hash-password PWD #
 +# where PWD is the desired control port password. After that, amend the   #
 +# tor configuration file to set the control port address, port and pass:  #
 +#                                                                         #
 +# ControlPort 0.0.0.0:8051                                                #
 +# HashedControlPassword 16:A482ADEAAWF43EE...                             #
 +#                                                                         #
 +# Running: ./this-script ADDRESS PORT PASSWORD                            #
 +# where:                                                                  #
 +#   * ADDRESS is the tor listening control address,                       #
 +#   * PORT is the tor listening control port,                             #
 +#   * PASSWORD is the plaintext control password                          #
 +#                                                                         #
 +# after which the return status can be checked on the shell with:         #
 +# echo $?                                                                 #
 +###########################################################################
 +
 +set address [lindex $argv 0];
 +set port [lindex $argv 1];
 +set password [lindex $argv 2];
 +
 +set timeout 5
 +spawn telnet $address $port
 +
 +send "AUTHENTICATE \"$password\"\n"
 +expect "250 OK\r\n"
 +send "GETINFO status/circuit-established\n"
 +expect {
 +    timeout {
 +        exit 1
 +    }
 +    -ex "250-status/circuit-established=1\r\n250 OK\r\n"
 +}
 +
 +</code>
  

fuss/tor.1677815287.txt.gz · Last modified: 2023/03/03 03:48 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.