diff --git a/scripts/cristin-cleanup.service b/scripts/cristin-cleanup.service new file mode 100644 index 0000000000000000000000000000000000000000..6998f510768b04d0230d9d0b29378e14fe09a4a9 --- /dev/null +++ b/scripts/cristin-cleanup.service @@ -0,0 +1,13 @@ +[Unit] +Description=Cristin cleanup +After=network.target + +[Service] +Type=simple +User=bottint +WorkingDirectory=/home/bottint/cristin/uib/prod/archive +ExecStart=/usr/local/bin/cristin-cleanup.sh + +[Install] +WantedBy=multi-user.target + diff --git a/scripts/cristin-cleanup.sh b/scripts/cristin-cleanup.sh new file mode 100644 index 0000000000000000000000000000000000000000..4499e5bd7f6d2af10e56ffb348ccc67a6f5f298d --- /dev/null +++ b/scripts/cristin-cleanup.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +printf "Deleting files older than 30 days" +find -maxdepth 1 -name "*.xml" -mtime +30 -exec rm {} \; + diff --git a/scripts/cristin-cleanup.timer b/scripts/cristin-cleanup.timer new file mode 100644 index 0000000000000000000000000000000000000000..db0711fa93a867920f214f10efec5bad38c942f5 --- /dev/null +++ b/scripts/cristin-cleanup.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Weekly cristin export upload + +[Timer] +OnCalendar=Sun 4:15 +AccuracySec=24h +Persistent=true + +[Install] +WantedBy=timers.target + diff --git a/scripts/cristin-upload.service b/scripts/cristin-upload.service new file mode 100644 index 0000000000000000000000000000000000000000..f2b98c09ba3a377b45ee7a5c1bee14176e6473cd --- /dev/null +++ b/scripts/cristin-upload.service @@ -0,0 +1,13 @@ +[Unit] +Description=Cristin export upload +After=network.target + +[Service] +Type=simple +User=bottint +WorkingDirectory=/home/bottint/cristin/uib/prod +ExecStart=/usr/local/bin/upload.sh + +[Install] +WantedBy=multi-user.target + diff --git a/scripts/cristin-upload.timer b/scripts/cristin-upload.timer new file mode 100644 index 0000000000000000000000000000000000000000..e290c4686f5555745a4cbd534316c1d9792ae48c --- /dev/null +++ b/scripts/cristin-upload.timer @@ -0,0 +1,8 @@ +[Timer] +OnCalendar=Sat 4:15 +AccuracySec=24h +Persistent=true + +[Install] +WantedBy=timers.target + diff --git a/scripts/upload.sh b/scripts/upload.sh new file mode 100644 index 0000000000000000000000000000000000000000..86ee71f1c342a51f09d438ef1cb9bd0908646c51 --- /dev/null +++ b/scripts/upload.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Upload script + +COUNT=0 + +rm sftp_batch.tmp +# Find files and write batchfile to be passed to sftp +for output in $(ls *.xml -1) +do + COUNT=1 + printf "put -P \"$output\"\n" >> sftp_batch.tmp +done + +# Exit if nothing to upload +if [[ $COUNT -eq 0 ]]; then + #printf "$0: No files to upload" >$2 + exit 1 +fi + +# Output which commands we will be running +#printf "Connecting with sftp and executing following commands:\n" +#printf "$(<sftp_batch.tmp)" + +sftp -b sftp_batch.tmp cristin-export@norzola.uio.no:cristin/ || exit 1 +#scp $output cristin-export@norzola.uio.no:cristin/ || exit + +#Archive transferred files +for output in $(ls *.xml -1) +do + mv $output archive/ +done + +rm sftp_batch.tmp +