Why the command in .bash_logout can't run after reboot?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Os : debian9.

Create a log file.



touch $HOME/logout.log


Add a command in .bash_logout.



vim .bash_logout
echo $(date) >> $HOME/logout.log


Now login with account name test,and create /home/test/logout.log.



I want to write date info in /home/test/logout.log,why no date info after reboot?

Nothing in /home/test/logout.log after reboot.







share|improve this question


















  • 1




    You need to be logged in to a user, then when you logout this file gets executed. Hence the name bash_logout. Can you specify exactly when you want echo $(date) to be executed? Also you can just do date >> $HOME/logout.log
    – Hunter.S.Thompson
    Jan 31 at 13:30











  • At reboot to write time info into $HOME/logout.log.
    – scrapy
    Jan 31 at 13:35











  • date >> $HOME/logout.log is enough.
    – Tomasz
    Jan 31 at 13:42














up vote
1
down vote

favorite












Os : debian9.

Create a log file.



touch $HOME/logout.log


Add a command in .bash_logout.



vim .bash_logout
echo $(date) >> $HOME/logout.log


Now login with account name test,and create /home/test/logout.log.



I want to write date info in /home/test/logout.log,why no date info after reboot?

Nothing in /home/test/logout.log after reboot.







share|improve this question


















  • 1




    You need to be logged in to a user, then when you logout this file gets executed. Hence the name bash_logout. Can you specify exactly when you want echo $(date) to be executed? Also you can just do date >> $HOME/logout.log
    – Hunter.S.Thompson
    Jan 31 at 13:30











  • At reboot to write time info into $HOME/logout.log.
    – scrapy
    Jan 31 at 13:35











  • date >> $HOME/logout.log is enough.
    – Tomasz
    Jan 31 at 13:42












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Os : debian9.

Create a log file.



touch $HOME/logout.log


Add a command in .bash_logout.



vim .bash_logout
echo $(date) >> $HOME/logout.log


Now login with account name test,and create /home/test/logout.log.



I want to write date info in /home/test/logout.log,why no date info after reboot?

Nothing in /home/test/logout.log after reboot.







share|improve this question














Os : debian9.

Create a log file.



touch $HOME/logout.log


Add a command in .bash_logout.



vim .bash_logout
echo $(date) >> $HOME/logout.log


Now login with account name test,and create /home/test/logout.log.



I want to write date info in /home/test/logout.log,why no date info after reboot?

Nothing in /home/test/logout.log after reboot.









share|improve this question













share|improve this question




share|improve this question








edited Jan 31 at 13:44

























asked Jan 31 at 13:27









scrapy

317213




317213







  • 1




    You need to be logged in to a user, then when you logout this file gets executed. Hence the name bash_logout. Can you specify exactly when you want echo $(date) to be executed? Also you can just do date >> $HOME/logout.log
    – Hunter.S.Thompson
    Jan 31 at 13:30











  • At reboot to write time info into $HOME/logout.log.
    – scrapy
    Jan 31 at 13:35











  • date >> $HOME/logout.log is enough.
    – Tomasz
    Jan 31 at 13:42












  • 1




    You need to be logged in to a user, then when you logout this file gets executed. Hence the name bash_logout. Can you specify exactly when you want echo $(date) to be executed? Also you can just do date >> $HOME/logout.log
    – Hunter.S.Thompson
    Jan 31 at 13:30











  • At reboot to write time info into $HOME/logout.log.
    – scrapy
    Jan 31 at 13:35











  • date >> $HOME/logout.log is enough.
    – Tomasz
    Jan 31 at 13:42







1




1




You need to be logged in to a user, then when you logout this file gets executed. Hence the name bash_logout. Can you specify exactly when you want echo $(date) to be executed? Also you can just do date >> $HOME/logout.log
– Hunter.S.Thompson
Jan 31 at 13:30





You need to be logged in to a user, then when you logout this file gets executed. Hence the name bash_logout. Can you specify exactly when you want echo $(date) to be executed? Also you can just do date >> $HOME/logout.log
– Hunter.S.Thompson
Jan 31 at 13:30













At reboot to write time info into $HOME/logout.log.
– scrapy
Jan 31 at 13:35





