1

I am trying to create and append to a text file using PHP SSH2. The command I am sending is this:

$cmd = "cd $output_directory; cat > myfile.txt; echo \"My Text\" >> myfile.txt";

The file is created, but the text is not appended to it.

Appreciate any input as to where I am going wrong.

user3101337
  • 364
  • 8
  • 24
  • Your command works for me. Have you tried prepending "php" to the command? – Jonathan Dec 11 '18 at 04:13
  • Show the PHP code you use to run this `$cmd`. Also note that on my linux, `cat >myfile.txt` does not work. I have to do `cat /dev/null >myfile.txt` or my preferred `>myfile.txt`, no cat at all. This creates the empty file, I assume you want to do. – Nic3500 Dec 11 '18 at 05:35

1 Answers1

1

Try to change cat to touch to create file.

Example:

$cmd = "cd $output_directory; touch myfile.txt; echo \"My Text\" >> myfile.txt";