shell script at ssh login screen











up vote
0
down vote

favorite












I want to run this command when there is an ssh login.



The command is



watch -n 5 'zen-cli getinfo | grep blocks'



I have already added this line by doing this
sudo crontab -e



I added @reboot watch -n 5 'zen-cli getinfo | grep blocks' in crontab



But it does not solve my problem. I want to show this specefic output at the startup screen when there is ssh login like the following:



    Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.4.154-1124-rockchip-ayufan-ged3ce4d15ec1 aarch64)
_ __ _ _
_ __ ___ ___| | ___ __ _ __ ___ / /_ | || |
| '__/ _ / __| |/ / '_ | '__/ _ | '_ | || |_
| | | (_) | (__| <| |_) | | | (_) | (_) |__ _|
|_| ___/ ___|_|_ .__/|_| ___/ ___/ |_|
|_|

* Documentation:
* Management:
* Support:

System information as of Wed Dec 5 06:58:25 UTC 2018

System load: 0.28 Processes: 163
Usage of /: 24.1% of 58.39GB Users logged in: 0
Memory usage: 26% IP address for eth0: 192.168.100.82
Swap usage: 0%


* MicroK8s is Kubernetes in a snap. Made by devs for devs.
One quick install on a workstation, VM, or appliance.
Current zen blocks are synced at


When I run my sh code it returns



rock64@rockpro64:/etc/update-motd.d$ sh 90-figlet 
+ zen-cli getinfo
+ grep blocks
+ printf Current zen blocks are synced at "blocks": 424064,


but when I exit and login again, at login it shows this Current zen blocks are synced at <blank>



This is my sh code



#!/bin/sh
set -x
printf "Current zen blocks are synced at $(zen-cli getinfo | grep blocks)"









share|improve this question




















  • 2




    Watch is a command that doesn't terminate on its own. Do you want the account to be unable to do anything on the machine (other than seeing the output of watch)?
    – Ulrich Schwarz
    Dec 5 at 7:43










  • I do not need watch i think, I just use it manually for convenience. I am doing some memory intensive work on this device and watch is not the primary function, just need it to make things convenient so that the users do not have to run zen-cli getinfo | grep blocks every-time they log in. and also to make sure that the server is running
    – Rakib Fiha
    Dec 5 at 7:50








  • 1




    Seeing as you're running ubuntu, just put your script in /etc/update-motd.d/ ... ?
    – tink
    Dec 5 at 8:08










  • I tried that, but it does not work
    – Rakib Fiha
    Dec 5 at 8:33










  • Did you make the script executable with chmod +x? Also, you probably want to remove that entry from the crontab. It tells the system to run the watch command on Boot, but it doesn't print its output anywhere as there is no session (it's useless).
    – Panki
    Dec 5 at 9:08

















up vote
0
down vote

favorite












I want to run this command when there is an ssh login.



The command is



watch -n 5 'zen-cli getinfo | grep blocks'



I have already added this line by doing this
sudo crontab -e



I added @reboot watch -n 5 'zen-cli getinfo | grep blocks' in crontab



But it does not solve my problem. I want to show this specefic output at the startup screen when there is ssh login like the following:



    Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.4.154-1124-rockchip-ayufan-ged3ce4d15ec1 aarch64)
_ __ _ _
_ __ ___ ___| | ___ __ _ __ ___ / /_ | || |
| '__/ _ / __| |/ / '_ | '__/ _ | '_ | || |_
| | | (_) | (__| <| |_) | | | (_) | (_) |__ _|
|_| ___/ ___|_|_ .__/|_| ___/ ___/ |_|
|_|

* Documentation:
* Management:
* Support:

System information as of Wed Dec 5 06:58:25 UTC 2018

System load: 0.28 Processes: 163
Usage of /: 24.1% of 58.39GB Users logged in: 0
Memory usage: 26% IP address for eth0: 192.168.100.82
Swap usage: 0%


* MicroK8s is Kubernetes in a snap. Made by devs for devs.
One quick install on a workstation, VM, or appliance.
Current zen blocks are synced at