At reboot to write time info into $HOME/logout.log.
– scrapy
Jan 31 at 13:35













date >> $HOME/logout.log is enough.
– Tomasz
Jan 31 at 13:42




date >> $HOME/logout.log is enough.
– Tomasz
Jan 31 at 13:42










2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










first



echo $(date) >> $HOME/logout.log


can be replace by



date >> $HOME/logout.log


next,



.bash_logout is run when you disconnect, not when there is a reboot.



  • A reboot is when you restart host, effectively killing (more or less nicely) all it process, database, webserver and so on.


  • A logout is when you (or any user) disconnect from interactive session, the host stay up, as well as database and the like.


If you want script to be executed during a schedule shutdown, place then in /etc/init.d , then have a link like K01-trace-logout in /etc/rcX.d where X is your run-level (result of who -r).



finaly



Be aware that unexpected shutdown (power outage, disk I/O freezing) will leave no trace in log file.






share|improve this answer




















  • I have a question, would $HOME in this case be /root or would it be the the home directory of the user who initiates the reboot, assuming the script is in /etc/rc6.d.
    – Hunter.S.Thompson
    Jan 31 at 14:03










  • @Hunter.S.Thompson No, unless you have way to trap which user start shutdown (by way of sudo for instance)...
    – Archemar
    Jan 31 at 14:06

















up vote
1
down vote













You need to run bash as login shell. You need to login as the user and when you log-out from the interactive login shell - the .bash_logout script will be executed.






share|improve this answer




















  • Command in .bash_logout execute in login shell ,most of time i'm in non-login shell (graphic mode).
    – scrapy
    Jan 31 at 14:06










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: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f420951%2fwhy-the-command-in-bash-logout-cant-run-after-reboot%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










first



echo $(date) >> $HOME/logout.log


can be replace by



date >> $HOME/logout.log


next,



.bash_logout is run when you disconnect, not when there is a reboot.



  • A reboot is when you restart host, effectively killing (more or less nicely) all it process, database, webserver and so on.


  • A logout is when you (or any user) disconnect from interactive session, the host stay up, as well as database and the like.


If you want script to be executed during a schedule shutdown, place then in /etc/init.d , then have a link like K01-trace-logout in /etc/rcX.d where X is your run-level (result of who -r).



finaly



Be aware that unexpected shutdown (power outage, disk I/O freezing) will leave no trace in log file.






share|improve this answer




















  • I have a question, would $HOME in this case be /root or would it be the the home directory of the user who initiates the reboot, assuming the script is in /etc/rc6.d.
    – Hunter.S.Thompson
    Jan 31 at 14:03










  • @Hunter.S.Thompson No, unless you have way to trap which user start shutdown (by way of sudo for instance)...
    – Archemar
    Jan 31 at 14:06














up vote
3
down vote



accepted










first



echo $(date) >> $HOME/logout.log


can be replace by



date >> $HOME/logout.log


next,



.bash_logout is run when you disconnect, not when there is a reboot.



  • A reboot is when you restart host, effectively killing (more or less nicely) all it process, database, webserver and so on.


  • A logout is when you (or any user) disconnect from interactive session, the host stay up, as well as database and the like.


If you want script to be executed during a schedule shutdown, place then in /etc/init.d , then have a link like K01-trace-logout in /etc/rcX.d where X is your run-level (result of who -r).



finaly



Be aware that unexpected shutdown (power outage, disk I/O freezing) will leave no trace in log file.






share|improve this answer




















  • I have a question, would $HOME in this case be /root or would it be the the home directory of the user who initiates the reboot, assuming the script is in /etc/rc6.d.
    – Hunter.S.Thompson
    Jan 31 at 14:03










  • @Hunter.S.Thompson No, unless you have way to trap which user start shutdown (by way of sudo for instance)...
    – Archemar
    Jan 31 at 14:06












up vote
3
down vote



accepted







up vote
3
down vote



accepted






first



echo $(date) >> $HOME/logout.log


can be replace by



date >> $HOME/logout.log


next,



.bash_logout is run when you disconnect, not when there is a reboot.



  • A reboot is when you restart host, effectively killing (more or less nicely) all it process, database, webserver and so on.


  • A logout is when you (or any user) disconnect from interactive session, the host stay up, as well as database and the like.


