Monkey with a machine gun
by taylorkh from LinuxQuestions.org on (#4WDRN)
That is me, every time I learn some new programming feature I am dangerous :D
Recently with the help of some kind members of this forum I learned that I could execute commands on a remote machine using "ssh command" and as I have trust relationships established with the target machine using keys it is almost like being there. My first application was to create a script to post a trigger file to the Raspberry Pi which serves as the VPN sharing box for my home LAN. The trigger will cause a script on the Pi to disconnect and reconnect the VPN in order to get a new exit server. This worked great.
Not wanting to leave well enough alone I decided to provide some feedback to myself as to the status of the reconnect. I did this by examining the log file on the Pi which is created by my VPN script which runs there. I need to check for two conditions to determine that the disconnect/connect is complete. My first approach was like this (the Pi is called "magic")Quote:
This did not work. I received errors likeCode:grep: sshgrep: ]: No such file or directory
grep: magic: No such file or directory
grep: tail: No such file or directory
: No such file or directorygrep: /var/log/protonvpn.log
: No such file or directory
/data/data/scripts/newserver.sh: line 22: [: missing `]'It appears that ssh is NOT working when within the if [ ] statement. I then did things piecemeal and it works fineCode: ssh magic tail /var/log/protonvpn.log | grep "Connect"
condition1=$?
ssh magic tail /var/log/protonvpn.log | grep "Public IP Address"
condition2=$?
if [ $condition1 -eq 0 -a $condition2 -eq 0 ]
thenI have tried enclosing ssh and various parts of the command within backtics. I get various errors but no success. Apparently I am missing something simple (again). Any suggestions?
TIA,
Ken


Recently with the help of some kind members of this forum I learned that I could execute commands on a remote machine using "ssh command" and as I have trust relationships established with the target machine using keys it is almost like being there. My first application was to create a script to post a trigger file to the Raspberry Pi which serves as the VPN sharing box for my home LAN. The trigger will cause a script on the Pi to disconnect and reconnect the VPN in order to get a new exit server. This worked great.
Not wanting to leave well enough alone I decided to provide some feedback to myself as to the status of the reconnect. I did this by examining the log file on the Pi which is created by my VPN script which runs there. I need to check for two conditions to determine that the disconnect/connect is complete. My first approach was like this (the Pi is called "magic")Quote:
| if [ ssh magic tail /var/log/protonvpn.log | grep "Connect" -a ssh magic tail /var/log/protonvpn.log | grep "Public IP Address" ] then |
grep: magic: No such file or directory
grep: tail: No such file or directory
: No such file or directorygrep: /var/log/protonvpn.log
: No such file or directory
/data/data/scripts/newserver.sh: line 22: [: missing `]'It appears that ssh is NOT working when within the if [ ] statement. I then did things piecemeal and it works fineCode: ssh magic tail /var/log/protonvpn.log | grep "Connect"
condition1=$?
ssh magic tail /var/log/protonvpn.log | grep "Public IP Address"
condition2=$?
if [ $condition1 -eq 0 -a $condition2 -eq 0 ]
thenI have tried enclosing ssh and various parts of the command within backtics. I get various errors but no success. Apparently I am missing something simple (again). Any suggestions?
TIA,
Ken