How to re-write this bash script in Python?

Mark Lawrence breamoreboy at
Thu Jul 30 21:36:06 CEST 2015

On 30/07/2015 19:31, sutanu.das at wrote:
> #!/bin/bash
> _maillist='pager at'
> _hname=`hostname`
> _logdir=/hadoop/logs
> _dirlog=${_logdir}/directory_check.log
> _year=$(date -d "-5 hour" +%Y)
> _month=$(date -d "-5 hour" +%m)
> _day=$(date -d "-5 hour" +%d)
> _hour=$(date -d "-5 hour" +%H)
> _hdfsdir=`hdfs dfs -ls -d /hadoop/flume_ingest_*/$_year/$_month | awk '{print $8}'`
> echo "Checking for HDFS directories:" > ${_dirlog}
> echo >> ${_dirlog}
> for _currdir in $_hdfsdir
> do
> hdfs dfs -ls -d $_currdir/$_day/$_hour &>> ${_dirlog}
> done
> if [[ `grep -i "No such file or directory" ${_dirlog}` ]];
> then
> echo "Verify Flume is working for all  servers" | mailx -s "HDFS Hadoop Failure on Flume: ${_hname}" -a ${_dirlog} ${_maillist}
> fi

Read the documentation here and then run up 
your favourite editor and start typing.  When and if you hit problems 
come back with a snippet of code that shows the problem, what you 
expected to happen, what actually happened, and the full traceback if 
there is one.  Please use cut and paste to ensure that you get the data 

My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

More information about the Python-list mailing list