Execute a shell script with php Execute a shell script with php hadoop hadoop

Execute a shell script with php


Use 2>&1 in order to achive that

$output = shell_exec('sh /usr/local/hadoop-3.0.2/copytoallhdfs.sh 2>&1');

2 refers to the second file descriptor of the process, i.e. stderr.

> means redirection.

&1 means the target of the redirection should be the same location as the first file descriptor, i.e. stdout.


With @nacho 's comment, i thought if it was something to do about the location of my sh script. I edited my sh script and inserted pwd to verify the location it is giving me. Then i realized that it was giving me the location of my apache directory.

So i changed the location and inserted the full path to execute the command bin/hdfs.It worked!

Here is my updated script:

#!/bin/bashmyarray=`/usr/local/hadoop-3.0.2/bin/hdfs dfs -ls -C /`echo $myarray;for name in $myarraydo /usr/local/hadoop-3.0.2/bin/hdfs dfs -copyFromLocal /usr/local/hadoop-3.0.2/myData/* $name;done

That was kind of a silly mistake, but i guess it can happen!