-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprinter.sh
executable file
·148 lines (135 loc) · 3.88 KB
/
printer.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
#Printer v1.2
#
#Options
#$1: commands like Specify printer, reset message to ip of printer, etc
#$2: IP address specified
#$3: Message specified
#
#Variables
#send: send a command out at the end of the script
#getip: get ip interactively while script runs
#getmessage: get message interactively while script runs
#helpme: print help message
#
#Defaults
#Prefer to use command line arguments over interactive approach for getting info
#The following lists are used when info isn't specified:
# cs: for messages
# ip: for ip addresses
#Automatically send the message to the printer
#With no commands, print help
#
###############################################
#Set default ip and message action
###############################################
ip=`fortune ip` #automatically use ip list
message=`fortune cs` #automatically use cs list
send=1 #automatically send command
if [ -z $1 ]; then #without arguments, show help
helpme=1
send=0
fi
###############################################
#Set ip and message based on Options
###############################################
if [ -n $2 ]; then
ip=$2
fi
if [ -n $3 ]; then
message=$3
fi
###############################################
#Set ip/message based on first argument
###############################################
if [ -n "$1" ]; then
#CS
if [ "$1" = "cs" ]; then
#If no ip was passed through an option, get it interactively
if [ -z $2 ]; then
getip=1
fi
fi
#Fortune
if [ "$1" = "fortune" ]; then
message=`fortune -n 40 -s`
#If no ip was passed through an option, get it interactively
if [ -z "$2" ]; then
getip=1
fi
fi
#Custom
if [ "$1" = "custom" ]; then
#If no ip/message was passed through an option, get it interactively
if [ -z $2 ]; then
getip=1
fi
if [ -z $3 ]; then
getmessage=1
fi
fi
#Reset
if [ "$1" = "reset" ]; then
message="${ip} Ready"
fi
#Help
if [ "$1" = "help" ]; then
helpme=1
send=0
fi
fi
###############################################
#Set each argument if needed
###############################################
if [ "$getmessage" = 1 ]; then
echo -n Please enter a message:
read message
fi
if [ "$getip" = 1 ]; then
echo -n Please enter an IP address:
read ip
fi
###############################################
#Send message "$message" to printer "$ip"
###############################################
if [ "$send" = 1 ]; then
echo -n `date +%R`
echo -n "Sending \""
echo -n $message
echo -n "\" to the printer "
echo $ip
echo @PJL RDYMSG DISPLAY=\"$message\" | netcat -q 0 $ip 9100
fi
###############################################
#Output the help info and documentation
###############################################
if [ "$helpme" = 1 ]; then
echo "NAME"
echo " printer - send a message to a printer's LCD display"
echo " default is to send random message from ip/ip.dat and cs/cs.dat"
echo
echo "SYNOPSIS"
echo " printer [fortune | cs | custom | help | reset] [ipAddress] [Message]"
echo
echo DESCRIPTION
echo " fortune"
echo " Grab a random quote from fortune that fits on an LCD screen"
echo " and send it to a specified ip for a printer"
echo " You must enter an IP address along with this option"
echo
echo " cs"
echo " Grab a random cs quote from a cs and cs.dat file pair"
echo " You may specify an IP address to send this message to"
echo " To generate a file pair, put quotes in a file"
echo " Seperate each line with a % on its own line"
echo " strfile cs cs.dat //this command generates cs.dat from cs"
echo
echo " custom"
echo " Enter a message to display on a specified ip for a printer"
echo
echo " reset"
echo " Sets the message to the ip of the printer"
echo
echo " help"
echo " Display this help documentation"
fi