I hope had figureout the solution, but not sure if gracefully.
The idea is, to create a folder on host, shared for guest plus proces in background which checks this folder. If any pdf file comes, it will be printed out to ssh tunnel, then removed.
Below working code made with inotify-tools package.
Code: Select all
sudo apt-get install inotify-tools
Let's name the folder "printorres" and ...
script "printerros".
Code: Select all
#!/bin/bash
inotifywait -m /home/.........../printorres -e create -e moved_to |
while read path action file; do
if [[ "${file^^}" =~ .*PDF$ ]]; then
# echo $file
lpr -H 127.0.0.1:1631 -P Printer-Name /home/.........../printorres/$file
rm /home/.........../printorres/$file
fi
done
If this proces is running we can print to offsite printer with "Print to PDF" command and place the printout to "printorres" folder. No matter if we print from host or guest desktop.
Now proposal of processing the ssh session from offsite computer connrcted to printer.
Code: Select all
#!/bin/bash
# Username and password
user="XXX"
pw=$(zenity --password)
# Launching "printerros" script
sshpass -p $pw ssh $user@SERVER "nohup /................./printerros < /dev/null > /tmp/mylogfile 2>&1 &"
# Open VNC/RDP and printing tunnels. Here VNC, for example
sshpass -p $pw ssh -L 5901:127.0.0.1:5901 -N -f $user@SERVER
sshpass -p $pw ssh -R 1631:127.0.0.1:631 -N -f $user@SERVER
# We can start headless VBox machine and exec VBoxManage commands
# Now open the client - viewer. In this case VNC.
xtigervncviewer 127.0.0.1::5901
# When client is closed, let's kill "printerros" process.
# I've wrote additional script, because I cannot figureout how to pass
# kill $(pidof inotifywait) trough ssh tunnel
sshpass -p $pw ssh $user@SERVER "/................./kill-printeros"
# Close ssh tunnels
kill $(pidof ssh)
Script kill-printeros
Code: Select all
#!/bin/bash
# Printerros can be killed by killing "inotifywait" process.
kill $(pidof inotifywait)
It looks like it works pretty good, but can I trust it will be reliable at real field?
So far, hope [SOLVED]