When I run my sh code it returns



rock64@rockpro64:/etc/update-motd.d$ sh 90-figlet 
+ zen-cli getinfo
+ grep blocks
+ printf Current zen blocks are synced at "blocks": 424064,


but when I exit and login again, at login it shows this Current zen blocks are synced at <blank>



This is my sh code



#!/bin/sh
set -x
printf "Current zen blocks are synced at $(zen-cli getinfo | grep blocks)"









share|improve this question




















  • 2




    Watch is a command that doesn't terminate on its own. Do you want the account to be unable to do anything on the machine (other than seeing the output of watch)?
    – Ulrich Schwarz
    Dec 5 at 7:43










  • I do not need watch i think, I just use it manually for convenience. I am doing some memory intensive work on this device and watch is not the primary function, just need it to make things convenient so that the users do not have to run zen-cli getinfo | grep blocks every-time they log in. and also to make sure that the server is running
    – Rakib Fiha
    Dec 5 at 7:50








  • 1




    Seeing as you're running ubuntu, just put your script in /etc/update-motd.d/ ... ?
    – tink
    Dec 5 at 8:08










  • I tried that, but it does not work
    – Rakib Fiha
    Dec 5 at 8:33










  • Did you make the script executable with chmod +x? Also, you probably want to remove that entry from the crontab. It tells the system to run the watch command on Boot, but it doesn't print its output anywhere as there is no session (it's useless).
    – Panki
    Dec 5 at 9:08















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to run this command when there is an ssh login.



The command is



watch -n 5 'zen-cli getinfo | grep blocks'



I have already added this line by doing this
sudo crontab -e



I added @reboot watch -n 5 'zen-cli getinfo | grep blocks' in crontab



But it does not solve my problem. I want to show this specefic output at the startup screen when there is ssh login like the following:



    Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.4.154-1124-rockchip-ayufan-ged3ce4d15ec1 aarch64)
_ __ _ _
_ __ ___ ___| | ___ __ _ __ ___ / /_ | || |
| '__/ _ / __| |/ / '_ | '__/ _ | '_ | || |_
| | | (_) | (__| <| |_) | | | (_) | (_) |__ _|
|_| ___/ ___|_|_ .__/|_| ___/ ___/ |_|
|_|

* Documentation:
* Management:
* Support:

System information as of Wed Dec 5 06:58:25 UTC 2018

System load: 0.28 Processes: 163
Usage of /: 24.1% of 58.39GB Users logged in: 0
Memory usage: 26% IP address for eth0: 192.168.100.82
Swap usage: 0%


* MicroK8s is Kubernetes in a snap. Made by devs for devs.
One quick install on a workstation, VM, or appliance.
Current zen blocks are synced at


When I run my sh code it returns



rock64@rockpro64:/etc/update-motd.d$ sh 90-figlet 
+ zen-cli getinfo
+ grep blocks
+ printf Current zen blocks are synced at "blocks": 424064,


but when I exit and login again, at login it shows this Current zen blocks are synced at <blank>



This is my sh code



#!/bin/sh
set -x
printf "Current zen blocks are synced at $(zen-cli getinfo | grep blocks)"









share|improve this question















I want to run this command when there is an ssh login.



The command is



watch -n 5 'zen-cli getinfo | grep blocks'



I have already added this line by doing this
sudo crontab -e



I added @reboot watch -n 5 'zen-cli getinfo | grep blocks' in crontab



But it does not solve my problem. I want to show this specefic output at the startup screen when there is ssh login like the following:



    Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.4.154-1124-rockchip-ayufan-ged3ce4d15ec1 aarch64)
_ __ _ _
_ __ ___ ___| | ___ __ _ __ ___ / /_ | || |
| '__/ _ / __| |/ / '_ | '__/ _ | '_ | || |_
| | | (_) | (__| <| |_) | | | (_) | (_) |__ _|
|_| ___/ ___|_|_ .__/|_| ___/ ___/ |_|
|_|

* Documentation:
* Management:
* Support:

System information as of Wed Dec 5 06:58:25 UTC 2018

