Shell script to display file systems which uses more than 90% disk usage












0















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.










share|improve this question









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 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
















0















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.










share|improve this question









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 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














0












0








0


2






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.










share|improve this question









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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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 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














  • 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








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










1 Answer
1






active

oldest

votes


















2














You have several mistakes.




  1. You have spaces before and after =

  2. You compare numbers with > you should use -gt

  3. You use brackets () in if


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





share|improve this answer





















  • 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











  • @Kusalananda, correct, will add some changes in to the script

    – Romeo Ninov
    Jan 9 at 7:45











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.










draft saved

draft discarded


















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









2














You have several mistakes.




  1. You have spaces before and after =

  2. You compare numbers with > you should use -gt

  3. You use brackets () in if


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





share|improve this answer





















  • 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











  • @Kusalananda, correct, will add some changes in to the script

    – Romeo Ninov
    Jan 9 at 7:45
















2














You have several mistakes.




  1. You have spaces before and after =

  2. You compare numbers with > you should use -gt

  3. You use brackets () in if


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





share|improve this answer





















  • 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











  • @Kusalananda, correct, will add some changes in to the script

    – Romeo Ninov
    Jan 9 at 7:45














2












2








2







You have several mistakes.




  1. You have spaces before and after =

  2. You compare numbers with > you should use -gt

  3. You use brackets () in if


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





share|improve this answer















You have several mistakes.




  1. You have spaces before and after =

  2. You compare numbers with > you should use -gt

  3. You use brackets () in if


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






share|improve this answer














share|improve this answer



share|improve this answer








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 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














  • 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











  • @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










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










draft saved

draft discarded


















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.




draft saved


draft discarded














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





















































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 make a Squid Proxy server?

第一次世界大戦

Touch on Surface Book