-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_print.sh
executable file
·56 lines (51 loc) · 1.73 KB
/
batch_print.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
#
# Author: Nate Levesque <[email protected]>
# Language: Shell
# Filename: batch_print.sh
#
# Description:
# Downloads a list of files from a public folder and prints them.
# The print_destination and baseUrl variables need to be set in the
# script before using. Not the cleanest code, but it works, was
# originally used to print a group of documents via a remote mac. When
# run, it prompts the user for a comma-separated list of files to download
# and print, then splits the list up around the commas into a file
# and iterates through it, downloading and printing the files one at a
# time.
#
########################################################################
# Settings #
########################################################################
baseUrl=http://www.thenaterhood.com/
print_destination=mcx_0
#
# Implement common code for dependency checks
depCheck(){
# Checks if a piece of software exists on a system and
# if it doesn't, stops execution and exits with an error.
#
# Arguments:
# $1: a command to test
#
if [ ! `command -v $1` ]; then
echo "You need $1 installed to use this script, exiting..."
exit 1
fi
}
#
# Checking for required software
depCheck curl
depCheck lp
#
# Requesting list of files from the user
read -p "Comma separated filenames of the files to be printed, ie file1.pdf,file2.pdf: " files
#
# Creates a list of files
echo $files | sed -e 's/,/\
/g' > files.lst
#
# downloads and prints the files
for file in `cat files.lst`; do
curl -O $baseUrl$file && lp -d "$print_destination" $file && echo "Downloaded and printed $file from $baseUrl" || echo "Could not print $file"
done