hadoop-mapreduce-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From L N <nklnaray...@gmail.com>
Subject Delete a hdfs directory if it already exists in a shell script.
Date Sat, 23 Mar 2013 17:42:34 GMT
Hi,

I am trying to delete a hdfs directory if it already exists in a shell
script.

I wrote below command in a shell script

DIRECTORY=`date +%m%d%Y`
TestDir= hadoop fs -test -d /user/lnindrakrishna/$DIRECTORY
echo $TestDir
if [ $TestDir  -eq  0 ]; then
               hadoop fs -rmr /user/lnindrakrishna/$DIRECTORY
               echo "Directory Deleted"
else
               echo "Directory does not Exist"
           fi
exec hadoop fs  -mkdir /user/lnindrakrishna/`date +%m%d%Y`



I get below output

[lnindrakrishna@lvshdc2en0011 ~]$ sh PXP_EAP_Process.sh

PXP_EAP_Process.sh: line 9: [: -eq: unary operator expected
Directory does not Exist
mkdir: cannot create directory /user/lnindrakrishna/03232013: File exists



Looks like  hadoop fs -test -d /user/lnindrakrishna/$DIRECTORY is returning
NULL and that is the reason it throws null value for echo $TestDir  and it
goes to else part and displays  "Directory does not Exist"


What is wrong in the above shell script that I have written


-

Mime
View raw message