I am using VPN connection using SSL Network Extender(SNX) to connect to remote server. The connection from the remote server is limited to only 12 hours. After that the connection is being disconnected and have to restart the SNX server again. To overcome those hardship I am trying to automate SNX restart using crontab.
vpn.sh
.#!/bin/bash snx -d sleep 3 echo 'password' | snx
.snxrc
inside home directoryserver server.com username username reauth yes
crontab -e
) config I have* */12 * * * bash /home/username/vpn.sh > /home/username/cron.log
It runs every 12 hours. But snx -d
runs successfully but on reaching echo 'newpass6' | snx
I am getting this error:
Failed to init terminal!
Any body encountered such issues? Please help me. I have been struggling for a week now. Thanks in advance.
I have followed this link to setup snx
The approved answer doesn't work for me. It creates an empty tmux session with no command executed inside. So this is my way to do this task:
byobu-tmux new-session -d "echo <password> | nohup snx -s <host> -u <user>"
Only one command to make it work. nohup
is required because snx process is going to the background and returning prompt. After that, tmux exits, and snx is not assigned to the terminal. Without nohup
after tmux exits, the system will terminate the snx process.
Because snx client cannot start without a terminal. So i put in my script these commands to start snx in a byobu session.
byobu new-session -d -s vpn;
byobu new-window -t vpn:1 -n "snx" "echo your_password | snx -s your_ip -u your_user; sleep 10"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With