htop and crontab











up vote
0
down vote

favorite












I have a crontab like this for root user:



9 17 * * * TERM=xterm /bin/bash /root/htop_stat.sh


htop_stat.sh:



/usr/bin/echo q | /usr/bin/htop -C | /usr/bin/aha --line-fix | /usr/bin/html2text -width 999 | /usr/bin/grep --line-buffered -v "F1Help|xml version=" > /tmp/htop.txt


If I manually run htop_stat.sh as root, it works fine.



However, when the above cronjob kicks in, htop.txt only has the first 23 lines of htop's output.



Any idea?










share|improve this question






















  • Have you try to remove set of TERM in cron?
    – Romeo Ninov
    Nov 20 at 10:10










  • Yes, I actually started without and it would make /tmp/htop.txt empty because htop relies on the environment variable TERM. Thanks.
    – HCSF
    Nov 20 at 10:15










  • Have you consider using top, ps? htop by definition is "interactive process viewer"
    – Romeo Ninov
    Nov 20 at 10:19










  • htop gives me a bit more detail about all the processes. That's why I choose htop instead. And yes, htop is interactive. But what I don't get is, "bash htop_stat.sh > /tmp/htop.txt" works perfectly.
    – HCSF
    Nov 20 at 10:23










  • It work fine because when you open terminal you have TERM variable set. Which is not the case with cron. In your shell script exec something like: stty rows 50 cols 132 before the command and check the result
    – Romeo Ninov
    Nov 20 at 10:33















up vote
0
down vote

favorite












I have a crontab like this for root user:



9 17 * * * TERM=xterm /bin/bash /root/htop_stat.sh


htop_stat.sh:



/usr/bin/echo q | /usr/bin/htop -C | /usr/bin/aha --line-fix | /usr/bin/html2text -width 999 | /usr/bin/grep --line-buffered -v "F1Help|xml version=" > /tmp/htop.txt


If I manually run htop_stat.sh as root, it works fine.



However, when the above cronjob kicks in, htop.txt only has the first 23 lines of htop's output.



Any idea?










share|improve this question






















  • Have you try to remove set of TERM in cron?
    – Romeo Ninov
    Nov 20 at 10:10










  • Yes, I actually started without and it would make /tmp/htop.txt empty because htop relies on the environment variable TERM. Thanks.
    – HCSF
    Nov 20 at 10:15










  • Have you consider using top, ps? htop by definition is "interactive process viewer"
    – Romeo Ninov
    Nov 20 at 10:19










  • htop gives me a bit more detail about all the processes. That's why I choose htop instead. And yes, htop is interactive. But what I don't get is, "bash htop_stat.sh > /tmp/htop.txt" works perfectly.
    – HCSF
    Nov 20 at 10:23










  • It work fine because when you open terminal you have TERM variable set. Which is not the case with cron. In your shell script exec something like: stty rows 50 cols 132 before the command and check the result
    – Romeo Ninov
    Nov 20 at 10:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a crontab like this for root user:



9 17 * * * TERM=xterm /bin/bash /root/htop_stat.sh


htop_stat.sh:



/usr/bin/echo q | /usr/bin/htop -C | /usr/bin/aha --line-fix | /usr/bin/html2text -width 999 | /usr/bin/grep --line-buffered -v "F1Help|xml version=" > /tmp/htop.txt


If I manually run htop_stat.sh as root, it works fine.



However, when the above cronjob kicks in, htop.txt only has the first 23 lines of htop's output.



Any idea?










share|improve this question













I have a crontab like this for root user:



9 17 * * * TERM=xterm /bin/bash /root/htop_stat.sh


htop_stat.sh:



/usr/bin/echo q | /usr/bin/htop -C | /usr/bin/aha --line-fix | /usr/bin/html2text -width 999 | /usr/bin/grep --line-buffered -v "F1Help|xml version=" > /tmp/htop.txt


