PDF export
I have a Linux instance (CentOS 7) setup under VMware that enables printing to PDF via CUPS PDF. (That used to work on OS X, but for the last several versions, I haven't been able to get it to work anymore.) Problem: The PDFs generated sit on the desktop of the Linux instance. Solution: A simple script that runs from rc.local in the background (actually in a screen session) and copies them to my macOS machine via SSH, as they're created. (Yes, I know I can "normally" print to PDF in Mac applications, but that doesn't work for Judicial Council forms I have to fill out in Acrobat Pro, dump to an unprotected populated PDF, and then paste on my electronic signature for e-filing.)
First, setup the instance to stop booting into the heavy GUI:
Build the script (which makes use of an .ssh/config file to specify hostnames, identity files, etc) (this could be more robust, may revisit later, but in practice it's working perfectly):
Install Screen:
Ensure SSHD is running as a service when I reboot:
Start the script running in the background:
Just as a convenience, announce the IP address in the login prompt:
Commit to it all:
First, setup the instance to stop booting into the heavy GUI:
[root@localhost system]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[root@localhost system]# systemctl get-default
multi-user.target
#!/usr/bin/env bash
export IFS=$'\n'!
cd ~charshman/Desktop
/bin/pwd
while `/bin/true`
do
for FILE in `/usr/bin/find . -maxdepth 1 -name "*.pdf"`
do
echo "Processing file [$FILE]";
# Sleep for a couple of seconds to make sure it's finished being written
sleep 3
scp "$FILE" blacktower:~/Downloads
export NEWFILE="old/`/usr/bin/date '+%Y.%m.%d.%H%M'`-`/bin/basename $FILE`"
/bin/mv -v "$FILE" "$NEWFILE"
done
sleep 5
done
Install Screen:
[root@localhost ~]# yum install -y screen
Ensure SSHD is running as a service when I reboot:
[root@localhost ~]# systemctl enable sshd
[root@localhost system]# vim /etc/rc.local
#!/bin/bash
# ...
/bin/sudo -u username /bin/screen -d -m -S CUPS-PDF /home/username/exporter.sh
[root@localhost ~]# vim /etc/issue
\S (\4)
Kernel \r on an \m
[root@localhost ~]# shutdown -r now
I love UNIX.
Comments
Post a Comment