Haris1977
Posts: 129
Joined: Sat Jul 05, 2014 8:19 am

Script needed !

Wed Nov 08, 2017 6:21 am

I ve managed to install an app (moonlight-embedded) on my rpi1 model B, but i want to create a scrip with 3 commands

My software is raspbian and it boots in cmd mode (i ve already downloaded wakeonlan and i m booting in cmd with username pi and password raspberry). The 3 commands of the script must be:

1) wakeonlan XX:XX:XX:XX:XX:XX (my pc mac address)
2) wait 15 seconds and then
3) moonlight stream -app mstsc.exe 192.168.1.109 -1080

all of them when raspbian boots. Can anyone help? I m a linux noob :)

User avatar
DougieLawson
Posts: 39895
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Script needed !

Wed Nov 08, 2017 6:55 am

You could add three lines to /etc/rc.local

The way to wait is with the sleep command.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Haris1977
Posts: 129
Joined: Sat Jul 05, 2014 8:19 am

Re: Script needed !

Wed Nov 08, 2017 7:44 am

Thanks but i do not know much about commands and about the form they should be presented.

From what i ve read could it be smth like this?


wakeonlan XX:XX:XX:XX:XX:XX
sleep 15
moonlight stream -app mstsc.exe 192.168.1.109 -1080

User avatar
RaTTuS
Posts: 10578
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Script needed !

Wed Nov 08, 2017 8:11 am

edit your .bashrc file
like
nano .basrc
and right at the end
put

if [ $(tty) == /dev/tty1 ]; then
wakeonlan XX:XX:XX:XX:XX:XX
sleep 15
moonlight stream -app mstsc.exe 192.168.1.109 -1080
fi

if your rpi is set to autologin as user pi then this will work after a reboot
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
DougieLawson
Posts: 39895
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Script needed !

Wed Nov 08, 2017 11:45 am

Haris1977 wrote:
Wed Nov 08, 2017 7:44 am
Thanks but i do not know much about commands and about the form they should be presented.

From what i ve read could it be smth like this?


wakeonlan XX:XX:XX:XX:XX:XX
sleep 15
moonlight stream -app mstsc.exe 192.168.1.109 -1080
You'll want it to have

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

wakeonlan XX:XX:XX:XX:XX:XX
sleep 15
moonlight stream -app mstsc.exe 192.168.1.109 -1080 &

exit 0
Or in RaTTus' version

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
if [ $(tty) == /dev/tty1 ]; then
wakeonlan XX:XX:XX:XX:XX:XX
sleep 15
moonlight stream -app mstsc.exe 192.168.1.109 -1080 &
fi
Because I assume moonlight is a daemon program that doesn't terminate.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Haris1977
Posts: 129
Joined: Sat Jul 05, 2014 8:19 am

Re: Script needed !

Wed Nov 08, 2017 1:19 pm

Thank you guys:) I will test them to see if i am ok with these :)

Haris1977
Posts: 129
Joined: Sat Jul 05, 2014 8:19 am

Re: Script needed !

Thu Nov 09, 2017 9:09 am

Well. I run @DougieLawson's script and it can't be run:

It states:

/bin/sh: 0: Illegal option -

The script is this

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

wakeonlan XXXXXXXXXXXXXX
sleep 65
moonlight stream -app mstsc.exe 192.168.1.109 -1080 &

exit 0

So is this wrong?

@RaTTuS this only works if you power off and on your pi. If you reboot it gets this error:

send: Network is unreachable at /usr/bin/wakeonlan line 126
Last edited by Haris1977 on Thu Nov 09, 2017 9:50 am, edited 2 times in total.

User avatar
DougieLawson
Posts: 39895
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Script needed !

Thu Nov 09, 2017 9:30 am

Change it to use /bin/bash rather than /bin/sh -e on the shebang line.

Test it with sudo bash -x /etc/rc.local from a command line or in an LXterminal window.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
jadro
Posts: 456
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: Script needed !

Thu Nov 09, 2017 9:35 am

Haris1977 wrote:
Wed Nov 08, 2017 6:21 am
i m booting in cmd with username pi and password raspberry
Please please if this is correct user and pass then CHANGE IT!!!
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

Haris1977
Posts: 129
Joined: Sat Jul 05, 2014 8:19 am

Re: Script needed !

Thu Nov 09, 2017 9:43 am

DougieLawson wrote:
Thu Nov 09, 2017 9:30 am
Change it to use /bin/bash rather than /bin/sh -e on the shebang line.

Test it with sudo bash -x /etc/rc.local from a command line or in an LXterminal window.
It only says this:

pi@raspberrypi:~ $ sudo bash -x /etc/rc.local
++ hostname -I
+ _IP='192.168.1.102 2a02:587:b913:XXXX:XXXX:XXXX:XXXX:XXX '
+ '[' '192.168.1.102 XXXXXXXXXXXX ' ']'
+ printf 'My IP address is %s\n' '192.168.1.102 XXXXXXXXXXXXX '
My IP address is 192.168.1.102 XXXXX
+ exit 0
pi@raspberrypi:~ $

(i just changed the letters and numbers here with XXX)
Last edited by Haris1977 on Thu Nov 09, 2017 9:45 am, edited 1 time in total.

User avatar
DougieLawson
Posts: 39895
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Script needed !

Thu Nov 09, 2017 9:45 am

Sorry we need to add the new code ahead of the "exit 0" line, that's what comes of writing posts on a mobile phone.

Just delete the "exit 0" line.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
jadro
Posts: 456
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: Script needed !

Thu Nov 09, 2017 9:46 am

DougieLawson wrote:
Thu Nov 09, 2017 9:45 am
Just delete the "exit 0" line.
What this exit 0 represent at all?
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

User avatar
DougieLawson
Posts: 39895
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Script needed !

Thu Nov 09, 2017 9:47 am

It sets the value returned to the calling shell to zero (which means success).

http://tldp.org/LDP/abs/html/exitcodes.html
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
jadro
Posts: 456
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: Script needed !

Thu Nov 09, 2017 9:49 am

Great. Thanx.
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

Haris1977
Posts: 129
Joined: Sat Jul 05, 2014 8:19 am

Re: Script needed !

Thu Nov 09, 2017 9:54 am

DougieLawson wrote:
Thu Nov 09, 2017 9:45 am
Sorry we need to add the new code ahead of the "exit 0" line, that's what comes of writing posts on a mobile phone.

Just delete the "exit 0" line.
Nope, doesnt work either. :cry: I get similar print. :? I get no error but it does nothing. Anyway, the only way i made it to work is by adding those lines at the end of the .bashrc file:

if [ $(tty) == /dev/tty1 ]; then
wakeonlan XX:XX:XX:XX:XX:XX
sleep 15
moonlight stream -app mstsc.exe 192.168.1.109 -1080
fi

This works :D BUT only if i power off and then on my pi. Any ideas why this is not working upon raspi's reboot?

If i reboot i get this error:

send: Network is unreachable at /usr/bin/wakeonlan line 126
Last edited by Haris1977 on Fri Nov 10, 2017 1:06 pm, edited 1 time in total.

SkyRise
Posts: 179
Joined: Tue Jan 24, 2012 1:20 pm

Re: Script needed !

Thu Nov 09, 2017 9:58 am

Sounds like your network is not up when the script is run. Put a sleep before the wake-on-lan stuff...

User avatar
davidcoton
Posts: 5359
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Script needed !

Thu Nov 09, 2017 10:00 am

Puit a sleep before the wakeonlan line. It seems to be trying to connect before the network is ready on the Pi.
Location: 345th cell on the right of the 210th row of L2 cache

User avatar
RaTTuS
Posts: 10578
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Script needed !

Thu Nov 09, 2017 10:23 am

or do it properly and make a systermd script for when the network is up .... ;-p [it's slightly m,ore complex]

create a script in your home directory called myscript
nano myscript

Code: Select all

#!/bin/bash
wakeonlan XX:XX:XX:XX:XX:XX
sleep 15
moonlight stream -app mstsc.exe 192.168.1.109 -1080
make it executable [ha]

Code: Select all

chmod 755 myscript
do the systemd stuf

sudo nano /lib/systemd/system/wol.service

Code: Select all

[unit]
Description=Auto start my stuf

[service]
ExecStart=/home/pi/myscript

[Install]
WantedBy=multi-user.target
enable it with

Code: Select all

sudo systemctl enable wol
run it

Code: Select all

sudo systemctl start wol
see it

Code: Select all

sudo systemctl status wol

[this is all blind from memory so maybe have typos .....
Last edited by RaTTuS on Thu Nov 09, 2017 10:36 am, edited 1 time in total.
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Haris1977
Posts: 129
Joined: Sat Jul 05, 2014 8:19 am

Re: Script needed !

Thu Nov 09, 2017 10:29 am

Well thanks guys for all your help here :D You helped me a lot. Will check them out!

And one last thing: When the pi initiates the 1st command the screen log is:

Sending magic packet to XXXXXX with 192.168.X.XXX

When the pi initiates the 3rd command the screen log e.g is:

Connecting to 192.XXX.X.XXX
Initializing platform...done
Resolving host name...done
Starting RTSP handshake..done blah blah etc.

Is there any "easy" way to "hide" all those lines (from Sending magic packet to Starting RTSP handshake) from seeing them in the terminal every time i reboot? I mean smth like SILENT BOOT on Raspbian (maybe with a boot splash screen :P :P ).

If not i am fine with it :D I m just curious..
Last edited by Haris1977 on Thu Nov 09, 2017 12:59 pm, edited 2 times in total.

SkyRise
Posts: 179
Joined: Tue Jan 24, 2012 1:20 pm

Re: Script needed !

Thu Nov 09, 2017 10:57 am

Standard output can be removed using "command >/dev/null"

To redirect stderr messages as well, use "command > /dev/null 2>&1"

Haris1977
Posts: 129
Joined: Sat Jul 05, 2014 8:19 am

Re: Script needed !

Fri Nov 10, 2017 6:42 am

Thanks but i was thinking smth like this:

https://raspberrypi.stackexchange.com/q ... -in-jessie or

https://www.pi-supply.com/make/disablin ... pberry-pi/

Duno if this will work but i will try

Thank y all! :D

Return to “General discussion”