[CentOS] Re: [hylafax-users] Having problems running sendfax from a bash script.

John Warren jwarren at prudentrx.com
Sat Jun 16 00:35:52 UTC 2007

I've been working on a way to send faxes from a bash script. It  
requires changing what parameters are used for each command. I keep  
having problems with quoted strings passed to the command.

I've created a really short test script which fails on my system.

commandline="sendfax -f noreply at prudentrx.com -n -x \"Test fax\" -d  
13105551212 /etc/hosts"
echo "Commandline: $commandline"

When I run the script I get the following:

Commandline: sendfax -f jwarren at prudentrx.com -n -x "Test fax" -d  
13105551212 /etc/hosts
fax": Can not open file

As you can see the sendfax command is not picking up the "'s around  
the "Test fax" string so it picks up the Test but thinks fax is the  
file to fax.

If you take the string and execute it from the command line it works.  
There is something about executing it from a string within a script  
that causes it to fail.

I tried doing the same thing using mail as the command with a quoted  
subject. Same thing happens, it break after the first space in the  
subject when executed from a sctips.

I've tried using both sh and exec commands but still no joy.

I really need to be able to build a command line with quoted text.  
Anyone have a way to work around this.


On Jun 15, 2007, at 3:43 PM, Lee Howard wrote:

> I think that you're making it harder than it needs to be.
> I don't like exec'ing variables or building command lines, etc.  I  
> prefer running this directly:
> sendfax -f "$FROMLINE" -n -D -i "$INFO" -c "$COMMENTS" -d "$DIAL"  
> That way quotes are your friend and not your enemy.
> Lee.
> John Warren wrote:
>> Update:
>> I replaced sendfax in the command line with echo, see below, just  
>> to see what echo would print. It printed the rest of line with the  
>> quotes. Now I'm totally confused. Why would echo see and print the  
>> quotes and sendfax dosen't but only when executed through a  
>> variable? This is weird.
>> echo -f jwarren at prudentrx.com <mailto:jwarren at prudentrx.com> -n -D  
>> -i 010000TESTFL -c "This is a test fax" -d Parmacist at 13106421032 / 
>> var/spool/hylafax/windows/jobs/QueuedT/00TESTFL.pdf
>> FYI, I had escape the "s when I built the command line as you showed.
>> /Update:
>> I think I have that right. See the following:
>> -----
>> sendfax -f jwarren at prudentrx.com <mailto:jwarren at prudentrx.com> -n  
>> -D -i 010000TESTFL -c "This is a test fax" -d  
>> Parmacist at 13106421032 /var/spool/hylafax/windows/jobs/QueuedT/ 
>> 00TESTFL.pdf
>> is: Can not open file
>> -----
>> The sendfax line is the echo of the variable that will be  
>> executed. As you can see the "'s are in the string that will be  
>> executed. What it looks like is that when you execute the string  
>> somehow the "'s are removed.
>> BTW, If I remember correctly I had a problem with putting "'s  
>> around the dial string but if I removed the Parmacist@ it worked.  
>> Don't hold me to this one though as I have to go back and recheck it.
>> This is driving me nuts.
>> John Warren
>> Network Operations Administrator
>> Prudent Rx Inc.
>> 100 Corporate Pointe, Suite 395
>> Culver City, CA 90230
>> ( +1.310.642.1700 x121
>> +1.310.642-1701
>> E: jwarren at prudentrx.com <mailto:jwarren at prudentrx.com>
>> **Notice of Confidentiality**
>> Please note that the information contained in this message may be  
>> privileged and confidential and protected from disclosure under  
>> the law, including the Health Insurance Portability and  
>> Accountability Act (HIPAA). If the reader of this message is not  
>> the intended recipient, or an employee or agent responsible for  
>> delivering this message to the intended recipient, you are hereby  
>> notified that any dissemination, distribution or copying of this  
>> communication is strictly prohibited and may subject you to  
>> criminal or civil penalties. If you have received this  
>> communication in error, please notify the sender by replying to  
>> the message and delete the material from any computer.
>> Thank you,
>> Prudent Rx, Inc.
>> On Jun 15, 2007, at 2:30 PM, Lee Howard wrote:
>>> John Warren wrote:
>>>> First, I'm new to writing bash scripts.
>>>> I have a string name "commandline" that contains the following:
>>>> sendfax -f jwarren at prudentrx.com <mailto:jwarren at prudentrx.com>  
>>>> <mailto:jwarren at prudentrx.com> -n -D -i 010000TESTFL -c "This is  
>>>> a test fax" -d Parmacist at 13106421032 /var/spool/hylafax/windows/ 
>>>> jobs/QueuedT/00TESTFL.pdf
>>>> If I do the following in a bash script it fails with "is: Can  
>>>> not open file"
>>>> $command
>>>> If I remove the  (  -c "This is a test fax"  )  or change it to   
>>>> (  -c "test"   ) it works.
>>>> If I execute the same line outside of the script it also works.
>>>> Is the Bash script taking out the "'s and if so how do I keep it  
>>>> from doing this?
>>> Sounds to me like you're creating some kind of COMMANDLINE  
>>> variable and then exec'ing that variable later.  In that case  
>>> you'll need to make sure to escape your quotes so that they don't  
>>> get eaten by the first parsing when it's placed into $COMMANDLINE...
>>> COMMANDLINE="sendfax -c\"This is a test fax\" -d  
>>> Pharmacist at 13106421032"
>>> Lee.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.centos.org/pipermail/centos/attachments/20070615/1eea13fe/attachment.htm

More information about the CentOS mailing list