If you want script to be executed during a schedule shutdown, place then in /etc/init.d , then have a link like K01-trace-logout in /etc/rcX.d where X is your run-level (result of who -r).



finaly



Be aware that unexpected shutdown (power outage, disk I/O freezing) will leave no trace in log file.






share|improve this answer












first



echo $(date) >> $HOME/logout.log


can be replace by



date >> $HOME/logout.log


next,



.bash_logout is run when you disconnect, not when there is a reboot.



  • A reboot is when you restart host, effectively killing (more or less nicely) all it process, database, webserver and so on.


  • A logout is when you (or any user) disconnect from interactive session, the host stay up, as well as database and the like.


If you want script to be executed during a schedule shutdown, place then in /etc/init.d , then have a link like K01-trace-logout in /etc/rcX.d where X is your run-level (result of who -r).



finaly



Be aware that unexpected shutdown (power outage, disk I/O freezing) will leave no trace in log file.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 31 at 13:46









Archemar

19k93366




19k93366











  • I have a question, would $HOME in this case be /root or would it be the the home directory of the user who initiates the reboot, assuming the script is in /etc/rc6.d.
    – Hunter.S.Thompson
    Jan 31 at 14:03










  • @Hunter.S.Thompson No, unless you have way to trap which user start shutdown (by way of sudo for instance)...
    – Archemar
    Jan 31 at 14:06
















  • I have a question, would $HOME in this case be /root or would it be the the home directory of the user who initiates the reboot, assuming the script is in /etc/rc6.d.
    – Hunter.S.Thompson
    Jan 31 at 14:03










  • @Hunter.S.Thompson No, unless you have way to trap which user start shutdown (by way of sudo for instance)...
    – Archemar
    Jan 31 at 14:06















I have a question, would $HOME in this case be /root or would it be the the home directory of the user who initiates the reboot, assuming the script is in /etc/rc6.d.
– Hunter.S.Thompson
Jan 31 at 14:03




I have a question, would $HOME in this case be /root or would it be the the home directory of the user who initiates the reboot, assuming the script is in /etc/rc6.d.
– Hunter.S.Thompson
Jan 31 at 14:03












@Hunter.S.Thompson No, unless you have way to trap which user start shutdown (by way of sudo for instance)...
– Archemar
Jan 31 at 14:06




@Hunter.S.Thompson No, unless you have way to trap which user start shutdown (by way of sudo for instance)...
– Archemar
Jan 31 at 14:06












up vote
1
down vote













You need to run bash as login shell. You need to login as the user and when you log-out from the interactive login shell - the .bash_logout script will be executed.






share|improve this answer




















  • Command in .bash_logout execute in login shell ,most of time i'm in non-login shell (graphic mode).
    – scrapy
    Jan 31 at 14:06














up vote
1
down vote













You need to run bash as login shell. You need to login as the user and when you log-out from the interactive login shell - the .bash_logout script will be executed.






share|improve this answer




















  • Command in .bash_logout execute in login shell ,most of time i'm in non-login shell (graphic mode).
    – scrapy
    Jan 31 at 14:06












up vote
1
down vote










up vote
1
down vote









You need to run bash as login shell. You need to login as the user and when you log-out from the interactive login shell - the .bash_logout script will be executed.






share|improve this answer












You need to run bash as login shell. You need to login as the user and when you log-out from the interactive login shell - the .bash_logout script will be executed.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 31 at 13:42









Georgi Tsvetanov Tsenov

1315




1315











  • Command in .bash_logout execute in login shell ,most of time i'm in non-login shell (graphic mode).
    – scrapy
    Jan 31 at 14:06
















  • Command in .bash_logout execute in login shell ,most of time i'm in non-login shell (graphic mode).
    – scrapy
    Jan 31 at 14:06















Command in .bash_logout execute in login shell ,most of time i'm in non-login shell (graphic mode).
– scrapy
Jan 31 at 14:06




Command in .bash_logout execute in login shell ,most of time i'm in non-login shell (graphic mode).
– scrapy
Jan 31 at 14:06












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420951%2fwhy-the-command-in-bash-logout-cant-run-after-reboot%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?