-
Notifications
You must be signed in to change notification settings - Fork 13
/
hue_multiple_home_cleanup.sh
executable file
·114 lines (100 loc) · 3.42 KB
/
hue_multiple_home_cleanup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
#Changes owner of Search Dashboard
PARCEL_DIR=/opt/cloudera/parcels/CDH
USAGE="usage: $0"
OVERRIDE=$1
if [[ ! ${USER} =~ .*root* ]]
then
if [[ -z ${OVERRIDE} ]]
then
echo "Script must be run as root: exiting"
exit 1
fi
fi
if [ ! -d "/usr/lib/hadoop" ]
then
CDH_HOME=$PARCEL_DIR
else
CDH_HOME=/usr
fi
if [[ -z ${HUE_CONF_DIR} ]]
then
if [ -d "/var/run/cloudera-scm-agent/process" ]
then
HUE_CONF_DIR="/var/run/cloudera-scm-agent/process/`ls -1 /var/run/cloudera-scm-agent/process | grep HUE_SERVER | sort -n | tail -1 `"
else
HUE_CONF_DIR="/etc/hue/conf"
fi
export HUE_CONF_DIR
fi
if [ -d "${CDH_HOME}/lib/hue/build/env/bin" ]
then
COMMAND="${CDH_HOME}/lib/hue/build/env/bin/hue shell"
else
COMMAND="${CDH_HOME}/share/hue/build/env/bin/hue shell"
fi
if [[ -z ${ORACLE_HOME} ]]
then
ORACLE_HOME=/opt/cloudera/parcels/ORACLE_INSTANT_CLIENT/instantclient_11_2/
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ORACLE_HOME}
export ORACLE_HOME LD_LIBRARY_PATH
fi
HUE_IGNORE_PASSWORD_SCRIPT_ERRORS=1
export CDH_HOME COMMAND HUE_IGNORE_PASSWORD_SCRIPT_ERRORS
echo "HUE_CONF_DIR: ${HUE_CONF_DIR}"
echo "COMMAND: ${COMMAND}"
${COMMAND} <<EOF
from datetime import datetime
from django.db import models
from desktop.models import Document, Document2
from django.contrib.auth.models import User
for user in User.objects.filter():
# print user.username
last_modified=datetime.now()
oldest_doc=0L
movecount=1
homedir_count=0
for document in Document2.objects.filter(owner=user, parent_directory=None, name=Document2.HOME_DIR):
homedir_count=homedir_count + 1
if homedir_count > 1:
print "%s has more than 1 homedir" % user.username
print "Fixing by moving newer ones to subdirectories"
for document in Document2.objects.filter(owner=user, parent_directory=None, name=Document2.HOME_DIR):
homedir_count=homedir_count + 1
if document.last_modified < last_modified:
last_modified=document.last_modified
oldest_doc_id=document.id
print "Oldest doc is %s" % oldest_doc_id
oldest_doc = Document2.objects.get(id=oldest_doc_id)
for document in Document2.objects.filter(owner=user, parent_directory=None, name=Document2.HOME_DIR):
if document.id != oldest_doc_id:
document.name="scriptmoved%s" % movecount
document.parent_directory=oldest_doc
document.save()
movecount=movecount + 1
for user in User.objects.filter():
print user.username
last_modified=datetime.now()
oldest_doc=0L
movecount=1
trashdir_count=0
for document in Document2.objects.filter(owner=user, name=Document2.TRASH_DIR):
print "User has a trash"
trashdir_count=trashdir_count + 1
if trashdir_count > 1:
print "%s has more than 1 trashdir" % user.username
print "Fixing by moving newer ones to subdirectories"
for document in Document2.objects.filter(owner=user, name=Document2.TRASH_DIR):
trashdir_count=trashdir_count + 1
if document.last_modified < last_modified:
last_modified=document.last_modified
oldest_doc_id=document.id
print "Oldest doc is %s" % oldest_doc_id
oldest_doc = Document2.objects.get(id=oldest_doc_id)
for document in Document2.objects.filter(owner=user, name=Document2.TRASH_DIR):
if document.id != oldest_doc_id:
document.name="scriptmoved%s" % movecount
document.parent_directory=oldest_doc
document.save()
movecount=movecount + 1
EOF