Trying to copy/paste long script with multiple EOFs, Terminal starts running half-way throughHow to...
Car as a good investment
Moonlight bright enough to see by
How do I count the number of elements in a list which are between two determined values?
Should I avoid "big words" when writing to a younger audience?
How to balance combat for a duet campaign with non-frontliner classes?
Did I Traumatize My Puppy?
100% positive Glassdoor employee reviews, 100% negative candidate reviews
90's/00's anime about 3 girls who travel between the real world and a fantasy world
Does any politician honestly want a No Deal Brexit?
How can you tell apart the pronounciation at the end between the "meine" and "meiner" in the daily spoken situation?
How (and if) to include name change for transgender person in genealogy?
In the twin paradox does the returning twin also come back permanently length contracted flatter than the twin on earth?
How to deal with people whose priority is to not get blamed?
Proving the order of quaternion group is 8
Demod as a neologism
Idiom for a situation or event that makes one poor or even poorer?
How to increment the value of a (decimal) variable (with leading zero) by +1?
Why do military jets sometimes have elevators in a depressed position when parked?
Limiting sensor input voltage without biasing measurement
Why is my paper "under review" if it contains no results?
Do more Americans want the Bidens investigated than Trump impeached?
How does a ball bearing door hinge work?
Did Terry Pratchett ever explain the inspiration behind the Luggage?
Company indirectly discriminating against introverts, specifically INTJ
Trying to copy/paste long script with multiple EOFs, Terminal starts running half-way through
How to copy/paste in Gnome-TerminalCasperJS and PHP In Cron Job Cannot Open Files, Works Fine When Run ManualySystemd Service Script Not EchoingMaking an Extra Copy and Paste ScriptScript fails, but copy and paste from script worksDebian startup script doesn't startCopy/paste from terminal selection not workingWhile Loop Breaking Half Way Through File
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}
Was trying to create a text block that I could just copy and paste into a Terminal window to accomplish something (in this case, create a systemd script to do maintenance on MySQL dbs, create a timer file to run that script weekly, and to enable the script).
When pasting it into a Terminal, it displays half of the script (up until the first EOF), prompts for the password through read, and then copies the typed password, along with the rest of the script in the spot where $pass is in the first file.
This is the block:
sudo sync && echo 'Enter MySQL password for Maintenance user' && read pass && sudo bash -s -c 'cat > "/usr/lib/systemd/system/db-m.service"' << "EOF"
[Service]
Type=oneshot
ExecStart='/usr/bin/mysqlcheck' --auto-repair --optimize --all-databases --force -u'maintenance' -p'$pass'
ExecStart='/usr/bin/sync'
EOF
sudo bash -c 'cat > "/usr/lib/systemd/system/db-m.timer"' << EOF
[Unit]
Description=Weekly database repair and maintenance
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload && sudo systemctl enable 'db-m.timer' && sudo systemctl start 'db-m' 'db-m.timer' && sudo systemctl status 'db-m' -l
I recently added the "read pass" and the '$pass' variable that occurs 3 lines later; without those two things, I can copy and paste the entire block no problem.
bash command-line scripting clipboard
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment
|
Was trying to create a text block that I could just copy and paste into a Terminal window to accomplish something (in this case, create a systemd script to do maintenance on MySQL dbs, create a timer file to run that script weekly, and to enable the script).
When pasting it into a Terminal, it displays half of the script (up until the first EOF), prompts for the password through read, and then copies the typed password, along with the rest of the script in the spot where $pass is in the first file.
This is the block:
sudo sync && echo 'Enter MySQL password for Maintenance user' && read pass && sudo bash -s -c 'cat > "/usr/lib/systemd/system/db-m.service"' << "EOF"
[Service]
Type=oneshot
ExecStart='/usr/bin/mysqlcheck' --auto-repair --optimize --all-databases --force -u'maintenance' -p'$pass'
ExecStart='/usr/bin/sync'
EOF
sudo bash -c 'cat > "/usr/lib/systemd/system/db-m.timer"' << EOF
[Unit]
Description=Weekly database repair and maintenance
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload && sudo systemctl enable 'db-m.timer' && sudo systemctl start 'db-m' 'db-m.timer' && sudo systemctl status 'db-m' -l
I recently added the "read pass" and the '$pass' variable that occurs 3 lines later; without those two things, I can copy and paste the entire block no problem.
bash command-line scripting clipboard
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Copy & Paste is very desktop environment dependent action. Are you trying to do this copy and paste on a Linux desktop environment ? Likes of Gnome/KDE/Xfce etc. ? Or you are on a windows or Mac computer, using a terminal emulator ? In either case, details about your environment, such as name and version numbers, would be helpful.
– MelBurslan
Apr 28 '16 at 15:45
I'd useexpect, as that can enter one command, check and wait for the result, do the next command, etc. Pasting will run into all sorts of fun interactions depending on what reads or writes what when, buffer sizes, etc.
– thrig
Apr 28 '16 at 15:47
just to emphasise what @Gilles said:what you should do is put this in a script, with '#!/bin/sh' at the top. don't paste it directly into your shell.
– cas
Apr 29 '16 at 0:24
add a comment
|
Was trying to create a text block that I could just copy and paste into a Terminal window to accomplish something (in this case, create a systemd script to do maintenance on MySQL dbs, create a timer file to run that script weekly, and to enable the script).
When pasting it into a Terminal, it displays half of the script (up until the first EOF), prompts for the password through read, and then copies the typed password, along with the rest of the script in the spot where $pass is in the first file.
This is the block:
sudo sync && echo 'Enter MySQL password for Maintenance user' && read pass && sudo bash -s -c 'cat > "/usr/lib/systemd/system/db-m.service"' << "EOF"
[Service]
Type=oneshot
ExecStart='/usr/bin/mysqlcheck' --auto-repair --optimize --all-databases --force -u'maintenance' -p'$pass'
ExecStart='/usr/bin/sync'
EOF
sudo bash -c 'cat > "/usr/lib/systemd/system/db-m.timer"' << EOF
[Unit]
Description=Weekly database repair and maintenance
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload && sudo systemctl enable 'db-m.timer' && sudo systemctl start 'db-m' 'db-m.timer' && sudo systemctl status 'db-m' -l
I recently added the "read pass" and the '$pass' variable that occurs 3 lines later; without those two things, I can copy and paste the entire block no problem.
bash command-line scripting clipboard
Was trying to create a text block that I could just copy and paste into a Terminal window to accomplish something (in this case, create a systemd script to do maintenance on MySQL dbs, create a timer file to run that script weekly, and to enable the script).
When pasting it into a Terminal, it displays half of the script (up until the first EOF), prompts for the password through read, and then copies the typed password, along with the rest of the script in the spot where $pass is in the first file.
This is the block:
sudo sync && echo 'Enter MySQL password for Maintenance user' && read pass && sudo bash -s -c 'cat > "/usr/lib/systemd/system/db-m.service"' << "EOF"
[Service]
Type=oneshot
ExecStart='/usr/bin/mysqlcheck' --auto-repair --optimize --all-databases --force -u'maintenance' -p'$pass'
ExecStart='/usr/bin/sync'
EOF
sudo bash -c 'cat > "/usr/lib/systemd/system/db-m.timer"' << EOF
[Unit]
Description=Weekly database repair and maintenance
[Timer]
OnCalendar=weekly
Persistent=true
[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload && sudo systemctl enable 'db-m.timer' && sudo systemctl start 'db-m' 'db-m.timer' && sudo systemctl status 'db-m' -l
I recently added the "read pass" and the '$pass' variable that occurs 3 lines later; without those two things, I can copy and paste the entire block no problem.
bash command-line scripting clipboard
bash command-line scripting clipboard
edited Apr 28 '16 at 22:24
Gilles
579k141 gold badges1195 silver badges1708 bronze badges
579k141 gold badges1195 silver badges1708 bronze badges
asked Apr 28 '16 at 15:27
Espionage724Espionage724
61 bronze badge
61 bronze badge
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Copy & Paste is very desktop environment dependent action. Are you trying to do this copy and paste on a Linux desktop environment ? Likes of Gnome/KDE/Xfce etc. ? Or you are on a windows or Mac computer, using a terminal emulator ? In either case, details about your environment, such as name and version numbers, would be helpful.
– MelBurslan
Apr 28 '16 at 15:45
I'd useexpect, as that can enter one command, check and wait for the result, do the next command, etc. Pasting will run into all sorts of fun interactions depending on what reads or writes what when, buffer sizes, etc.
– thrig
Apr 28 '16 at 15:47
just to emphasise what @Gilles said:what you should do is put this in a script, with '#!/bin/sh' at the top. don't paste it directly into your shell.
– cas
Apr 29 '16 at 0:24
add a comment
|
Copy & Paste is very desktop environment dependent action. Are you trying to do this copy and paste on a Linux desktop environment ? Likes of Gnome/KDE/Xfce etc. ? Or you are on a windows or Mac computer, using a terminal emulator ? In either case, details about your environment, such as name and version numbers, would be helpful.
– MelBurslan
Apr 28 '16 at 15:45
I'd useexpect, as that can enter one command, check and wait for the result, do the next command, etc. Pasting will run into all sorts of fun interactions depending on what reads or writes what when, buffer sizes, etc.
– thrig
Apr 28 '16 at 15:47
just to emphasise what @Gilles said:what you should do is put this in a script, with '#!/bin/sh' at the top. don't paste it directly into your shell.
– cas
Apr 29 '16 at 0:24
Copy & Paste is very desktop environment dependent action. Are you trying to do this copy and paste on a Linux desktop environment ? Likes of Gnome/KDE/Xfce etc. ? Or you are on a windows or Mac computer, using a terminal emulator ? In either case, details about your environment, such as name and version numbers, would be helpful.
– MelBurslan
Apr 28 '16 at 15:45
Copy & Paste is very desktop environment dependent action. Are you trying to do this copy and paste on a Linux desktop environment ? Likes of Gnome/KDE/Xfce etc. ? Or you are on a windows or Mac computer, using a terminal emulator ? In either case, details about your environment, such as name and version numbers, would be helpful.
– MelBurslan
Apr 28 '16 at 15:45
I'd use
expect, as that can enter one command, check and wait for the result, do the next command, etc. Pasting will run into all sorts of fun interactions depending on what reads or writes what when, buffer sizes, etc.– thrig
Apr 28 '16 at 15:47
I'd use
expect, as that can enter one command, check and wait for the result, do the next command, etc. Pasting will run into all sorts of fun interactions depending on what reads or writes what when, buffer sizes, etc.– thrig
Apr 28 '16 at 15:47
just to emphasise what @Gilles said:
what you should do is put this in a script, with '#!/bin/sh' at the top. don't paste it directly into your shell.– cas
Apr 29 '16 at 0:24
just to emphasise what @Gilles said:
what you should do is put this in a script, with '#!/bin/sh' at the top. don't paste it directly into your shell.– cas
Apr 29 '16 at 0:24
add a comment
|
1 Answer
1
active
oldest
votes
The shell running in the terminal receives the script that you're pasting on its standard input, and your script itself reads from standard input. There's a conflict here: your script will end up reading a bit of itself.
If you don't get a sudo prompt, then what happens is:
- The shell reads whole lines until it has a complete command. The first line starts a here document, so the shell keeps reading the here document.
- When the shell reaches the first
EOFline, it has a complete command, so it executes it.
sudo syncand `echo '…' run.
read passruns. It reads a line of input, which issudo bash -c …. This setspass.
sudo syncruns.- The shell has finished executing the commands it had read, so it reads the next line of input which is
[Unit].
Don't paste complex multiline shell code into a terminal. Instead, if you really need to run the clipboard content as a shell script, use xsel or xclip under X11, or pbpaste on OSX.
eval "`xsel`"
eval "`xclip`"
eval "`pbpaste`"
But really, what you should do is put this in a script, with #!/bin/sh at the top.
Wouldntfc, orC-xC-ebe an easy solution to this problem?
– Steven Penny
May 7 '16 at 1:16
@StevenPenny Feels more cumbersome to me thaneval "`xsel`", but it does have the benefit (dubious, for a multiline command in bash) of entering the command in the history.
– Gilles
May 7 '16 at 10:48
shopt cmdhist/lithist?
– Steven Penny
May 7 '16 at 15:34
add a comment
|
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/4.0/"u003ecc by-sa 4.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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
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%2funix.stackexchange.com%2fquestions%2f279770%2ftrying-to-copy-paste-long-script-with-multiple-eofs-terminal-starts-running-hal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The shell running in the terminal receives the script that you're pasting on its standard input, and your script itself reads from standard input. There's a conflict here: your script will end up reading a bit of itself.
If you don't get a sudo prompt, then what happens is:
- The shell reads whole lines until it has a complete command. The first line starts a here document, so the shell keeps reading the here document.
- When the shell reaches the first
EOFline, it has a complete command, so it executes it.
sudo syncand `echo '…' run.
read passruns. It reads a line of input, which issudo bash -c …. This setspass.
sudo syncruns.- The shell has finished executing the commands it had read, so it reads the next line of input which is
[Unit].
Don't paste complex multiline shell code into a terminal. Instead, if you really need to run the clipboard content as a shell script, use xsel or xclip under X11, or pbpaste on OSX.
eval "`xsel`"
eval "`xclip`"
eval "`pbpaste`"
But really, what you should do is put this in a script, with #!/bin/sh at the top.
Wouldntfc, orC-xC-ebe an easy solution to this problem?
– Steven Penny
May 7 '16 at 1:16
@StevenPenny Feels more cumbersome to me thaneval "`xsel`", but it does have the benefit (dubious, for a multiline command in bash) of entering the command in the history.
– Gilles
May 7 '16 at 10:48
shopt cmdhist/lithist?
– Steven Penny
May 7 '16 at 15:34
add a comment
|
The shell running in the terminal receives the script that you're pasting on its standard input, and your script itself reads from standard input. There's a conflict here: your script will end up reading a bit of itself.
If you don't get a sudo prompt, then what happens is:
- The shell reads whole lines until it has a complete command. The first line starts a here document, so the shell keeps reading the here document.
- When the shell reaches the first
EOFline, it has a complete command, so it executes it.
sudo syncand `echo '…' run.
read passruns. It reads a line of input, which issudo bash -c …. This setspass.
sudo syncruns.- The shell has finished executing the commands it had read, so it reads the next line of input which is
[Unit].
Don't paste complex multiline shell code into a terminal. Instead, if you really need to run the clipboard content as a shell script, use xsel or xclip under X11, or pbpaste on OSX.
eval "`xsel`"
eval "`xclip`"
eval "`pbpaste`"
But really, what you should do is put this in a script, with #!/bin/sh at the top.
Wouldntfc, orC-xC-ebe an easy solution to this problem?
– Steven Penny
May 7 '16 at 1:16
@StevenPenny Feels more cumbersome to me thaneval "`xsel`", but it does have the benefit (dubious, for a multiline command in bash) of entering the command in the history.
– Gilles
May 7 '16 at 10:48
shopt cmdhist/lithist?
– Steven Penny
May 7 '16 at 15:34
add a comment
|
The shell running in the terminal receives the script that you're pasting on its standard input, and your script itself reads from standard input. There's a conflict here: your script will end up reading a bit of itself.
If you don't get a sudo prompt, then what happens is:
- The shell reads whole lines until it has a complete command. The first line starts a here document, so the shell keeps reading the here document.
- When the shell reaches the first
EOFline, it has a complete command, so it executes it.
sudo syncand `echo '…' run.
read passruns. It reads a line of input, which issudo bash -c …. This setspass.
sudo syncruns.- The shell has finished executing the commands it had read, so it reads the next line of input which is
[Unit].
Don't paste complex multiline shell code into a terminal. Instead, if you really need to run the clipboard content as a shell script, use xsel or xclip under X11, or pbpaste on OSX.
eval "`xsel`"
eval "`xclip`"
eval "`pbpaste`"
But really, what you should do is put this in a script, with #!/bin/sh at the top.
The shell running in the terminal receives the script that you're pasting on its standard input, and your script itself reads from standard input. There's a conflict here: your script will end up reading a bit of itself.
If you don't get a sudo prompt, then what happens is:
- The shell reads whole lines until it has a complete command. The first line starts a here document, so the shell keeps reading the here document.
- When the shell reaches the first
EOFline, it has a complete command, so it executes it.
sudo syncand `echo '…' run.
read passruns. It reads a line of input, which issudo bash -c …. This setspass.
sudo syncruns.- The shell has finished executing the commands it had read, so it reads the next line of input which is
[Unit].
Don't paste complex multiline shell code into a terminal. Instead, if you really need to run the clipboard content as a shell script, use xsel or xclip under X11, or pbpaste on OSX.
eval "`xsel`"
eval "`xclip`"
eval "`pbpaste`"
But really, what you should do is put this in a script, with #!/bin/sh at the top.
answered Apr 28 '16 at 22:46
GillesGilles
579k141 gold badges1195 silver badges1708 bronze badges
579k141 gold badges1195 silver badges1708 bronze badges
Wouldntfc, orC-xC-ebe an easy solution to this problem?
– Steven Penny
May 7 '16 at 1:16
@StevenPenny Feels more cumbersome to me thaneval "`xsel`", but it does have the benefit (dubious, for a multiline command in bash) of entering the command in the history.
– Gilles
May 7 '16 at 10:48
shopt cmdhist/lithist?
– Steven Penny
May 7 '16 at 15:34
add a comment
|
Wouldntfc, orC-xC-ebe an easy solution to this problem?
– Steven Penny
May 7 '16 at 1:16
@StevenPenny Feels more cumbersome to me thaneval "`xsel`", but it does have the benefit (dubious, for a multiline command in bash) of entering the command in the history.
– Gilles
May 7 '16 at 10:48
shopt cmdhist/lithist?
– Steven Penny
May 7 '16 at 15:34
Wouldnt
fc, or C-xC-e be an easy solution to this problem?– Steven Penny
May 7 '16 at 1:16
Wouldnt
fc, or C-xC-e be an easy solution to this problem?– Steven Penny
May 7 '16 at 1:16
@StevenPenny Feels more cumbersome to me than
eval "`xsel`", but it does have the benefit (dubious, for a multiline command in bash) of entering the command in the history.– Gilles
May 7 '16 at 10:48
@StevenPenny Feels more cumbersome to me than
eval "`xsel`", but it does have the benefit (dubious, for a multiline command in bash) of entering the command in the history.– Gilles
May 7 '16 at 10:48
shopt cmdhist/lithist?– Steven Penny
May 7 '16 at 15:34
shopt cmdhist/lithist?– Steven Penny
May 7 '16 at 15:34
add a comment
|
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
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%2funix.stackexchange.com%2fquestions%2f279770%2ftrying-to-copy-paste-long-script-with-multiple-eofs-terminal-starts-running-hal%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');
});
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');
});
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');
});
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
Copy & Paste is very desktop environment dependent action. Are you trying to do this copy and paste on a Linux desktop environment ? Likes of Gnome/KDE/Xfce etc. ? Or you are on a windows or Mac computer, using a terminal emulator ? In either case, details about your environment, such as name and version numbers, would be helpful.
– MelBurslan
Apr 28 '16 at 15:45
I'd use
expect, as that can enter one command, check and wait for the result, do the next command, etc. Pasting will run into all sorts of fun interactions depending on what reads or writes what when, buffer sizes, etc.– thrig
Apr 28 '16 at 15:47
just to emphasise what @Gilles said:
what you should do is put this in a script, with '#!/bin/sh' at the top. don't paste it directly into your shell.– cas
Apr 29 '16 at 0:24