I’m working on a function this works but it is ugly. One thing that could be changed is being able to know the name of the screen. Using screen -dms minecraft java ….jar now starts a screen session named with what appears to be random numbers..hostname. Next is the voodoo that happens to strip the name from screen -ls and use it. Then there is awk. There has to be a better way.

    REEN="$(ssh -p 8989 screen -ls)"
    echo $REEN > log/log.txt
    AWK="$(awk 'FNR == 1 { print $6 }' log/log.txt)"
    NAME="$(echo $AWK)"
    echo $1
    ssh -p 8989 screen -S $NAME -p 0 -X stuff \"$1^M\"

say_this "say test"
say_this "say !@#$%^&*()<>?This string should work!"

You're using a lot of variables and a log file unnecessarily.

I'm not sure about the stuff after stuff, but I bet it can be simpler:

    local name="$(ssh -p 8989 screen -ls | awk 'NR==2 {print $1}')"
    echo "$1"
    ssh -p 8989 screen -S "$name" -p 0 -X stuff "$1"
| improve this answer | |
  • That worked! Thank you very much! Not ugly anymore. – fuzzyfreak Dec 26 '14 at 22:35
  • Also I had to change "$1" to \"$1^M\" for it to work. – fuzzyfreak Dec 26 '14 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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