If I manually run htop_stat.sh as root, it works fine.



However, when the above cronjob kicks in, htop.txt only has the first 23 lines of htop's output.



Any idea?







terminal cron xterm htop






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 9:57









HCSF

256




256












  • Have you try to remove set of TERM in cron?
    – Romeo Ninov
    Nov 20 at 10:10










  • Yes, I actually started without and it would make /tmp/htop.txt empty because htop relies on the environment variable TERM. Thanks.
    – HCSF
    Nov 20 at 10:15










  • Have you consider using top, ps? htop by definition is "interactive process viewer"
    – Romeo Ninov
    Nov 20 at 10:19










  • htop gives me a bit more detail about all the processes. That's why I choose htop instead. And yes, htop is interactive. But what I don't get is, "bash htop_stat.sh > /tmp/htop.txt" works perfectly.
    – HCSF
    Nov 20 at 10:23










  • It work fine because when you open terminal you have TERM variable set. Which is not the case with cron. In your shell script exec something like: stty rows 50 cols 132 before the command and check the result
    – Romeo Ninov
    Nov 20 at 10:33


















  • Have you try to remove set of TERM in cron?
    – Romeo Ninov
    Nov 20 at 10:10










  • Yes, I actually started without and it would make /tmp/htop.txt empty because htop relies on the environment variable TERM. Thanks.
    – HCSF
    Nov 20 at 10:15










  • Have you consider using top, ps? htop by definition is "interactive process viewer"
    – Romeo Ninov
    Nov 20 at 10:19










  • htop gives me a bit more detail about all the processes. That's why I choose htop instead. And yes, htop is interactive. But what I don't get is, "bash htop_stat.sh > /tmp/htop.txt" works perfectly.
    – HCSF
    Nov 20 at 10:23










  • It work fine because when you open terminal you have TERM variable set. Which is not the case with cron. In your shell script exec something like: stty rows 50 cols 132 before the command and check the result
    – Romeo Ninov
    Nov 20 at 10:33
















Have you try to remove set of TERM in cron?
– Romeo Ninov
Nov 20 at 10:10




Have you try to remove set of TERM in cron?
– Romeo Ninov
Nov 20 at 10:10












Yes, I actually started without and it would make /tmp/htop.txt empty because htop relies on the environment variable TERM. Thanks.
– HCSF
Nov 20 at 10:15




Yes, I actually started without and it would make /tmp/htop.txt empty because htop relies on the environment variable TERM. Thanks.
– HCSF
Nov 20 at 10:15












Have you consider using top, ps? htop by definition is "interactive process viewer"
– Romeo Ninov
Nov 20 at 10:19




Have you consider using top, ps? htop by definition is "interactive process viewer"
– Romeo Ninov
Nov 20 at 10:19












htop gives me a bit more detail about all the processes. That's why I choose htop instead. And yes, htop is interactive. But what I don't get is, "bash htop_stat.sh > /tmp/htop.txt" works perfectly.
– HCSF
Nov 20 at 10:23




htop gives me a bit more detail about all the processes. That's why I choose htop instead. And yes, htop is interactive. But what I don't get is, "bash htop_stat.sh > /tmp/htop.txt" works perfectly.
– HCSF
Nov 20 at 10:23












It work fine because when you open terminal you have TERM variable set. Which is not the case with cron. In your shell script exec something like: stty rows 50 cols 132 before the command and check the result
– Romeo Ninov
Nov 20 at 10:33




It work fine because when you open terminal you have TERM variable set. Which is not the case with cron. In your shell script exec something like: stty rows 50 cols 132 before the command and check the result
– Romeo Ninov
Nov 20 at 10:33










1 Answer
1






active

oldest

votes

















up vote
1
down vote













The prefix TERM=xterm is not allowed for a cron command, it is not a shell prompt.



Either put it as a separate line in the crontab file:



TERM=xterm
9 17 * * * /bin/bash /root/htop_stat.sh


or include it in your htop_stat.sh.



See man 5 crontab for details.






share|improve this answer





















  • Thanks! You are indeed right that environment variable should be in a separate line per manpage. Tho, it is weird that putting in a separate line also has the same result as putting it in the same line preceding to the command.
    – HCSF
    Nov 20 at 14:27










  • I think why environment variable can be set preceding my script. link
    – HCSF
    Nov 21 at 1:46











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',
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
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482923%2fhtop-and-crontab%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








up vote
1
down vote













The prefix TERM=xterm is not allowed for a cron command, it is not a shell prompt.



Either put it as a separate line in the crontab file:



TERM=xterm
9 17 * * * /bin/bash /root/htop_stat.sh


or include it in your htop_stat.sh.



See man 5 crontab for details.






share|improve this answer





















  • Thanks! You are indeed right that environment variable should be in a separate line per manpage. Tho, it is weird that putting in a separate line also has the same result as putting it in the same line preceding to the command.
    – HCSF
    Nov 20 at 14:27










  • I think why environment variable can be set preceding my script. link
    – HCSF
    Nov 21 at 1:46















up vote
1
down vote













The prefix TERM=xterm is not allowed for a cron command, it is not a shell prompt.



Either put it as a separate line in the crontab file:



TERM=xterm
9 17 * * * /bin/bash /root/htop_stat.sh


or include it in your htop_stat.sh.



See man 5 crontab for details.






share|improve this answer





















  • Thanks! You are indeed right that environment variable should be in a separate line per manpage. Tho, it is weird that putting in a separate line also has the same result as putting it in the same line preceding to the command.
    – HCSF
    Nov 20 at 14:27










  • I think why environment variable can be set preceding my script. link
    – HCSF
    Nov 21 at 1:46













up vote
1
down vote










up vote
1
down vote









The prefix TERM=xterm is not allowed for a cron command, it is not a shell prompt.



Either put it as a separate line in the crontab file:



TERM=xterm
9 17 * * * /bin/bash /root/htop_stat.sh


or include it in your htop_stat.sh.



See man 5 crontab for details.






share|improve this answer












The prefix TERM=xterm is not allowed for a cron command, it is not a shell prompt.



Either put it as a separate line in the crontab file:



TERM=xterm
9 17 * * * /bin/bash /root/htop_stat.sh


or include it in your htop_stat.sh.



See man 5 crontab for details.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 10:35









nst0022

2412




2412












  • Thanks! You are indeed right that environment variable should be in a separate line per manpage. Tho, it is weird that putting in a separate line also has the same result as putting it in the same line preceding to the command.
    – HCSF
    Nov 20 at 14:27










  • I think why environment variable can be set preceding my script. link
    – HCSF
    Nov 21 at 1:46


















  • Thanks! You are indeed right that environment variable should be in a separate line per manpage. Tho, it is weird that putting in a separate line also has the same result as putting it in the same line preceding to the command.
    – HCSF
    Nov 20 at 14:27










  • I think why environment variable can be set preceding my script. link
    – HCSF
    Nov 21 at 1:46
















Thanks! You are indeed right that environment variable should be in a separate line per manpage. Tho, it is weird that putting in a separate line also has the same result as putting it in the same line preceding to the command.
– HCSF
Nov 20 at 14:27




Thanks! You are indeed right that environment variable should be in a separate line per manpage. Tho, it is weird that putting in a separate line also has the same result as putting it in the same line preceding to the command.
– HCSF
Nov 20 at 14:27












I think why environment variable can be set preceding my script. link
– HCSF
Nov 21 at 1:46




I think why environment variable can be set preceding my script. link
– HCSF
Nov 21 at 1:46


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482923%2fhtop-and-crontab%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

List directoties down one level, excluding some named directories and files

list processes belonging to a network namespace

list systemd RuntimeDirectory mounts