Revised media ingest scriptSimple media ingest scriptbash script for printer administrationBash Backup Scriptscript- loop through files and directoriesNew svn repository scriptBash script to monitor Webserver php scriptOS testing scriptScript to toggle touchpadBash script prepares virtual environmentMemoizing or caching Bash function resultsSimple media ingest script
Cynical novel that describes an America ruled by the media, arms manufacturers, and ethnic figureheads
What does the word "foliage" mean here?
What is the term when two people sing in harmony, but they aren't singing the same notes?
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
How can I use the arrow sign in my bash prompt?
Could you calculate the variance of data using the median or something other than the mean?
Is there an Impartial Brexit Deal comparison site?
Greatest common substring
The baby cries all morning
Print name if parameter passed to function
Are there any thematic similarities between Shostakovichs' Symphony 5th and Beethovens' 7th symphony?
Why does John Bercow say “unlock” after reading out the results of a vote?
Is there a good way to store credentials outside of a password manager?
Opposite of a diet
how to analyze "是其于主也至忠矣"
Is exact Kanji stroke length important?
Best way to store options for panels
What would be the benefits of having both a state and local currencies?
Is there any reason not to eat food that's been dropped on the surface of the moon?
apt-get update is failing in debian
Mapping a list into a phase plot
voltage of sounds of mp3files
Failed to fetch jessie backports repository
How can I replace every global instance of "x[2]" with "x_2"
Revised media ingest script
Simple media ingest scriptbash script for printer administrationBash Backup Scriptscript- loop through files and directoriesNew svn repository scriptBash script to monitor Webserver php scriptOS testing scriptScript to toggle touchpadBash script prepares virtual environmentMemoizing or caching Bash function resultsSimple media ingest script
$begingroup$
link to original question: Simple media ingest script
As per answers I have refactored my code and would like to get feedback on the current structure.
The purpose of this tool is to allow someone to copy media from cards (SD cards, CFast, etc) using rsync and to also allow someone to complete incomplete transfer that they have initiated.
I've chosen to use prompts because it's more user friendly for the environment the script will be used in. The intended users are not command line tool friendly.
I'm not very familiar with bash and am quite out of practice with code in general so I would like to check behind myself. I received excellent feedback in the previous post and have addressed several of the points raised.
#!/usr/local/bin/bash
set -e
set -u
# prompt user for input
prompt_user()
while [[ -z "$!2:-" ]]
do
read -r -p "$1" "$2"
done
# prompt user for additional rsync options
add_rsync_options()
while true;
do
read -r -p "Add rsync options? [y/n] " add_options
case $add_options in
[Yy]* )
read -r -p $'Enter additional rsync options:n' rsync_options
break;;
[Nn]* )
break;;
*) echo "Please enter y or no!"
esac
done
# make target directory for transfer
make_directory()
echo $'Follow the prompt to create a project directory.n'
prompt_user $'Path of target directory?n' target_directory
prompt_user $'Brand Prefix?n' brand_prefix
prompt_user $'Project Name?n' project_name
prompt_user $'Media Type?n' media_type
prompt_user $'Location?n' location
prompt_user $'Employee?n' employee
destination_path=$target_directory/$(date +'%Y%m%d')_$brand_prefix_$project_name_$media_type_$location_$employee
echo "Creating directory: $destination_path"
mkdir -p "$destination_path" "$destination_path/logs"
# run rsync command
run_rsync()
echo $'Follow the prompt to complete the rsync command.n'
prompt_user $'Path to source media?n' source_path
# if partial ingest indicate pre-existing target directory
if [[ "$option" == "2" ]]; then
prompt_user $'Target directory?n' target_directory
destination_path=$target_directory
fi
add_rsync_options
echo $'Running rsync command:n'
rsync -r --info=progress2 --log-file="$destination_path/logs/$(date +'%Y%m%d')_transfer_log.txt" $rsync_options:- "$source_path/" "$destination_path"
# clear terminal for readability
clear
# start
while true
do
# read user input and run appropriate functions
read -r -p $'Enter [1] to start an ingest or [2] to complete a partial ingest.n' option
case $option in
1 )
make_directory
run_rsync
break;;
2 )
run_rsync
break;;
* )
echo $'Please enter a valid option!n';;
esac
done
Error handling is at a minimum still I believe and I'm not too sure what would even be relevant to handle past what's implemented. I'm not very experienced in that regard so resources are appreciated!
Thanks!
bash
New contributor
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
link to original question: Simple media ingest script
As per answers I have refactored my code and would like to get feedback on the current structure.
The purpose of this tool is to allow someone to copy media from cards (SD cards, CFast, etc) using rsync and to also allow someone to complete incomplete transfer that they have initiated.
I've chosen to use prompts because it's more user friendly for the environment the script will be used in. The intended users are not command line tool friendly.
I'm not very familiar with bash and am quite out of practice with code in general so I would like to check behind myself. I received excellent feedback in the previous post and have addressed several of the points raised.
#!/usr/local/bin/bash
set -e
set -u
# prompt user for input
prompt_user()
while [[ -z "$!2:-" ]]
do
read -r -p "$1" "$2"
done
# prompt user for additional rsync options
add_rsync_options()
while true;
do
read -r -p "Add rsync options? [y/n] " add_options
case $add_options in
[Yy]* )
read -r -p $'Enter additional rsync options:n' rsync_options
break;;
[Nn]* )
break;;
*) echo "Please enter y or no!"
esac
done
# make target directory for transfer
make_directory()
echo $'Follow the prompt to create a project directory.n'
prompt_user $'Path of target directory?n' target_directory
prompt_user $'Brand Prefix?n' brand_prefix
prompt_user $'Project Name?n' project_name
prompt_user $'Media Type?n' media_type
prompt_user $'Location?n' location
prompt_user $'Employee?n' employee
destination_path=$target_directory/$(date +'%Y%m%d')_$brand_prefix_$project_name_$media_type_$location_$employee
echo "Creating directory: $destination_path"
mkdir -p "$destination_path" "$destination_path/logs"
# run rsync command
run_rsync()
echo $'Follow the prompt to complete the rsync command.n'
prompt_user $'Path to source media?n' source_path
# if partial ingest indicate pre-existing target directory
if [[ "$option" == "2" ]]; then
prompt_user $'Target directory?n' target_directory
destination_path=$target_directory
fi
add_rsync_options
echo $'Running rsync command:n'
rsync -r --info=progress2 --log-file="$destination_path/logs/$(date +'%Y%m%d')_transfer_log.txt" $rsync_options:- "$source_path/" "$destination_path"
# clear terminal for readability
clear
# start
while true
do
# read user input and run appropriate functions
read -r -p $'Enter [1] to start an ingest or [2] to complete a partial ingest.n' option
case $option in
1 )
make_directory
run_rsync
break;;
2 )
run_rsync
break;;
* )
echo $'Please enter a valid option!n';;
esac
done
Error handling is at a minimum still I believe and I'm not too sure what would even be relevant to handle past what's implemented. I'm not very experienced in that regard so resources are appreciated!
Thanks!
bash
New contributor
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
link to original question: Simple media ingest script
As per answers I have refactored my code and would like to get feedback on the current structure.
The purpose of this tool is to allow someone to copy media from cards (SD cards, CFast, etc) using rsync and to also allow someone to complete incomplete transfer that they have initiated.
I've chosen to use prompts because it's more user friendly for the environment the script will be used in. The intended users are not command line tool friendly.
I'm not very familiar with bash and am quite out of practice with code in general so I would like to check behind myself. I received excellent feedback in the previous post and have addressed several of the points raised.
#!/usr/local/bin/bash
set -e
set -u
# prompt user for input
prompt_user()
while [[ -z "$!2:-" ]]
do
read -r -p "$1" "$2"
done
# prompt user for additional rsync options
add_rsync_options()
while true;
do
read -r -p "Add rsync options? [y/n] " add_options
case $add_options in
[Yy]* )
read -r -p $'Enter additional rsync options:n' rsync_options
break;;
[Nn]* )
break;;
*) echo "Please enter y or no!"
esac
done
# make target directory for transfer
make_directory()
echo $'Follow the prompt to create a project directory.n'
prompt_user $'Path of target directory?n' target_directory
prompt_user $'Brand Prefix?n' brand_prefix
prompt_user $'Project Name?n' project_name
prompt_user $'Media Type?n' media_type
prompt_user $'Location?n' location
prompt_user $'Employee?n' employee
destination_path=$target_directory/$(date +'%Y%m%d')_$brand_prefix_$project_name_$media_type_$location_$employee
echo "Creating directory: $destination_path"
mkdir -p "$destination_path" "$destination_path/logs"
# run rsync command
run_rsync()
echo $'Follow the prompt to complete the rsync command.n'
prompt_user $'Path to source media?n' source_path
# if partial ingest indicate pre-existing target directory
if [[ "$option" == "2" ]]; then
prompt_user $'Target directory?n' target_directory
destination_path=$target_directory
fi
add_rsync_options
echo $'Running rsync command:n'
rsync -r --info=progress2 --log-file="$destination_path/logs/$(date +'%Y%m%d')_transfer_log.txt" $rsync_options:- "$source_path/" "$destination_path"
# clear terminal for readability
clear
# start
while true
do
# read user input and run appropriate functions
read -r -p $'Enter [1] to start an ingest or [2] to complete a partial ingest.n' option
case $option in
1 )
make_directory
run_rsync
break;;
2 )
run_rsync
break;;
* )
echo $'Please enter a valid option!n';;
esac
done
Error handling is at a minimum still I believe and I'm not too sure what would even be relevant to handle past what's implemented. I'm not very experienced in that regard so resources are appreciated!
Thanks!
bash
New contributor
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
link to original question: Simple media ingest script
As per answers I have refactored my code and would like to get feedback on the current structure.
The purpose of this tool is to allow someone to copy media from cards (SD cards, CFast, etc) using rsync and to also allow someone to complete incomplete transfer that they have initiated.
I've chosen to use prompts because it's more user friendly for the environment the script will be used in. The intended users are not command line tool friendly.
I'm not very familiar with bash and am quite out of practice with code in general so I would like to check behind myself. I received excellent feedback in the previous post and have addressed several of the points raised.
#!/usr/local/bin/bash
set -e
set -u
# prompt user for input
prompt_user()
while [[ -z "$!2:-" ]]
do
read -r -p "$1" "$2"
done
# prompt user for additional rsync options
add_rsync_options()
while true;
do
read -r -p "Add rsync options? [y/n] " add_options
case $add_options in
[Yy]* )
read -r -p $'Enter additional rsync options:n' rsync_options
break;;
[Nn]* )
break;;
*) echo "Please enter y or no!"
esac
done
# make target directory for transfer
make_directory()
echo $'Follow the prompt to create a project directory.n'
prompt_user $'Path of target directory?n' target_directory
prompt_user $'Brand Prefix?n' brand_prefix
prompt_user $'Project Name?n' project_name
prompt_user $'Media Type?n' media_type
prompt_user $'Location?n' location
prompt_user $'Employee?n' employee
destination_path=$target_directory/$(date +'%Y%m%d')_$brand_prefix_$project_name_$media_type_$location_$employee
echo "Creating directory: $destination_path"
mkdir -p "$destination_path" "$destination_path/logs"
# run rsync command
run_rsync()
echo $'Follow the prompt to complete the rsync command.n'
prompt_user $'Path to source media?n' source_path
# if partial ingest indicate pre-existing target directory
if [[ "$option" == "2" ]]; then
prompt_user $'Target directory?n' target_directory
destination_path=$target_directory
fi
add_rsync_options
echo $'Running rsync command:n'
rsync -r --info=progress2 --log-file="$destination_path/logs/$(date +'%Y%m%d')_transfer_log.txt" $rsync_options:- "$source_path/" "$destination_path"
# clear terminal for readability
clear
# start
while true
do
# read user input and run appropriate functions
read -r -p $'Enter [1] to start an ingest or [2] to complete a partial ingest.n' option
case $option in
1 )
make_directory
run_rsync
break;;
2 )
run_rsync
break;;
* )
echo $'Please enter a valid option!n';;
esac
done
Error handling is at a minimum still I believe and I'm not too sure what would even be relevant to handle past what's implemented. I'm not very experienced in that regard so resources are appreciated!
Thanks!
bash
bash
New contributor
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 12 mins ago
usulmuaddibusulmuaddib
163
163
New contributor
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
usulmuaddib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
usulmuaddib is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216286%2frevised-media-ingest-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
usulmuaddib is a new contributor. Be nice, and check out our Code of Conduct.
usulmuaddib is a new contributor. Be nice, and check out our Code of Conduct.
usulmuaddib is a new contributor. Be nice, and check out our Code of Conduct.
usulmuaddib is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216286%2frevised-media-ingest-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown