Jump to content

Pass Variable To Bash Script


ShadowMage
 Share

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. Edited by AElliott
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...