Reputation: 73
I am trying to execute a remote command for one of my scripts. I have to run this script across many servers. so i will put it in a script. What I am trying to do is
ssh [email protected] nohup perl /script/myscript.pl 06/04/2014 60 &
The script runs just fine but there is an info message which is displayed whenever you try to login . The one many of you would be familiar with ..
|-----------------------------------------------------------------|
| This system is for the use of authorized users only. |
| Individuals using this computer system without authority, or in |
Due to this the script execution is haulted unless an enter is pressed. I want to put the script in a cronjob for automatic execution, so i dont need to see this info message.
Upvotes: 0
Views: 116
Reputation: 123480
Here's my theory:
Your command doesn't run the program in the background on the server. It runs runs the program in the foreground on the server, and then you background ssh
.
Since ssh
runs in the background, you are immediately returned to your prompt.
Milliseconds later, ssh
overwrites your prompt with this message and runs the command.
You are now looking at the ssh message and no prompt.
You hit press enter, which causes the prompt to be redrawn on the next line.
This leads you to believe ssh
was actually waiting for you to press enter. In reality, the command was already run, and bash was ready for new commands, just obscured by ssh noise.
How to test:
If I'm right, pressing Ctrl+L instead of Enter will clear the screen and show the bash prompt. (assuming you don't use bash's vi
mode).
If I'm not, Ctrl+L will instead either do nothing, print the ssh message again or just write ^L
to the screen.
How to fix if I'm right:
ssh -f [email protected] 'nohup perl /script/myscript.pl 06/04/2014 60 &' 2> /dev/null
Upvotes: 2