Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Ok I have 2 linux machines, machine A and machine B. Machine A is a server running icecast audio server. Machine B is a desktop in the studio running BUTT(Broadcast Using This Tool) an x11 app that sends audio back to machine A.

Butt on machine B sometimes crashes(in fact any app we've tried and on windows too eventually crashes), killing the stream. However I have found out I configure icecast to run a stript whenever the source disconnects. I have private key authorization working for ssh between A and B. I have a script that if I run on B (via normal interactive ssh) will reluanch butt. What I don't know is how to write the script on A so it will run the script I have on B.

I have tried this:

#!/bin/bash
ssh username_placeholder@B '/home/username_placeholder/broadcast.sh'
exit

running from A. But that seems to keep ssh alive. All I want to do is run it and hang up. broadcast.sh looks like this:

#!/bin/bash
killall butt
env DISPLAY=:0 butt&
exit

This is because butt only runs in gui mode. and we do want to see the gui in the studio from time to time anyway. So how do I make it run that script and hangup, or is there an even better way to do this on A without trying to call the script on B. I want it to kill butt if it's still runing and then start it(remeber it still has to display on B, not A. and A is the computer that can know when the source on B hangs up.)

Computer A runs ubuntu server, and computer B runs linux mint in case anyone cares.

share|improve this question
add comment

2 Answers

You should consider using the screen command, it will allow you to do what you want with the added benefit of being able to reconnect to the shell at any point in time.

SSH TO REMOTE HOST

machine_a:> ssh machine_b

START A NEW SHELL USING SCREEN

machine_b:> screen
machine_b:> run your script here

DETACH FROM THE SCREEN

( Press Ctrl-a then ctrl-d to disconnect from the screen )

EXIT OUT OF SERVER SHELL

machine_b:> exit
machine_a:> 

LOGIN BACK INTO SERVER (at later date)

machine_a:>ssh machine_b

LIST ALL SCREENS THAT EXIST FOR YOUR USER

screen -list  (to show a list of all screen sessions that exist).

eg.    
username@machine_b:~/> screen -list
There are screens on:
        30264.pts-5.machine_b  (Detached)
2 Sockets in /var/run/uscreens/S-username.

RECONNECT TO A DETACHED SCREEN

machine_b:> screen -dr 30264

At this stage you can see your script/command/shell exactly as you left it. Even if the command you ran was an xwindows application with display set to the remote server display.

To create the remote screen with your script running in the same way you are attempting to do using just ssh alone try this:

ssh -t username_placeholder@B 'screen -d -m /home/username_placeholder/broadcast.sh'
share|improve this answer
    
Thank you for your answer, but I'm sorry I don't understand this very well. Am I supposed to run these commands for the setup process and then put the "screen -dr 30264" in my script to reconnect to that screen. will this kill the connection when I'm not using it? is 30264 a port I will need to open on my router protecting B? I still don't get what I put in the script on A that will run comands on B and hang up. Also Butt must show the gui on B, it seems like we are making some kind of virtual display here, is that what's going on? Thanks –  UserZer0 Jan 29 '13 at 17:32
    
sorry for the delay... think of screen as running an entire shell as a background process that you can later reconnect to. ie. you can login remotely, create a screen, run commands or several and leave them running.... disconnect from that shell (drops you back to your original ssh shell) and you can safely exit that shell.. then at a later day you can ssh back into the remote machine and reconnect to the "screen" using the screen -list and screen -dr commands. –  Matthew Aldous Feb 1 '13 at 6:04
    
Yeah don't run the screen command in your script... I've updated my answer to be more clear on how to use it. You could automate the whole thing with a single ssh command probably like... –  Matthew Aldous Feb 1 '13 at 6:23
    
Try something like this: ssh -t username_placeholder@B 'screen -d -m /home/username_placeholder/broadcast.sh' –  Matthew Aldous Feb 1 '13 at 6:42
add comment

you must run your broadcast script from machine A with '-f' option of ssh:

#!/bin/sh
ssh -f username_placeholder@B /home/username_placeholder/broadcast.sh

this will automatically make 'broadcast.sh' go to the background.

The 'broadcast.sh' script itself then should look like this:

#!/bin/sh
killall butt
DISPLAY=:0 butt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.