Jump to content

Pass Variable To Bash Script


ShadowMage

Recommended Posts

I have an automatic emailer that sends a pdf report every week. The report is generated using a php script. The report needs to be sent to only a specific group of users based on a particular condition. What I'm wondering is if it is possible to construct this recipient list in the php script, then pass that variable off to a bash script that emails the pdf file.Thank you

Link to comment
Share on other sites

Well... you could dump it in a temporary file (in bash format if you want) then read that into the bash script. If it's a short list you can pass them as parameters to the script call.I don't know of a way you could pass a variable more directly than that. I would probably dump a file in /tmp (on unix-like) and then loop over the contents of that file in bash myself.

Link to comment
Share on other sites

Heh, don't blame you, it's not exactly a particularly nice thing to work with. Here's a quick example of looping over the contents of a file called "tmp" (each entry is delimited by a newline):

#!/bin/shCOUNT=0 # Initialise a count variable to show loopingfor DATA in `cat tmp` # here we're taking the contents of "tmp" to loopdo   echo "$COUNT - $DATA"; # Just output the data, you'd do something different   COUNT=$(($COUNT+1)); # Increment countdone

So, for a file containing "foo\nbar\nbork" it outputs:

0 - foo1 - bar2 - bork
You'd of course have a different loop body, but it's an example of the main idea.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...