Create Bash Script to Wait and then Run
What I am basically trying to achieve is to automate something I do every time I start work.
In this order, I
- VPN connection
- Open new
gnome-terminal
tab - SSH into a remote machine
I have this so far:
WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool type --delay 1 --clearmodifiers "sudo openvpn --config 'conn1.ovpn'"
xdotool key Return
xdotool key ctrl+shift+t
wmctrl -i -a $WID
sleep 1
while ! $(/usr/bin/fping -q 192.168.0.5); do sleep 1;done
xdotool type --delay 3 --clearmodifiers "ssh machine1"
sleep 3
xdotool key Return
The problem I am having is that the SSH commands require the VPN connection to be open first. I thought that by putting the last sleep command in, that the code would wait for 3 seconds before hitting enter.
What is actually happening is that the openvpn
command is not running until after the last sleep, so the SSH command fails.
Can someone please point me in the direction I need to be heading for this.
bash shell-script
add a comment |
What I am basically trying to achieve is to automate something I do every time I start work.
In this order, I
- VPN connection
- Open new
gnome-terminal
tab - SSH into a remote machine
I have this so far:
WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool type --delay 1 --clearmodifiers "sudo openvpn --config 'conn1.ovpn'"
xdotool key Return
xdotool key ctrl+shift+t
wmctrl -i -a $WID
sleep 1
while ! $(/usr/bin/fping -q 192.168.0.5); do sleep 1;done
xdotool type --delay 3 --clearmodifiers "ssh machine1"
sleep 3
xdotool key Return
The problem I am having is that the SSH commands require the VPN connection to be open first. I thought that by putting the last sleep command in, that the code would wait for 3 seconds before hitting enter.
What is actually happening is that the openvpn
command is not running until after the last sleep, so the SSH command fails.
Can someone please point me in the direction I need to be heading for this.
bash shell-script
add a comment |
What I am basically trying to achieve is to automate something I do every time I start work.
In this order, I
- VPN connection
- Open new
gnome-terminal
tab - SSH into a remote machine
I have this so far:
WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool type --delay 1 --clearmodifiers "sudo openvpn --config 'conn1.ovpn'"
xdotool key Return
xdotool key ctrl+shift+t
wmctrl -i -a $WID
sleep 1
while ! $(/usr/bin/fping -q 192.168.0.5); do sleep 1;done
xdotool type --delay 3 --clearmodifiers "ssh machine1"
sleep 3
xdotool key Return
The problem I am having is that the SSH commands require the VPN connection to be open first. I thought that by putting the last sleep command in, that the code would wait for 3 seconds before hitting enter.
What is actually happening is that the openvpn
command is not running until after the last sleep, so the SSH command fails.
Can someone please point me in the direction I need to be heading for this.
bash shell-script
What I am basically trying to achieve is to automate something I do every time I start work.
In this order, I
- VPN connection
- Open new
gnome-terminal
tab - SSH into a remote machine
I have this so far:
WID=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}')
xdotool windowfocus $WID
xdotool type --delay 1 --clearmodifiers "sudo openvpn --config 'conn1.ovpn'"
xdotool key Return
xdotool key ctrl+shift+t
wmctrl -i -a $WID
sleep 1
while ! $(/usr/bin/fping -q 192.168.0.5); do sleep 1;done
xdotool type --delay 3 --clearmodifiers "ssh machine1"
sleep 3
xdotool key Return
The problem I am having is that the SSH commands require the VPN connection to be open first. I thought that by putting the last sleep command in, that the code would wait for 3 seconds before hitting enter.
What is actually happening is that the openvpn
command is not running until after the last sleep, so the SSH command fails.
Can someone please point me in the direction I need to be heading for this.
bash shell-script
bash shell-script
edited 2 days ago
Rui F Ribeiro
39.3k1479131
39.3k1479131
asked Nov 7 '17 at 23:40
Wildcard27Wildcard27
13516
13516
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Put a waiting loop before starting ssh:
while ! $(/usr/bin/fping -q <openvpn remote endpoint ip>); do sleep 1;done
When I do this, the VPN connection won't run. The new tab opens but both tabs appear to be waiting for the IP to be available
– Wildcard27
Nov 8 '17 at 0:09
@Wildcard27 do you mean that with the ping loop the VPN doesn't go up anymore?
– Zip
Nov 8 '17 at 0:44
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403202%2fcreate-bash-script-to-wait-and-then-run%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Put a waiting loop before starting ssh:
while ! $(/usr/bin/fping -q <openvpn remote endpoint ip>); do sleep 1;done
When I do this, the VPN connection won't run. The new tab opens but both tabs appear to be waiting for the IP to be available
– Wildcard27
Nov 8 '17 at 0:09
@Wildcard27 do you mean that with the ping loop the VPN doesn't go up anymore?
– Zip
Nov 8 '17 at 0:44
add a comment |
Put a waiting loop before starting ssh:
while ! $(/usr/bin/fping -q <openvpn remote endpoint ip>); do sleep 1;done
When I do this, the VPN connection won't run. The new tab opens but both tabs appear to be waiting for the IP to be available
– Wildcard27
Nov 8 '17 at 0:09
@Wildcard27 do you mean that with the ping loop the VPN doesn't go up anymore?
– Zip
Nov 8 '17 at 0:44
add a comment |
Put a waiting loop before starting ssh:
while ! $(/usr/bin/fping -q <openvpn remote endpoint ip>); do sleep 1;done
Put a waiting loop before starting ssh:
while ! $(/usr/bin/fping -q <openvpn remote endpoint ip>); do sleep 1;done
answered Nov 7 '17 at 23:54
Ipor SircerIpor Sircer
10.5k11024
10.5k11024
When I do this, the VPN connection won't run. The new tab opens but both tabs appear to be waiting for the IP to be available
– Wildcard27
Nov 8 '17 at 0:09
@Wildcard27 do you mean that with the ping loop the VPN doesn't go up anymore?
– Zip
Nov 8 '17 at 0:44
add a comment |
When I do this, the VPN connection won't run. The new tab opens but both tabs appear to be waiting for the IP to be available
– Wildcard27
Nov 8 '17 at 0:09
@Wildcard27 do you mean that with the ping loop the VPN doesn't go up anymore?
– Zip
Nov 8 '17 at 0:44
When I do this, the VPN connection won't run. The new tab opens but both tabs appear to be waiting for the IP to be available
– Wildcard27
Nov 8 '17 at 0:09
When I do this, the VPN connection won't run. The new tab opens but both tabs appear to be waiting for the IP to be available
– Wildcard27
Nov 8 '17 at 0:09
@Wildcard27 do you mean that with the ping loop the VPN doesn't go up anymore?
– Zip
Nov 8 '17 at 0:44
@Wildcard27 do you mean that with the ping loop the VPN doesn't go up anymore?
– Zip
Nov 8 '17 at 0:44
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403202%2fcreate-bash-script-to-wait-and-then-run%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown