bash script gets stuck after sed












0















I have this bash script in CentOS 7 that creates users using a text document as input, the text document has 3 fields separated by colons; username:full name:email
The problem is that the script runs but it never finishes and according to the bash -x debug, it gets at least as far as the sed command but goes no further. The syntax used to run the script is script-name argument(input-file)



Here is the script in question:



#!/bin/bash

if [ $USER != "root" ]
then
echo "Note: You are required to run this program as root."
exit 1
fi

if [ "$#" -eq 0 ] # if no arguments after command
then
echo "You must enter an argument" >&2
echo "USAGE: $0 [-i {input-path}]" >&2
exit 2
fi

outputFlag="n"
while getopts i: name
do
case $name in
i) inputFile=$OPTARG ;;
:) echo "Error: You need text after options requiring text"
exit 1 ;;
?) echo "Error: Incorrect option"
exit 1 ;;
esac
done

if [ ! -f $inputFile ]
then
echo "The file pathname "$inputFile" is empty or does not exist" >&2
exit 2
fi

set $(sed 's/ /+/g' $inputFile) # temporarily convert spaces to + for storing lines as positional parameters

for x
do
userPassWd=$(date | md5sum | cut -d" " -f1)
useradd -m -c "$(echo $x | cut -d":" -f2 | sed 's/+/ /g')" -p $userPassWd $(echo $x | cut -d":" -f1)
mail -s "Server Account Information" $(echo $x | cut -d":" -f3) <<+
Here is your server account information:
servername: placeholder.servername.on.ca
username: $(echo $x | cut -d":" -f1)
password: $userPassWd
Regards,
IT Department
+
done

echo -e "nnAccounts have been creatednn"
exit 0


Here is are contents of the input file:



msaul:Murray Edward Saul:msaul@placeholder.on.ca
dward:David Ward:dward@placeholder.on.ca
eweaver:Evan Weaver:eweaver@placeholder.on.ca
sapted:Scott Apted:sapted@placeholder.on.ca









share|improve this question









New contributor




user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • wow this website does not like actual code...

    – user337809
    3 hours ago











  • if you would like to help and want the code in a usable state then please contact me at ds2000@mail.com

    – user337809
    3 hours ago











  • Edit your question and click on the "?" in the upper right corner.

    – Freddy
    3 hours ago






  • 1





    Use the {} formatting tool instead of individual backtick lines. Paste the script, select it all, then click the {} button.

    – Jeff Schaller
    2 hours ago











  • which of the two sed does it stop at?

    – Jeff Schaller
    2 hours ago
















0















I have this bash script in CentOS 7 that creates users using a text document as input, the text document has 3 fields separated by colons; username:full name:email
The problem is that the script runs but it never finishes and according to the bash -x debug, it gets at least as far as the sed command but goes no further. The syntax used to run the script is script-name argument(input-file)



Here is the script in question:



#!/bin/bash

if [ $USER != "root" ]
then
echo "Note: You are required to run this program as root."
exit 1
fi

if [ "$#" -eq 0 ] # if no arguments after command
then
echo "You must enter an argument" >&2
echo "USAGE: $0 [-i {input-path}]" >&2
exit 2
fi

outputFlag="n"
while getopts i: name
do
case $name in
i) inputFile=$OPTARG ;;
:) echo "Error: You need text after options requiring text"
exit 1 ;;
?) echo "Error: Incorrect option"
exit 1 ;;
esac
done

if [ ! -f $inputFile ]
then
echo "The file pathname "$inputFile" is empty or does not exist" >&2
exit 2
fi

set $(sed 's/ /+/g' $inputFile) # temporarily convert spaces to + for storing lines as positional parameters

