-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsanger_crontab_script.sh
executable file
·73 lines (62 loc) · 2.15 KB
/
sanger_crontab_script.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
#!/bin/bash
########## Configuration settings ########
#set -x
source /opt/sanger_script/sanger_configuration
export PATH="/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin"
time=$(date +%T-%m%d%y)
echo "Initiating crontab - $time"
proc_file="$PROCESSED_FILE_DIRECTORY/$PROCESSED_FILE_NAME"
echo "$proc_file"
if [ ! -f $proc_file ]; then
touch $proc_file
echo "Created $proc_file"
fi
files=$(ls -t1 $PATH_SANGER_FOLDER/*.txt)
if [[ $files == '' ]]; then
echo "There are no files to process on folder $INPUT_DIRECTORY"
echo "Exiting the script "
echo "------------------------------------------"
exit 1
fi
while read -r line ; do
if [ ! -d tmp ]; then
mkdir -p tmp
fi
bn_file=$(basename $line)
if ! grep -q $bn_file "$proc_file"; then
echo "echo line :$line - $bn_file"
path_folder=$(echo "$bn_file" | cut -d "." -f 1)
if [[ ! -d $PATH_SANGER_FOLDER/$path_folder ]];then
echo "Run folder $path_folder missing. Run not being processed..."
continue
fi
time=$(date +%T-%m%d%y)
echo "Executing script $time: $SANGER_SCRIPT -f $PATH_SANGER_FOLDER/$bn_file -r $PATH_SANGER_FOLDER/$path_folder -o $SHARED_FOLDER"
$SANGER_SCRIPT -f $PATH_SANGER_FOLDER/$bn_file -r $PATH_SANGER_FOLDER/$path_folder -o $REMOTE_SAMBA_SHARED_FOLDER
# include the file into procesed file
error_code=$?
echo "Error code: $error_code"
if [ $error_code == 0 ]; then
echo "$bn_file" >> $proc_file
else
echo -e "Something unexpected went wrong in sanger script" | sendmail -f "[email protected]" -t "[email protected]" -v "[email protected]"
fi
else
echo "Run already processed."
fi
# Delete temporary folder
rm -rf $PROCESSED_FILE_DIRECTORY/tmp
done <<<"$files"
# Restart samba
echo "Restarting Samba service"
# Ubuntu
#ssh $REMOTE_USER@$REMOTE_SAMBA_SERVER 'sudo /usr/sbin/service smbd restart'
# CestOS
#ssh -q $REMOTE_USER@$REMOTE_SAMBA_SERVER 'sudo /usr/sbin/service smb restart'
if [ $? -eq 0 ]; then
echo "Samba restarting succesfully"
else
echo -e "Something unexpected went wrong in samba restarting" | sendmail -f "[email protected]" -t "[email protected]"
fi
time=$(date +%T-%m%d%y)
echo "End crontab - $time"