Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

how to verify if name node is in safe mode

avatar

how to verify if name node is in safe mode ?

goal - in case of name node in safe mode , then bash script will perform the following steps on one of the masters machines

# su - hdfs  
$ hdfs dfsadmin -safemode get 
$ hdfs dfsadmin -safemode leave 

second how to perform the steps as described in the bash script

is it ok to do the following :

su - hdfs -c "hdfs dfsadmin -safemode get"
su - hdfs -c "hdfs dfsadmin -safemode leave" 
Michael-Bronson
1 ACCEPTED SOLUTION

avatar
Super Guru

@Michael Bronson,

Yes. You can use the second way to achieve your task. You can also use the below to check if namenode is in SafeMode and leave conditionally.

su - hdfs -c "hdfs dfsadmin -safemode get" | grep ON
if [ $? -ne 0 ]
then
  su - hdfs -c "hdfs dfsadmin -safemode leave" 
fi

To run the above script, put the content in a file say xyz.sh

chmod +x xyz.sh
./xyz.sh

Thanks,

Aditya

View solution in original post

1 REPLY 1

avatar
Super Guru

@Michael Bronson,

Yes. You can use the second way to achieve your task. You can also use the below to check if namenode is in SafeMode and leave conditionally.

su - hdfs -c "hdfs dfsadmin -safemode get" | grep ON
if [ $? -ne 0 ]
then
  su - hdfs -c "hdfs dfsadmin -safemode leave" 
fi

To run the above script, put the content in a file say xyz.sh

chmod +x xyz.sh
./xyz.sh

Thanks,

Aditya