for x
do
userPassWd=$(date | md5sum | cut -d" " -f1)
useradd -m -c "$(echo $x | cut -d":" -f2 | sed 's/+/ /g')" -p $userPassWd $(echo $x | cut -d":" -f1)
mail -s "Server Account Information" $(echo $x | cut -d":" -f3) <<+
Here is your server account information:
servername: placeholder.servername.on.ca
username: $(echo $x | cut -d":" -f1)
password: $userPassWd
Regards,
IT Department
+
done

echo -e "nnAccounts have been creatednn"
exit 0


Here is are contents of the input file:



msaul:Murray Edward Saul:msaul@placeholder.on.ca
dward:David Ward:dward@placeholder.on.ca
eweaver:Evan Weaver:eweaver@placeholder.on.ca
sapted:Scott Apted:sapted@placeholder.on.ca









share|improve this question









New contributor




user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • wow this website does not like actual code...

    – user337809
    3 hours ago











  • if you would like to help and want the code in a usable state then please contact me at ds2000@mail.com

    – user337809
    3 hours ago











  • Edit your question and click on the "?" in the upper right corner.

    – Freddy
    3 hours ago






  • 1





    Use the {} formatting tool instead of individual backtick lines. Paste the script, select it all, then click the {} button.

    – Jeff Schaller
    2 hours ago











  • which of the two sed does it stop at?

    – Jeff Schaller
    2 hours ago














0












0








0








I have this bash script in CentOS 7 that creates users using a text document as input, the text document has 3 fields separated by colons; username:full name:email
The problem is that the script runs but it never finishes and according to the bash -x debug, it gets at least as far as the sed command but goes no further. The syntax used to run the script is script-name argument(input-file)



Here is the script in question:



#!/bin/bash

if [ $USER != "root" ]
then
echo "Note: You are required to run this program as root."
exit 1
fi

if [ "$#" -eq 0 ] # if no arguments after command
then
echo "You must enter an argument" >&2
echo "USAGE: $0 [-i {input-path}]" >&2
exit 2
fi

outputFlag="n"
while getopts i: name
do
case $name in
i) inputFile=$OPTARG ;;
:) echo "Error: You need text after options requiring text"
exit 1 ;;
?) echo "Error: Incorrect option"
exit 1 ;;
esac
done

if [ ! -f $inputFile ]
then
echo "The file pathname "$inputFile" is empty or does not exist" >&2
exit 2
fi

set $(sed 's/ /+/g' $inputFile) # temporarily convert spaces to + for storing lines as positional parameters

for x
do
userPassWd=$(date | md5sum | cut -d" " -f1)
useradd -m -c "$(echo $x | cut -d":" -f2 | sed 's/+/ /g')" -p $userPassWd $(echo $x | cut -d":" -f1)
mail -s "Server Account Information" $(echo $x | cut -d":" -f3) <<+
Here is your server account information:
servername: placeholder.servername.on.ca
username: $(echo $x | cut -d":" -f1)
password: $userPassWd
Regards,
IT Department
+
done

echo -e "nnAccounts have been creatednn"
exit 0


Here is are contents of the input file:



msaul:Murray Edward Saul:msaul@placeholder.on.ca
dward:David Ward:dward@placeholder.on.ca
eweaver:Evan Weaver:eweaver@placeholder.on.ca
sapted:Scott Apted:sapted@placeholder.on.ca









share|improve this question









New contributor




user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I have this bash script in CentOS 7 that creates users using a text document as input, the text document has 3 fields separated by colons; username:full name:email
The problem is that the script runs but it never finishes and according to the bash -x debug, it gets at least as far as the sed command but goes no further. The syntax used to run the script is script-name argument(input-file)



Here is the script in question:



#!/bin/bash

if [ $USER != "root" ]
then
echo "Note: You are required to run this program as root."
exit 1
fi

if [ "$#" -eq 0 ] # if no arguments after command
then
echo "You must enter an argument" >&2
echo "USAGE: $0 [-i {input-path}]" >&2
exit 2
fi

