Shell script to display file systems which uses more than 90% disk usage
df -h | awk '{ print $5 " " $1 }' > sample.txt
while read -r line;
do
echo $line
var1 = $( echo $line | cut -d "%" -f5 )
if [[ ( var1 > 90 ) ]]
then
echo $line sample1.txt
fi
done < sample.txt
main.ksh[6]: var1: not found [No such file or directory] I am getting this error.
I need to run this script.
shell-script
New contributor
user330543 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 |
df -h | awk '{ print $5 " " $1 }' > sample.txt
while read -r line;
do
echo $line
var1 = $( echo $line | cut -d "%" -f5 )
if [[ ( var1 > 90 ) ]]
then
echo $line sample1.txt
fi
done < sample.txt
main.ksh[6]: var1: not found [No such file or directory] I am getting this error.
I need to run this script.
shell-script
New contributor
user330543 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
A simpel solution?df -h | awk 'NR>1 && $5+0 >= 90`
– Valentin Bajrami
Jan 9 at 7:36
1
What's your intention withecho $line sample1.txt?
– Kusalananda
Jan 9 at 7:38
1
Please review your code in shellcheck.net it contains several errors.
– Isaac
Jan 9 at 8:03
add a comment |
df -h | awk '{ print $5 " " $1 }' > sample.txt
while read -r line;
do
echo $line
var1 = $( echo $line | cut -d "%" -f5 )
if [[ ( var1 > 90 ) ]]
then
echo $line sample1.txt
fi
done < sample.txt
main.ksh[6]: var1: not found [No such file or directory] I am getting this error.
I need to run this script.
shell-script
New contributor
user330543 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
df -h | awk '{ print $5 " " $1 }' > sample.txt
while read -r line;
do
echo $line
var1 = $( echo $line | cut -d "%" -f5 )
if [[ ( var1 > 90 ) ]]
then
echo $line sample1.txt
fi
done < sample.txt
main.ksh[6]: var1: not found [No such file or directory] I am getting this error.
I need to run this script.
shell-script
shell-script
New contributor
user330543 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user330543 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
Rui F Ribeiro
39.4k1479131
39.4k1479131
New contributor
user330543 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Jan 9 at 7:23
user330543user330543
1
1
New contributor
user330543 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user330543 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
user330543 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
A simpel solution?df -h | awk 'NR>1 && $5+0 >= 90`
– Valentin Bajrami
Jan 9 at 7:36
1
What's your intention withecho $line sample1.txt?
– Kusalananda
Jan 9 at 7:38
1
Please review your code in shellcheck.net it contains several errors.
– Isaac
Jan 9 at 8:03
add a comment |
2
A simpel solution?df -h | awk 'NR>1 && $5+0 >= 90`
– Valentin Bajrami
Jan 9 at 7:36
1
What's your intention withecho $line sample1.txt?
– Kusalananda
Jan 9 at 7:38
1
Please review your code in shellcheck.net it contains several errors.
– Isaac
Jan 9 at 8:03
2
2
A simpel solution?
df -h | awk 'NR>1 && $5+0 >= 90 `– Valentin Bajrami
Jan 9 at 7:36
A simpel solution?
df -h | awk 'NR>1 && $5+0 >= 90 `– Valentin Bajrami
Jan 9 at 7:36
1
1
What's your intention with
echo $line sample1.txt?– Kusalananda
Jan 9 at 7:38
What's your intention with
echo $line sample1.txt?– Kusalananda
Jan 9 at 7:38
1
1
Please review your code in shellcheck.net it contains several errors.
– Isaac
Jan 9 at 8:03
Please review your code in shellcheck.net it contains several errors.
– Isaac
Jan 9 at 8:03
add a comment |
1 Answer
1
active
oldest
votes
You have several mistakes.
- You have spaces before and after
=
- You compare numbers with
>you should use-gt
- You use brackets
()inif
Use this way:
df -h | awk '{ print $5 , $1 }' > sample.txt
while read -r line;
do
echo $line
var1=$( echo $line | cut -d "%" -f5 )
if [[ "$var1" -gt 90 ]]
then
echo $line sample1.txt
fi
done < sample.txt
2
Also, concatenating fields with an explicit space inawkis not needed if one uses the defaultOFSvalue. Use of unquoted variable expansions is bad. The output filesample.txtseems unneeded. The whole script could be replaced by a one-liner. No comment on these things?
– Kusalananda
Jan 9 at 7:40
@Kusalananda, correct, will add some changes in to the script
– Romeo Ninov
Jan 9 at 7:45
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
});
}
});
user330543 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%2f493400%2fshell-script-to-display-file-systems-which-uses-more-than-90-disk-usage%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
You have several mistakes.
- You have spaces before and after
=
- You compare numbers with
>you should use-gt
- You use brackets
()inif
Use this way:
df -h | awk '{ print $5 , $1 }' > sample.txt
while read -r line;
do
echo $line
var1=$( echo $line | cut -d "%" -f5 )
if [[ "$var1" -gt 90 ]]
then
echo $line sample1.txt
fi
done < sample.txt
2
Also, concatenating fields with an explicit space inawkis not needed if one uses the defaultOFSvalue. Use of unquoted variable expansions is bad. The output filesample.txtseems unneeded. The whole script could be replaced by a one-liner. No comment on these things?
– Kusalananda
Jan 9 at 7:40
@Kusalananda, correct, will add some changes in to the script
– Romeo Ninov
Jan 9 at 7:45
add a comment |
You have several mistakes.
- You have spaces before and after
=
- You compare numbers with
>you should use-gt
- You use brackets
()inif
Use this way:
df -h | awk '{ print $5 , $1 }' > sample.txt
while read -r line;
do
echo $line
var1=$( echo $line | cut -d "%" -f5 )
if [[ "$var1" -gt 90 ]]
then
echo $line sample1.txt
fi
done < sample.txt
2
Also, concatenating fields with an explicit space inawkis not needed if one uses the defaultOFSvalue. Use of unquoted variable expansions is bad. The output filesample.txtseems unneeded. The whole script could be replaced by a one-liner. No comment on these things?
– Kusalananda
Jan 9 at 7:40
@Kusalananda, correct, will add some changes in to the script
– Romeo Ninov
Jan 9 at 7:45
add a comment |
You have several mistakes.
- You have spaces before and after
=
- You compare numbers with
>you should use-gt
- You use brackets
()inif
Use this way:
df -h | awk '{ print $5 , $1 }' > sample.txt
while read -r line;
do
echo $line
var1=$( echo $line | cut -d "%" -f5 )
if [[ "$var1" -gt 90 ]]
then
echo $line sample1.txt
fi
done < sample.txt
You have several mistakes.
- You have spaces before and after
=
- You compare numbers with
>you should use-gt
- You use brackets
()inif
Use this way:
df -h | awk '{ print $5 , $1 }' > sample.txt
while read -r line;
do
echo $line
var1=$( echo $line | cut -d "%" -f5 )
if [[ "$var1" -gt 90 ]]
then
echo $line sample1.txt
fi
done < sample.txt
edited Jan 9 at 7:46
answered Jan 9 at 7:32
Romeo NinovRomeo Ninov
5,55831827
5,55831827
2
Also, concatenating fields with an explicit space inawkis not needed if one uses the defaultOFSvalue. Use of unquoted variable expansions is bad. The output filesample.txtseems unneeded. The whole script could be replaced by a one-liner. No comment on these things?
– Kusalananda
Jan 9 at 7:40
@Kusalananda, correct, will add some changes in to the script
– Romeo Ninov
Jan 9 at 7:45
add a comment |
2
Also, concatenating fields with an explicit space inawkis not needed if one uses the defaultOFSvalue. Use of unquoted variable expansions is bad. The output filesample.txtseems unneeded. The whole script could be replaced by a one-liner. No comment on these things?
– Kusalananda
Jan 9 at 7:40
@Kusalananda, correct, will add some changes in to the script
– Romeo Ninov
Jan 9 at 7:45
2
2
Also, concatenating fields with an explicit space in
awk is not needed if one uses the default OFS value. Use of unquoted variable expansions is bad. The output file sample.txt seems unneeded. The whole script could be replaced by a one-liner. No comment on these things?– Kusalananda
Jan 9 at 7:40
Also, concatenating fields with an explicit space in
awk is not needed if one uses the default OFS value. Use of unquoted variable expansions is bad. The output file sample.txt seems unneeded. The whole script could be replaced by a one-liner. No comment on these things?– Kusalananda
Jan 9 at 7:40
@Kusalananda, correct, will add some changes in to the script
– Romeo Ninov
Jan 9 at 7:45
@Kusalananda, correct, will add some changes in to the script
– Romeo Ninov
Jan 9 at 7:45
add a comment |
user330543 is a new contributor. Be nice, and check out our Code of Conduct.
user330543 is a new contributor. Be nice, and check out our Code of Conduct.
user330543 is a new contributor. Be nice, and check out our Code of Conduct.
user330543 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%2f493400%2fshell-script-to-display-file-systems-which-uses-more-than-90-disk-usage%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
2
A simpel solution?
df -h | awk 'NR>1 && $5+0 >= 90`– Valentin Bajrami
Jan 9 at 7:36
1
What's your intention with
echo $line sample1.txt?– Kusalananda
Jan 9 at 7:38
1
Please review your code in shellcheck.net it contains several errors.
– Isaac
Jan 9 at 8:03