System load: 0.28 Processes: 163
Usage of /: 24.1% of 58.39GB Users logged in: 0
Memory usage: 26% IP address for eth0: 192.168.100.82
Swap usage: 0%


* MicroK8s is Kubernetes in a snap. Made by devs for devs.
One quick install on a workstation, VM, or appliance.
Current zen blocks are synced at


When I run my sh code it returns



rock64@rockpro64:/etc/update-motd.d$ sh 90-figlet 
+ zen-cli getinfo
+ grep blocks
+ printf Current zen blocks are synced at "blocks": 424064,


but when I exit and login again, at login it shows this Current zen blocks are synced at <blank>



This is my sh code



#!/bin/sh
set -x
printf "Current zen blocks are synced at $(zen-cli getinfo | grep blocks)"






ssh motd






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 6 at 7:27

























asked Dec 5 at 7:38









Rakib Fiha

135




135








  • 2




    Watch is a command that doesn't terminate on its own. Do you want the account to be unable to do anything on the machine (other than seeing the output of watch)?
    – Ulrich Schwarz
    Dec 5 at 7:43










  • I do not need watch i think, I just use it manually for convenience. I am doing some memory intensive work on this device and watch is not the primary function, just need it to make things convenient so that the users do not have to run zen-cli getinfo | grep blocks every-time they log in. and also to make sure that the server is running
    – Rakib Fiha
    Dec 5 at 7:50








  • 1




    Seeing as you're running ubuntu, just put your script in /etc/update-motd.d/ ... ?
    – tink
    Dec 5 at 8:08










  • I tried that, but it does not work
    – Rakib Fiha
    Dec 5 at 8:33










  • Did you make the script executable with chmod +x? Also, you probably want to remove that entry from the crontab. It tells the system to run the watch command on Boot, but it doesn't print its output anywhere as there is no session (it's useless).
    – Panki
    Dec 5 at 9:08
















  • 2




    Watch is a command that doesn't terminate on its own. Do you want the account to be unable to do anything on the machine (other than seeing the output of watch)?
    – Ulrich Schwarz
    Dec 5 at 7:43










  • I do not need watch i think, I just use it manually for convenience. I am doing some memory intensive work on this device and watch is not the primary function, just need it to make things convenient so that the users do not have to run zen-cli getinfo | grep blocks every-time they log in. and also to make sure that the server is running
    – Rakib Fiha
    Dec 5 at 7:50








  • 1




    Seeing as you're running ubuntu, just put your script in /etc/update-motd.d/ ... ?
    – tink
    Dec 5 at 8:08










  • I tried that, but it does not work
    – Rakib Fiha
    Dec 5 at 8:33










  • Did you make the script executable with chmod +x? Also, you probably want to remove that entry from the crontab. It tells the system to run the watch command on Boot, but it doesn't print its output anywhere as there is no session (it's useless).
    – Panki
    Dec 5 at 9:08










2




2




Watch is a command that doesn't terminate on its own. Do you want the account to be unable to do anything on the machine (other than seeing the output of watch)?
– Ulrich Schwarz
Dec 5 at 7:43




Watch is a command that doesn't terminate on its own. Do you want the account to be unable to do anything on the machine (other than seeing the output of watch)?
– Ulrich Schwarz
Dec 5 at 7:43












I do not need watch i think, I just use it manually for convenience. I am doing some memory intensive work on this device and watch is not the primary function, just need it to make things convenient so that the users do not have to run zen-cli getinfo | grep blocks every-time they log in. and also to make sure that the server is running
– Rakib Fiha
Dec 5 at 7:50






I do not need watch i think, I just use it manually for convenience. I am doing some memory intensive work on this device and watch is not the primary function, just need it to make things convenient so that the users do not have to run zen-cli getinfo | grep blocks every-time they log in. and also to make sure that the server is running
– Rakib Fiha
Dec 5 at 7:50






1




1




Seeing as you're running ubuntu, just put your script in /etc/update-motd.d/ ... ?
– tink
Dec 5 at 8:08