outputFlag="n"
while getopts i: name
do
case $name in
i) inputFile=$OPTARG ;;
:) echo "Error: You need text after options requiring text"
exit 1 ;;
?) echo "Error: Incorrect option"
exit 1 ;;
esac
done

if [ ! -f $inputFile ]
then
echo "The file pathname "$inputFile" is empty or does not exist" >&2
exit 2
fi

set $(sed 's/ /+/g' $inputFile) # temporarily convert spaces to + for storing lines as positional parameters

for x
do
userPassWd=$(date | md5sum | cut -d" " -f1)
useradd -m -c "$(echo $x | cut -d":" -f2 | sed 's/+/ /g')" -p $userPassWd $(echo $x | cut -d":" -f1)
mail -s "Server Account Information" $(echo $x | cut -d":" -f3) <<+
Here is your server account information:
servername: placeholder.servername.on.ca
username: $(echo $x | cut -d":" -f1)
password: $userPassWd
Regards,
IT Department
+
done

echo -e "nnAccounts have been creatednn"
exit 0


Here is are contents of the input file:



msaul:Murray Edward Saul:msaul@placeholder.on.ca
dward:David Ward:dward@placeholder.on.ca
eweaver:Evan Weaver:eweaver@placeholder.on.ca
sapted:Scott Apted:sapted@placeholder.on.ca






shell-script centos






share|improve this question









New contributor




user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 hours ago









G-Man

13.1k93466




13.1k93466






New contributor




user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









user337809user337809

1




1




New contributor




user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user337809 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • wow this website does not like actual code...

    – user337809
    3 hours ago











  • if you would like to help and want the code in a usable state then please contact me at ds2000@mail.com

    – user337809
    3 hours ago











  • Edit your question and click on the "?" in the upper right corner.

    – Freddy
    3 hours ago






  • 1





    Use the {} formatting tool instead of individual backtick lines. Paste the script, select it all, then click the {} button.

    – Jeff Schaller
    2 hours ago











  • which of the two sed does it stop at?

    – Jeff Schaller
    2 hours ago



















  • wow this website does not like actual code...

    – user337809
    3 hours ago











  • if you would like to help and want the code in a usable state then please contact me at ds2000@mail.com

    – user337809
    3 hours ago











  • Edit your question and click on the "?" in the upper right corner.

    – Freddy
    3 hours ago






  • 1





    Use the {} formatting tool instead of individual backtick lines. Paste the script, select it all, then click the {} button.

    – Jeff Schaller
    2 hours ago











  • which of the two sed does it stop at?

    – Jeff Schaller
    2 hours ago

















wow this website does not like actual code...

– user337809
3 hours ago





wow this website does not like actual code...

– user337809
3 hours ago













if you would like to help and want the code in a usable state then please contact me at ds2000@mail.com

– user337809
3 hours ago





if you would like to help and want the code in a usable state then please contact me at ds2000@mail.com

– user337809
3 hours ago













Edit your question and click on the "?" in the upper right corner.

– Freddy
3 hours ago





Edit your question and click on the "?" in the upper right corner.

– Freddy
3 hours ago




1




1





Use the {} formatting tool instead of individual backtick lines. Paste the script, select it all, then click the {} button.

– Jeff Schaller
2 hours ago





Use the {} formatting tool instead of individual backtick lines. Paste the script, select it all, then click the {} button.

– Jeff Schaller
2 hours ago













which of the two sed does it stop at?

– Jeff Schaller
2 hours ago





which of the two sed does it stop at?

– Jeff Schaller
2 hours ago










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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
});


}
});






user337809 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501747%2fbash-script-gets-stuck-after-sed%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








user337809 is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















user337809 is a new contributor. Be nice, and check out our Code of Conduct.













user337809 is a new contributor. Be nice, and check out our Code of Conduct.












user337809 is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Unix & Linux 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.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501747%2fbash-script-gets-stuck-after-sed%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

濃尾地震

How to rewrite equation of hyperbola in standard form

No ethernet ip address in my vocore2