0

I did this:

ssh -f user@host "screen -dm -S screenName"

Now I want to add a bash script command to this line so that the command is executed then the screen detaches.

edit:

so I want to do so

ssh -f user@host "screen -dm -S screenName bash bashing.sh"

bashing.sh:

#!/bin/bash
echo "testing it";

but actually nothing happens when I run the command over ssh.

Even when I just from the server run this command only screen -dm -S screenName bash bashing.sh.

edit 1:

I tried everything so far in the answers and comments and even in the suggested question as duplicate but nothing works for me, so any help would be still very appreciated.

Sincerely

  • Its not working – Omar K. Aly Mar 27 '18 at 15:52
  • 1
    "Sure it is - no, it's not - sure it is...". Please add failure details to your question. – NickD Mar 27 '18 at 18:18
  • ssh -f user@host "screen -dm -S screenName *want to run bash script here* " ====== so I did it like this ssh -f user@host "screen -dm -S screenName sh bashScript.sh" ====== and like this ssh -f user@host "screen -dm -S screenName ./bashScript.sh" ========== and like this ssh -f user@host "screen -dm -S screenName bash bashScript.sh" ======= and none of this run the script – Omar K. Aly Mar 28 '18 at 11:54
  • edit your question do not answer in comment please. Comment maybe deleted and are not made to last. – Kiwy Mar 28 '18 at 12:51
  • @OmarK.Aly where is your bash script ? – Kiwy Mar 28 '18 at 12:52
  • I think your question is a duplicate of this question https://unix.stackexchange.com/q/87405/53092 – Kiwy Mar 28 '18 at 13:04
  • @Kiwy : but could you explain how I could tweak those commands to use with screen command also. I mean to run a script on screen over ssh not just running a script over ssh – Omar K. Aly Mar 28 '18 at 13:23
  • @Kiwy I edited my question so it contains it now – Omar K. Aly Mar 28 '18 at 13:30
  • @OmarK.Aly WHERE not what. is it on your laptop or your server. – Kiwy Mar 28 '18 at 13:36
  • @Kiwy oh sorry ... Its on the server it self – Omar K. Aly Mar 28 '18 at 13:38
  • your problem is that you should use the fullpath of your script on the server. or your script need to be in the PATH. `ssh -f user@host "screen -dm -S screenName bash /path/to/bashing.sh"` – Kiwy Mar 28 '18 at 14:01
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/75190/discussion-between-omar-k-aly-and-kiwy). – Omar K. Aly Mar 28 '18 at 14:06

1 Answers1

1
ssh -f user@host "screen -dm -S screenName sleep 123"
Hauke Laging
  • 88,146
  • 18
  • 125
  • 174
  • That kills the screen after the sleep time is done I want to run a command and keep the screen alive just detach from it – Omar K. Aly Mar 28 '18 at 12:01
  • 1
    `ssh -f user@host "screen -dm -S screenName myscript"` where myscript does something like `sleep 123; bash`. – NickD Mar 28 '18 at 13:15
  • @Nick actually my script should do this ====> #!/bin/bash echo "testing it"; ==== And instead of myscript I just used my script name ===> "bashing.sh" .... is that right ? – Omar K. Aly Mar 28 '18 at 13:25