awk syntax error inside script while assigning it to a variable Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionrecursive search for a pattern, then for each match print out the specific SEQUENCE: line number, file name, and no file contentssyntax error in conditional expression while executing the shell script?awk syntax error unexpected new line or end of stringawk : syntax errorRounding a number in awkawk + set variable inside the awkSyntax error when i use ssh with awk over bcalter awk variable based on match inside awkAWK syntax errorAwk syntax, strange variable?
An isoperimetric-type inequality inside a cube
The test team as an enemy of development? And how can this be avoided?
Inverse square law not accurate for non-point masses?
How does the body cool itself in a stillsuit?
Simple Line in LaTeX Help!
How to resize main filesystem
Did pre-Columbian Americans know the spherical shape of the Earth?
Google .dev domain strangely redirects to https
Statistical analysis applied to methods coming out of Machine Learning
Why is there so little support for joining EFTA in the British parliament?
What should one know about term logic before studying propositional and predicate logic?
Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?
Marquee sign letters
How to name indistinguishable henchmen in a screenplay?
Pointing to problems without suggesting solutions
Weaponising the Grasp-at-a-Distance spell
How can I prevent/balance waiting and turtling as a response to cooldown mechanics
Where did Ptolemy compare the Earth to the distance of fixed stars?
Understanding piped commands in GNU/Linux
What are some likely causes to domain member PC losing contact to domain controller?
Why can't fire hurt Daenerys but it did to Jon Snow in season 1?
malloc in main() or malloc in another function: allocating memory for a struct and its members
New Order #6: Easter Egg
How do I find my Spellcasting Ability for my D&D character?
awk syntax error inside script while assigning it to a variable
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionrecursive search for a pattern, then for each match print out the specific SEQUENCE: line number, file name, and no file contentssyntax error in conditional expression while executing the shell script?awk syntax error unexpected new line or end of stringawk : syntax errorRounding a number in awkawk + set variable inside the awkSyntax error when i use ssh with awk over bcalter awk variable based on match inside awkAWK syntax errorAwk syntax, strange variable?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Basically memory is a variable. In a script, I am trying to remote login to one server and execute free command to check memory usage and using awk I'm getting the usage in percentage. But I am getting syntax error for the below.
memory=`ssh $line -n "free | grep Mem | awk ' print $3/$2 *100.0 '"`
echo -e "The memory usage is: $memory" >>$LOGFILE
Error is:
awk: print / *100.0
awk: ^ unterminated regexp
awk: cmd. line:1: print / *100.0
awk: cmd. line:1: ^ unexpected newline or end of string
awk
New contributor
add a comment |
Basically memory is a variable. In a script, I am trying to remote login to one server and execute free command to check memory usage and using awk I'm getting the usage in percentage. But I am getting syntax error for the below.
memory=`ssh $line -n "free | grep Mem | awk ' print $3/$2 *100.0 '"`
echo -e "The memory usage is: $memory" >>$LOGFILE
Error is:
awk: print / *100.0
awk: ^ unterminated regexp
awk: cmd. line:1: print / *100.0
awk: cmd. line:1: ^ unexpected newline or end of string
awk
New contributor
add a comment |
Basically memory is a variable. In a script, I am trying to remote login to one server and execute free command to check memory usage and using awk I'm getting the usage in percentage. But I am getting syntax error for the below.
memory=`ssh $line -n "free | grep Mem | awk ' print $3/$2 *100.0 '"`
echo -e "The memory usage is: $memory" >>$LOGFILE
Error is:
awk: print / *100.0
awk: ^ unterminated regexp
awk: cmd. line:1: print / *100.0
awk: cmd. line:1: ^ unexpected newline or end of string
awk
New contributor
Basically memory is a variable. In a script, I am trying to remote login to one server and execute free command to check memory usage and using awk I'm getting the usage in percentage. But I am getting syntax error for the below.
memory=`ssh $line -n "free | grep Mem | awk ' print $3/$2 *100.0 '"`
echo -e "The memory usage is: $memory" >>$LOGFILE
Error is:
awk: print / *100.0
awk: ^ unterminated regexp
awk: cmd. line:1: print / *100.0
awk: cmd. line:1: ^ unexpected newline or end of string
awk
awk
New contributor
New contributor
edited Apr 17 at 12:27
Rui F Ribeiro
42.2k1484142
42.2k1484142
New contributor
asked Apr 17 at 11:58
user347628user347628
61
61
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Problem is that $3
and $2
are substituted by the shell (with nothing when unassigned) before the command runs, because they are enclosed in double quotes.
The single quotes inside the double quotes don't prevent that:
$ echo "'$unassigned'"
''
You should escape the $
:
memory=$(ssh $line -n "free | awk '/Mem/ print $3/$2 *100.0 '")
Alternatively, you could run only free
on the server, and awk
on the client.
memory=$(ssh $line -n "free" | awk '/Mem/ print $3/$2 *100.0 ')
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/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
);
);
user347628 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');
);
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%2f512988%2fawk-syntax-error-inside-script-while-assigning-it-to-a-variable%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
Problem is that $3
and $2
are substituted by the shell (with nothing when unassigned) before the command runs, because they are enclosed in double quotes.
The single quotes inside the double quotes don't prevent that:
$ echo "'$unassigned'"
''
You should escape the $
:
memory=$(ssh $line -n "free | awk '/Mem/ print $3/$2 *100.0 '")
Alternatively, you could run only free
on the server, and awk
on the client.
memory=$(ssh $line -n "free" | awk '/Mem/ print $3/$2 *100.0 ')
add a comment |
Problem is that $3
and $2
are substituted by the shell (with nothing when unassigned) before the command runs, because they are enclosed in double quotes.
The single quotes inside the double quotes don't prevent that:
$ echo "'$unassigned'"
''
You should escape the $
:
memory=$(ssh $line -n "free | awk '/Mem/ print $3/$2 *100.0 '")
Alternatively, you could run only free
on the server, and awk
on the client.
memory=$(ssh $line -n "free" | awk '/Mem/ print $3/$2 *100.0 ')
add a comment |
Problem is that $3
and $2
are substituted by the shell (with nothing when unassigned) before the command runs, because they are enclosed in double quotes.
The single quotes inside the double quotes don't prevent that:
$ echo "'$unassigned'"
''
You should escape the $
:
memory=$(ssh $line -n "free | awk '/Mem/ print $3/$2 *100.0 '")
Alternatively, you could run only free
on the server, and awk
on the client.
memory=$(ssh $line -n "free" | awk '/Mem/ print $3/$2 *100.0 ')
Problem is that $3
and $2
are substituted by the shell (with nothing when unassigned) before the command runs, because they are enclosed in double quotes.
The single quotes inside the double quotes don't prevent that:
$ echo "'$unassigned'"
''
You should escape the $
:
memory=$(ssh $line -n "free | awk '/Mem/ print $3/$2 *100.0 '")
Alternatively, you could run only free
on the server, and awk
on the client.
memory=$(ssh $line -n "free" | awk '/Mem/ print $3/$2 *100.0 ')
edited Apr 17 at 12:46
answered Apr 17 at 12:25
RoVoRoVo
3,980317
3,980317
add a comment |
add a comment |
user347628 is a new contributor. Be nice, and check out our Code of Conduct.
user347628 is a new contributor. Be nice, and check out our Code of Conduct.
user347628 is a new contributor. Be nice, and check out our Code of Conduct.
user347628 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.
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%2f512988%2fawk-syntax-error-inside-script-while-assigning-it-to-a-variable%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