-
Notifications
You must be signed in to change notification settings - Fork 8
/
g09-organize-data.zsh
executable file
·146 lines (117 loc) · 3.14 KB
/
g09-organize-data.zsh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env zsh
set -f
#
#
# This script will gather all Gaussian output files and test whether or not they terminated correctly (by testing if "Normal" is present at the end of the file. The script will notify you of both normally terminated jobs and those that aren't. Additionally, it will both archive and organize your input and output files as follows:
#
# | Archive | .gjf, .chk and .out | $HOME/research/archive/$date/foo
# | Organize | .gjf, .chk and .out | $HOME/research/finished_jobs/foo
# | Trash | .e, .o, and others | $HOME/.Trash
#
# NOTE: All files are organized based upon the file's basename! (i.e., foo.gjf, foo.out, foo.chk, foo.e.12345 and foo.o.12345 will all be parsed as one job; if, however, I had bar.chk instead, then bar.chk would be ignored by the script--unless there is a file name bar.out)
#
#
# Define defaults
#
# directories
directory_finished_jobs="$HOME/research/finished_jobs"
directory_archive="$HOME/research/archive"
trash="$HOME/.Trash"
# ensure correct sed (GNU sed)
if (( $+commands[gsed] ))
then
alias sed="gsed"
fi
#
# Debugging
#
function die()
{
echo
date
echo
echo "[ERROR] : ${@}"
exit 1
}
function status()
{
echo
date
echo
echo "[Status] : ${@}"
}
function success()
{
echo
date
echo
echo "[Success] : ${@}"
exit 0
}
#
# Test if we have finished Gaussian jobs
#
[ "$(ls **/*out)" ] \
|| die "There are no output files in the current directory tree"
#
# Make directories if they don't exist
#
# finished jobs
[[ ! -d "$directory_finished_jobs" ]] && mkdir -p $directory_finished_jobs
# trash in case the script fails -> clean out periodically
[[ ! -d "$trash" ]] && mkdir -p $trash
#
# Determine what finished jobs exist; make a list if they do
#
function make_list()
{
echo
echo "Jobs requiring attention:"
echo "-------------------------"
for file in "$@"
do
[[ -f "$file" ]]
# test if the job finished properly
test=$(tail $file | sed -n '/Normal/x; ${x;p;}')
if [[ -n $test ]]
then # job finished properly
echo $file >> /tmp/move_list.tmp
sed -i 's/.out/./g' /tmp/move_list.tmp
else # job did not finished properly
basename $file .out
fi
done
}
make_list **/*.out
#
# Move jobs and clean up log files
#
if [[ -f "/tmp/move_list.tmp" ]]
then
# organize data and remove junk
less /tmp/move_list.tmp | awk '{print "cp "$0"out '$directory_finished_jobs'"}' | zsh
less /tmp/move_list.tmp | awk '{print "cp "$0"gjf '$directory_finished_jobs'"}' | zsh
less /tmp/move_list.tmp | awk '{print "cp "$0"chk '$directory_finished_jobs'"}' | zsh
less /tmp/move_list.tmp | awk '{print "mv "$0"* '$trash'"}' | zsh
# move data to archive for safekeeping
date_time_stamp=$(date "+%Y-%m-%d at %H%M.%S hrs")
mkdir -p "$directory_archive/$date_time_stamp"
cp "$directory_finished_jobs"/* "$directory_archive/$date_time_stamp"
fi
# clean up
rm -f /tmp/move_list.tmp
#
# List completed jobs
#
if [ "$(ls -A $directory_finished_jobs)" ]
then
echo
echo "Finished Jobs:"
echo "--------------"
for file in $(ls $directory_finished_jobs/*.out)
do
basename $file .out
done
echo
fi
success "Script completed."