Last active
August 29, 2015 14:21
-
-
Save dlech/4c9b268571af59cb7bb4 to your computer and use it in GitHub Desktop.
ev3dev run on vt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is used to start a program from a remote terminal but have it run | |
# on a virtual terminal. openvt has to be run as root, so we use sudo for that. | |
# Then, we use sudo --user to run the actual program as the current user. We also | |
# wrap the invocation in a shell so that we can rediect stdout/stderr to the | |
# current terminal. Finally, we capture the stderr of openvt and parse it to get | |
# the tty that the program is being run on so that we can kill it later. | |
tmpfile=$(tempfile) | |
sudo openvt --switch --verbose -- sudo --user $USER -- sh -c "$@ > $(tty) 2>&1" 2>$tmpfile | |
tty=$(sed "s|openvt: Using VT /dev/||" < $tmpfile) | |
rm -f $tmpfile | |
#echo $tty | |
read -p "Press [Enter] to terminate..." | |
sudo pkill -t $tty | |
sudo chvt 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment