I have the list of users in user.log, under each user folder there is sub1 folder is there. i want to check whether sub1 is empty or not, if it is empty i have to skip that user user folder and iterate next user folders. i have the sample code,its not giving not proper results.
while read line
do
if [ -d /tmp/$line/sub1 ]
then
if [ find /tmp/$line/sub1 -empty -type d ]
then
echo " empty "
else
echo " not empty"
fi < user.log
#!/usr/bin/env python
import os
users=open("user.log").read().split("\n")
for r,d,f in os.walk("/tmp"):
if r.split("/")[1] in users:
if d==[] and f==[]:
try:
os.removedirs(r)
except Exception,e:
print e
else:
print "Directory %s successfully removed." % r