View difference between Paste ID: gamfXyDc and xk3mENq4
SHOW: | | - or go back to the newest paste.
1
----------------------------------------
2
Opens a reverse ssh connection to "username@host", forwarding "port" to the local ssh.
3
Retries every 3 minutes if the forwarding (or the connection) fails
4
----------------------------------------
5
#!/bin/bash
6
for (( ; ; ))
7
do
8
    ssh -g -o "ExitOnForwardFailure yes" -R port:localhost:22     username@host
9
    sleep 180
10
done
11
12
13
14
----------------------------------------
15
Script that adds another route to internet. Add table "admin" to /etc/iproute2/rt_tables once before running the script the first time. Here, 10.0.0.138 is the router, eth0 is the network device that connects to the secondary route.
16
----------------------------------------
17
18
#!/bin/bash
19
#Add table "admin" to /etc/iproute2/rt_tables
20
myotherdevice=eth0
21
myothernetwork=10.0.0
22
myothergateway=10.0.0.138
23
myotherip=$(ifconfig | grep $myothernetwork | cut -d: -f2 | cut -f1 -d' ')
24
ip route add ${myothernetwork}.0/24 dev $myotherdevice src $myotherip table admin
25
ip route add default via $myothergateway dev $myotherdevice table admin
26
ip rule add from ${myotherip}/32 table admin
27
ip rule add to ${myotherip}/32 table admin
28
ip route flush cache
29
30
31
----------------------------------------
32
Script that downloads a directory using rsync, with resume.
33
----------------------------------------
34
35
#!/bin/bash
36
while [ 1 ]
37
do
38
    rsync -avrvv --size-only --partial --progress username@host:/source_dir destination_dir
39
    if [ "$?" = "0" ] ; then
40
        echo "Rsync completed normally."
41
        exit
42
    else
43
        echo "Rsync failed. Retrying in 3 minutes."
44
        sleep 180
45
    fi
46
done
47
48
----------------------------------------
49
Same, but binds the connection to the other interface/route (10.0.0.2 is the assigned ip).
50
----------------------------------------
51
52
#!/bin/bash
53
54
while [ 1 ]
55
do
56
    rsync --address=10.0.0.2 -avrvv --size-only --partial --progress -e 'ssh -oBindAddress=10.0.0.2' username@host:/source_dir destination_dir
57
    if [ "$?" = "0" ] ; then
58
        echo "Rsync completed normally."
59
        exit
60
    else
61
        echo "Rsync failed. Retrying in 3 minutes."
62
        sleep 180
63
    fi
64
done