Results 1 to 5 of 5
Hello everyone,
The following code:
Code:
#!/bin/bash
x=1
echo $x
while [ $x -eq "1" ]
do
echo $x
x=2
done
echo "reached the end"
outputs "1" from line 3, ...
- 06-28-2010 #1Just Joined!
- Join Date
- Jun 2010
- Posts
- 3
well now this is embarrasing - simple bash script doesn't work
Hello everyone,
The following code:
outputs "1" from line 3, but nothing else.Code:#!/bin/bash x=1 echo $x while [ $x -eq "1" ] do echo $x x=2 done echo "reached the end"
I don't have access to a shell on the server and I'm calling it from php using
I'd say it's a problem with how the script is being called, but the script obviously starts and does not continue so I'm stumped!Code:echo passthru('/bin/bash -x ./process.sh');
Paul
- 06-28-2010 #2Just Joined!
- Join Date
- Jun 2010
- Posts
- 4
I get this output.
what exactly is it you want to do?Code:./foo.sh 1 1 reached the end
- 06-28-2010 #3Just Joined!
- Join Date
- Jun 2010
- Posts
- 3
Well that's not the script I want to use of course
I've tried to narrow down to find where the problem lies. What I'm doing is sending out a lot of emails (not spam!); once a day a cron job calls php which sets up a table of emails needing to be sent and then calls a bash script to initiate sending. In order to not send them out too quickly (and get blocked for spam) it sends out 4 per second. In order for php to not timeout, it is called repeatedly from inside the bash loop.
So the bash scripting I need is very simple, but seems to not be working on my server, or when being called from php. Even the following doesn't work (it outputs a but not a+1).
Any idea why?Code:#!/bin/bash a=1 echo $a echo $((a+1))
- 06-28-2010 #4Just Joined!
- Join Date
- Jun 2010
- Posts
- 4
Okey, the problem is that you are using passthru() its ment to be used if the bash data is binary and are to be passed directly to the browser.
Use system() or exec() and catch the output in stead.
Hope this helps.
- 06-28-2010 #5Just Joined!
- Join Date
- Jun 2010
- Posts
- 3
Thanks for the suggestion. I tried with exec first, and then was trying passthru and shell_exec to capture the output when exec wasn't working.
I've just realised I don't need to exec from php at all, but call bash straight from crontab and do the initial setup from there. Here's the actual script....
Still not working...Code:#!/bin/bash php setup_alerts.php code=2 while [ $code -eq 2 ] do php send_alerts.php code=$? done
I even tested with "echo hello > file" in the first line, but no file was produced. I guess it's time to get on to the server admin.
*****UPDATE: Turns out I was using a DOS file with CR+LFs. There goes most of a day.


Reply With Quote