Search code examples
bashshellhadoopcronhbase

Hbase commands not working in script executed via crontab


I was trying to list the set of tables present in the hbase using the below script:

#!/bin/bash
/home/user/hbase-1.2.4/bin/hbase shell << eof > /home/user/myfile.txt
list 'RAW_5_.*'
eof

I am able to get the table list while i run the script in the bash terminal using ::

sh script.sh

, but its creating a 0kb file while running using the crontab. I have given the absolute path for the hbase.

Can anyone help on this bottleneck please?


Solution

  • Since it is executing properly from terminal and not in crontab, try loading user bash profile in the script instead of #!/bin/bash ie,

    change

    #!/bin/bash
    

    to

    . ~/.bash_profile
    

    Usually #!/bin/bash is included in bash_profile and it will have user specific configurations as well.