Seeing as you're running ubuntu, just put your script in /etc/update-motd.d/ ... ?
– tink
Dec 5 at 8:08












I tried that, but it does not work
– Rakib Fiha
Dec 5 at 8:33




I tried that, but it does not work
– Rakib Fiha
Dec 5 at 8:33












Did you make the script executable with chmod +x? Also, you probably want to remove that entry from the crontab. It tells the system to run the watch command on Boot, but it doesn't print its output anywhere as there is no session (it's useless).
– Panki
Dec 5 at 9:08






Did you make the script executable with chmod +x? Also, you probably want to remove that entry from the crontab. It tells the system to run the watch command on Boot, but it doesn't print its output anywhere as there is no session (it's useless).
– Panki
Dec 5 at 9:08












1 Answer
1






active

oldest

votes

















up vote
0
down vote













This seems to be an issue with the environment not being fully initialized.



The following works for me:



#!/bin/sh
# set -x

blocks=`sudo zen-cli getinfo | grep "blocks"`

printf "n"
printf "Current zen blocks are synced at $blocksn"





share|improve this answer























  • I have just tried it but did not work. It is strange because when I run run-parts /etc/update-motd.d/ it works, but when I exit and re login via ssh, it does not. I mean the line ends after .....synced at
    – Rakib Fiha
    Dec 6 at 7:34













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%2f486087%2fshell-script-at-ssh-login-screen%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
0
down vote













This seems to be an issue with the environment not being fully initialized.



The following works for me:



#!/bin/sh
# set -x

blocks=`sudo zen-cli getinfo | grep "blocks"`

printf "n"
printf "Current zen blocks are synced at $blocksn"





share|improve this answer























  • I have just tried it but did not work. It is strange because when I run run-parts /etc/update-motd.d/ it works, but when I exit and re login via ssh, it does not. I mean the line ends after .....synced at
    – Rakib Fiha
    Dec 6 at 7:34

















up vote
0
down vote













This seems to be an issue with the environment not being fully initialized.



The following works for me:



#!/bin/sh
# set -x

blocks=`sudo zen-cli getinfo | grep "blocks"`

printf "n"
printf "Current zen blocks are synced at $blocksn"





share|improve this answer























  • I have just tried it but did not work. It is strange because when I run run-parts /etc/update-motd.d/ it works, but when I exit and re login via ssh, it does not. I mean the line ends after .....synced at
    – Rakib Fiha
    Dec 6 at 7:34















up vote
0
down vote










up vote
0
down vote









This seems to be an issue with the environment not being fully initialized.



The following works for me:



#!/bin/sh
# set -x

blocks=`sudo zen-cli getinfo | grep "blocks"`

printf "n"
printf "Current zen blocks are synced at $blocksn"





share|improve this answer














This seems to be an issue with the environment not being fully initialized.



The following works for me:



#!/bin/sh
# set -x

blocks=`sudo zen-cli getinfo | grep "blocks"`

printf "n"
printf "Current zen blocks are synced at $blocksn"






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 5 at 13:33

























answered Dec 5 at 13:07









Djo

12




12












  • I have just tried it but did not work. It is strange because when I run run-parts /etc/update-motd.d/ it works, but when I exit and re login via ssh, it does not. I mean the line ends after .....synced at
    – Rakib Fiha
    Dec 6 at 7:34




















  • I have just tried it but did not work. It is strange because when I run run-parts /etc/update-motd.d/ it works, but when I exit and re login via ssh, it does not. I mean the line ends after .....synced at
    – Rakib Fiha
    Dec 6 at 7:34


















I have just tried it but did not work. It is strange because when I run run-parts /etc/update-motd.d/ it works, but when I exit and re login via ssh, it does not. I mean the line ends after .....synced at
– Rakib Fiha
Dec 6 at 7:34






I have just tried it but did not work. It is strange because when I run run-parts /etc/update-motd.d/ it works, but when I exit and re login via ssh, it does not. I mean the line ends after .....synced at
– Rakib Fiha
Dec 6 at 7:34




















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f486087%2fshell-script-at-ssh-login-screen%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