Bash script for adding SMB/Windows printer to CUPS failing, why??
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash script for adding SMB/Windows printer to CUPS failing, why??
I am trying to create a simple command-line script for a RHEL5.1_64 system to add shared Windows printers to their Linux server. When I run this command alone at a bash prompt, it works:
But when I put that into a script, I get no successes and a lot of errors in the cups/error_log. Here is my script:
Code:
#!/bin/bash
echo -e "\n"
echo -e "Please enter the Windows computer name, which must not have spaces:"
read COMP
echo -e "Please enter the printer's Share Name, also without spaces:"
read PRINTER
echo -e "Please enter the desktop Administrator's password:"
read PASSWD
clear
echo -e "\n\nDoes this look correct? \n\t Computer: $COMP \n\t Printer: $PRINTER \n\t Password: $PASSWD \n If this is wrong, press [Ctrl][C] to stop this program; otherwise press [Enter] to add your printer. \n\n"
read PAUSE
/usr/sbin/lpadmin \-p $PRINTER \-v smb://Administrator:${PASSWD}@${COMP}/${PRINTER} \-E
echo -e "\n"
echo -e "Printing test page now to $PRINTER"
/usr/bin/lpr -P "$PRINTER" /root/printtest.txt
echo -e "\n"
The errors are generally "Tree connect failed (NT_STATUS_BAD_NETWORK_NAME)" but I get others also, depending on if I try to \@ escape the @ symbol in the "-v URI" string; I've tried with and without quotes, with and without \-v \-E, but no matter what I cannot get it.
I am trying to create a simple command-line script for a RHEL5.1_64 system to add shared Windows printers to their Linux server. When I run this command alone at a bash prompt, it works:
But when I put that into a script, I get no successes and a lot of errors in the cups/error_log. Here is my script:
Code:
#!/bin/bash
echo -e "\n"
echo -e "Please enter the Windows computer name, which must not have spaces:"
read COMP
echo -e "Please enter the printer's Share Name, also without spaces:"
read PRINTER
echo -e "Please enter the desktop Administrator's password:"
read PASSWD
clear
echo -e "\n\nDoes this look correct? \n\t Computer: $COMP \n\t Printer: $PRINTER \n\t Password: $PASSWD \n If this is wrong, press [Ctrl][C] to stop this program; otherwise press [Enter] to add your printer. \n\n"
read PAUSE
/usr/sbin/lpadmin \-p $PRINTER \-v smb://Administrator:${PASSWD}@${COMP}/${PRINTER} \-E
echo -e "\n"
echo -e "Printing test page now to $PRINTER"
/usr/bin/lpr -P "$PRINTER" /root/printtest.txt
echo -e "\n"
The errors are generally "Tree connect failed (NT_STATUS_BAD_NETWORK_NAME)" but I get others also, depending on if I try to \@ escape the @ symbol in the "-v URI" string; I've tried with and without quotes, with and without \-v \-E, but no matter what I cannot get it.
... a bash shell script should be the same as typing in a bash shell, so unless you're trying to echo something out, there's no reason to escape anything (unless you would escape it when you type it on the command line).
I should have been more clear; when I wrote "I've tried with and without quotes, with and without \-v \-E" I meant, with the escape in \-v and \-E, and without the escape (just -p and -v and -E, not escaped).
I have bigger issues, I think. I can connect to another samba share when I mount it but I have browsing issues (like I can cd /mnt/winshare/fakedir/thisisreallyfake/ and run an ls -a there, and it shows me the same as /mnt/winshare/ ...)
Last edited by lefty.crupps; 04-24-2008 at 11:42 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.