It is currently Mon Jun 27, 2022 12:54 pm
All times are UTC + 8 hours

[HOW TO] Run your own script on system startup

Share your awesome tips and tricks here.

Re: [HOW TO] Run your own script on system startup

Postby SpeedSnnop » Sat Nov 06, 2021 5:47 am

Hello, how are you?
I have done everything mentioned with the same negative result.
I put the code of mount.sh

Code: Select all
#!/bin/sh
#script montar drive Adrisamina en plex
/volume1/.@plugins/AppCentral/entware/opt/bin/rclone mount PLEX: /volume1/PELIS --allow-other &
/volume1/.@plugins/AppCentral/entware/opt/bin/rclone mount SERIES: /volume1/SERIES --allow-other &


I put the code of the symbolic link

Code: Select all
#!/bin/sh
#script montar drive Adrisamina en plex
/volume1/.@plugins/AppCentral/entware/opt/bin/rclone mount PLEX: /volume1/PELIS --allow-other &
/volume1/.@plugins/AppCentral/entware/opt/bin/rclone mount SERIES: /volume1/SERIES --allow-other &


The symbolic link name is S85mount.sh with chmod + x just like mount.sh

Ls instruction code

Code: Select all
admin@AS6604T-578D:/volume1/home/admin $ ls -l /volume1/.@plugins/etc/init.d/S85
mount.sh
lrwxrwxrwx    1 admin    administ        28 Nov  5 22:09 /volume1/.@plugins/etc/init.d/S85mount.sh -> /volume1/home/admin/mount.sh*


Thank you very much for your interest.
SpeedSnnop
 
Posts: 5
Joined: Fri Nov 05, 2021 7:01 am

Re: [HOW TO] Run your own script on system startup

Postby father.mande » Sat Nov 06, 2021 4:45 pm

Hi,

Remarks :
... you don't trace the command (as orion and me suggest), so add output (ex. echo "start" > /tmp/mytrace.out first, then add output to your command : (end of line before &) 2>&1 > /tmp/mytrace.out; and a last echo at end.
... ... so all run, error, output are traced.

... you don't respect init.d script format, better to use the "formal" form ex. :
Code: Select all
#!/bin/sh

prefix="/opt"
PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
        start)
                HERE you command at boot (start)

                ;;
        stop)
                ;;
        restart)
                ;;
        status)
                ;;
        *)
                echo "Usage: $0 (start|stop|restart|status)"
                exit 1
                ;;
esac


... you start your command in background ( & at end of line) ... this can kill your process if the shell end (and script in init.d or in /usr/local end) ... so perhaps your command start but are immediately killed at end of the script.
... ... prefer using nohup (/usr/bin/nohup) to start and detach task from your script. : /usr/bin/nohup command args &

Philippe.
AS5202T /AS5002T / AS202TE / AS1002T
My Blog specific to my APKG : https://blog.father-mande.ovh/
User avatar
father.mande
 
Posts: 1408
Joined: Sat Sep 12, 2015 2:55 am

Re: [HOW TO] Run your own script on system startup

Postby SpeedSnnop » Sat Nov 06, 2021 5:29 pm

Hello, good morning, as always, thank you very much for your dedication and involvement with my problem.

As you will see, I do not understand anything about this, I do not know anything about codes and python or and I try to learn, and what I am doing is copying from one to the other and trying to make it run correctly but it is an odyssey for me at the moment.

I will copy what you tell me and I will try to implement it to see if I can execute it.
Now that I remember, that code that you tell me, a user passed that script to me by telegram, which when executing it threw me an error.
I copy the code to see:

Code: Select all
#!/bin/sh
case "$1" in
start)
sh  /volume1/home/admin/mount.sh
;;
stop)
echo "Funciona"
;;
reload)
sh /volume1/home/admin/mount.sh
;;
*)
echo "usage: $0 {start|stop|reload}"
exit 1
;;
esac
exit 0


The error that it throws me when I try to execute it with sh S85mount.sh is the following:
syntax error: unexpected word (expecting "in")

Thank you very much, I will inform you.

All the best

Hello again, I attach script and result of said script, thank you.

Code: Select all
#!/bin/sh

prefix="/opt"
PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
        start)
                sh /volume1/home/admin/mount.sh (start)

                ;;
        stop)
                ;;
        restart)
                ;;
        status)
                ;;
        *)
                echo "Usage: $0 (start|stop|restart|status)"
                exit 1
                ;;
esac



Code: Select all
admin@AS6604T-578D:/volume1/.@plugins/etc/init.d $ sh S82mount.sh
: not found: line 2:
: not found: line 5:
S82mount.sh: line 6: syntax error: unexpected word (expecting "in")
admin@AS6604T-578D:/volume1/.@plugins/etc/init.d $
SpeedSnnop
 
Posts: 5
Joined: Fri Nov 05, 2021 7:01 am

Re: [HOW TO] Run your own script on system startup

Postby SpeedSnnop » Sun Nov 07, 2021 4:11 am

Chicossss I finally achieved it, first of all I would like to thank you for your tremendous help, thank you very much, I am attaching the codes of how everything has turned out.

Code: Select all
#!/bin/bash
# -*- ENCODING: UTF-8 -*-
prefix="/opt"
PATH=${prefix}/bin:${prefix}/sbin:/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
     start)
             sh /volume1/home/admin/mount.sh
             ;;
     stop)
             ;;
     restart)
             sh /volume1/home/admin/mount.sh
             ;;
     status)
             ;;
     *)
             echo "Usage: $0 (start|stop|restart|status)"
             exit 1
             ;;
esac


Code: Select all
#!/bin/bash
# -*- ENCODING: UTF-8 -*-
rclone mount PLEX: /volume1/PELIS --allow-other &
rclone mount SERIES: /volume1/SERIES --allow-other &

SpeedSnnop
 
Posts: 5
Joined: Fri Nov 05, 2021 7:01 am

Re: [HOW TO] Run your own script on system startup

Postby maytinhdalat » Thu Jun 09, 2022 5:59 pm

Thanks
User avatar
maytinhdalat
 
Posts: 1
Joined: Thu Jun 09, 2022 5:51 pm
Location: 90 Nguyễn Công Trứ, Phường 8, Tp. Đà Lạt

Previous

Return to Tips & Tricks

  • You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot post attachments in this forum
  • Who is online

    Users browsing this forum: No registered users and 3 guests

cron