Posted on 11-17-2023 12:30 AM
Hi, I have a script which i try to run trough Self Service using SwiftDialog. Script works fine when tested on local machine, but not when run trough JAMF. Can someone send me in right direction ? Script :
#!/bin/zsh
PrintLog="/Users/Shared/.AS/Logs/Print.log"
if [ -f $PrintLog ]; then
echo "______________________________________________________________________" >> $PrintLog
echo "######## Print Installer RUN ON: `date +%d.%m.%Y:%T` ########" >> $PrintLog
echo "Printer Installer log already exists. Continuing to Install...." >> $PrintLog
sleep 3
else
echo "______________________________________________________________________" >> $PrintLog
echo "######## Print Installer RUN ON: `date +%d.%m.%Y:%T` ########" >> $PrintLog
echo "Printer Installer has not run before. Creating master log now...." >> $PrintLog
mkdir -p /Users/Shared/.AS/Logs/
sleep 3
fi
# Use dialog to capture user input
userInfo=$(dialog \
--bannerimage "https://user-images.githubusercontent.com/3598965/111854068-84f6ab00-8971-11eb-935b-487f1a15b91f.png" \
--moveable \
--ontop \
--infobox "### Aditional Info\n\n#### Item 1 \n - Point one \n - Point two" \
--icon "https://user-images.githubusercontent.com/3598965/111854068-84f6ab00-8971-11eb-935b-487f1a15b91f.png" \
--message "Text can include **bold** and _italics_" \
--title "Enter Your Username" \
--icon "SF=checkmark.circle" \
--textfield "User Name:",required,prompt="User Name" \
--json)
user=$(echo $userInfo | awk -F '"User Name:" : "' '{print$2}' | awk -F '"' '{print$1}')
echo "User name is: $user" >> $PrintLog
# Check if the user pressed Cancel or closed the dialog
if [ $? -ne 0 ]; then
echo "User canceled. Exiting."
exit 1
fi
# Check if the entered username is empty
if [ -z "$userInfo" ]; then
echo "Username cannot be empty. Exiting."
exit 1
fi
# Construct the lpadmin command with the provided username
lpadmin_cmd="lpadmin -p MyCompany-Print -E -v lpd://$user@printserver/secure -P /Library/Printers/PPDs/Contents/Resources/KONICAMINOLTAC658.gz -o printer-is-shared=false"
# Display the lpadmin command to the user
echo "The following command will be executed:"
echo "$lpadmin_cmd"
# Ask for confirmation before executing the command
dialog \
--title "Confirmation" \
--icon "SF=checkmark.circle" \
--yesno "Do you want to proceed with the command?" 10 40
# Check the exit code of the confirmation dialog
if [ $? -eq 0 ]; then
# User chose to proceed, execute the lpadmin command
eval "$lpadmin_cmd"
echo "Command executed successfully."
else
# User chose not to proceed
echo "User canceled. Exiting."
fi
When user run this from Self Service, SwiftDialog shows up, Asks for Input of username(i put "ding" just to test), and uses that variable to run the command but then instead of adding printer i get
(eval):2: no such file or directory: ding@Printserver/secure
Script result: The following command will be executed:
lpadmin -p MyCompany-Print -E -v lpd://
ding@MPrintServer/secure -P /Library/Printers/PPDs/Contents/Resources/KONICAMINOLTAC658.gz -o printer-is-shared=false
(eval):2: no such file or directory: ding@Printserver/secure
Command executed successfully.
Posted on 11-17-2023 07:17 AM
Since you're using a PPD file you should really be using -m PPD_LOC. Using a capital P(-P) I believe will only work for generic drivers.
Posted on 11-17-2023 09:19 AM
I think the -P is correct (think Path to PPD), but the line break on the printer URI look suspicious. Make sure that your username parsing isn't adding a newline anywhere unexpected, which would produce the error message give.
If your username are *nix style short usernames, don't both with --json and just use a cut command or bashism to parse out the name.
11-17-2023 12:46 PM - edited 11-17-2023 12:46 PM
True, either will work. For what's it worth though the lpadmin man page lists -P as deprecated. Deprecated is a relative term when it comes to linux and Apple cups though as they've had PPDs deprecated for a number of years now.