forked from inovex/lfs458-course-prep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a script to save the contents of the students home directories (i…
…novex#8) * Add a script to save the contents of the students home directories * Add docs * scp in parallel for better network utilization Add output to gitignore
- Loading branch information
1 parent
b08b048
commit 0faf282
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ terraform.tfstate.backup | |
.terraform | ||
ips | ||
packages | ||
homes | ||
account.json | ||
.DS_STORE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
# Find the script location. Inspired by: https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself | ||
scriptLocation="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
dest=${scriptLocation}/homes | ||
mkdir -p ${dest} | ||
|
||
function ipOf() { | ||
local student=${1} | ||
local node=${2} | ||
cat ${scriptLocation}/ips/${student} | grep ${node} | awk '{ print $2 }' | ||
} | ||
|
||
function download() { | ||
local student=${1} | ||
tmpDir=$(mktemp -d) | ||
mkdir ${tmpDir}/master | ||
scp -q -o StrictHostKeyChecking=no -r -i ${scriptLocation}/keys/${student} student@$(ipOf ${student} master):/home/student ${tmpDir}/master || echo "some files might be missing for ${student} master" | ||
mkdir ${tmpDir}/node | ||
scp -q -o StrictHostKeyChecking=no -r -i ${scriptLocation}/keys/${student} student@$(ipOf ${student} node):/home/student ${tmpDir}/node || echo "some files might be missing for ${student} node" | ||
zip -q -r ${dest}/${student}_home.zip ${tmpDir} | ||
rm -rf ${tmpDir} | ||
} | ||
|
||
for student in $(find ips -type f -exec basename {} \;) ; | ||
do | ||
download ${student} & | ||
done | ||
|
||
wait |