We recently moved to AWS EC2 instances w/ the Amazon Linux distro.
On our old servers (RH Enterprise), we've been able to run a command in the background (&
) and also redirect the output to a log file, such as the below:
php /path/to/script > log.txt &
However, this no longer works on AWS. log.txt is created, but is empty.
If I leave off the & so the task runs in the foreground (php /path/to/script > log.txt
), it works and log.txt contains data.
What am I doing wrong here and/or what can I do to get the output of my scripts logged again?
Thanks in advance.
Here's a code sample of what is happening:
[ec2-user@ip /]$ cat logtest.php
<?php echo "It's big, it's heavy, it's wood!\n"; ?>
[ec2-user@ip /]$ php logtest.php > log.txt
[ec2-user@ip /]$ cat log.txt
It's big, it's heavy, it's wood!
[ec2-user@ip /]$ rm log.txt
[ec2-user@ip /]$ php logtest.php > log.txt &
[3] 6649
[ec2-user@ip /]$ <I waited 5 seconds and pressed enter here>
[3]+ Stopped php logtest.php > log.txt
[ec2-user@ip /]$ cat log.txt
[ec2-user@ip /]$ ll log.txt
-rw-rw-r-- 1 ec2-user ec2-user 0 Jan 3 00:30 log.txt
[ec2-user@ip /]$