[SCRIPT] create-autorun.sh

Introduce yourself to us and other members here, or share your own product reviews, suggestions, and tips and tricks of using QNAP products.
cactoid
New here
Posts: 4
Joined: Sat Jun 01, 2019 3:11 am

Re: [SCRIPT] create-autorun.sh

Post by cactoid » Sat Jun 01, 2019 5:07 pm

That looks just like what I need and much simpler than the other solutions I'd found - will give it a shot next week

Thanks again

chripopper
New here
Posts: 5
Joined: Mon Aug 12, 2019 4:55 pm

Re: [SCRIPT] create-autorun.sh

Post by chripopper » Thu Aug 22, 2019 4:57 am

Awesome script! Thank you very much!

Works great on TS-451+ running QTS 4.4.1.1031

User avatar
OneCD
Ask me anything
Posts: 7541
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Thu Aug 22, 2019 6:21 am

Thanks and welcome to the forum. :D

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

jsteng
Getting the hang of things
Posts: 59
Joined: Thu Mar 29, 2018 7:48 am

Re: [SCRIPT] create-autorun.sh

Post by jsteng » Sat Feb 08, 2020 7:51 am

Hi

I have installed your script months ago; working great thus far.

Then lately, I wrote another script (auto_delete.sh) but could not get it to work.
Autorun log only gives this:
Sat Feb 8 05:17:07 HKT 2020 - /share/CACHEDEV1_DATA/.system/autorun/scripts/auto_delete.sh

When I run the sh file from terminal, I always get "command not found".


#!/usr/bin/env bash
MAXAGE=7776000
LOGFILE='/share/CACHEDEV1_DATA/.system/autorun/scripts/log.txt'
FOLDER="/share/Multimedia/VIDEO/Movies/TEMP"
FILE="${FOLDER}/DELETE.ME"
echo "==================================================" >> "$LOGFILE"
echo "== auto_delete.sh $(date) ==" >> "$LOGFILE"
echo "==================================================" >> "$LOGFILE"
echo "${FILE}" >> "$LOGFILE"
if test -e "${FILE}"
then
AGE=$(( $(date +%s) - $(date +%s -r "${FILE}") ))
if [ $AGE -gt $MAXAGE ]
then
echo "RESULT: $AGE seconds, OVERDUE" >> "$LOGFILE"
else
echo "RESULT: $AGE seconds, Not Overdue" >> "$LOGFILE"
fi
else
echo "RESULT: File not found. Creating file" >> "$LOGFILE"
touch "${FILE}"
fi
echo "" >> "$LOGFILE"


1. The file does have +x
2. Syntax wise, the script works if I manually copy-paste the script to terminal.
3. Internet suggests that I have to convert the file to UNIX format which I already did.

What is wrong? I run out of ideas.

thanks for helping.
You do not have the required permissions to view the files attached to this post.
Last edited by jsteng on Sat Feb 08, 2020 7:58 am, edited 1 time in total.

User avatar
OneCD
Ask me anything
Posts: 7541
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Sat Feb 08, 2020 7:53 am

jsteng wrote:
Sat Feb 08, 2020 7:51 am
When I run the sh file from terminal, I always get "command not found".
Can you please post a terminal transcript demonstrating this? Need to see the command prompt, your command and the response from the shell. :geek:

Copy-paste it if you can, but a screenshot is also acceptable.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

jsteng
Getting the hang of things
Posts: 59
Joined: Thu Mar 29, 2018 7:48 am

Re: [SCRIPT] create-autorun.sh

Post by jsteng » Sat Feb 08, 2020 8:00 am

Hi

please check previous post. I added a screen shot.
(I could not attach screen shot on new post?)

thanks

User avatar
OneCD
Ask me anything
Posts: 7541
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Sat Feb 08, 2020 8:01 am

You’re not executing your script correctly. ;)

Use:

Code: Select all

./autodelete.sh

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

jsteng
Getting the hang of things
Posts: 59
Joined: Thu Mar 29, 2018 7:48 am

Re: [SCRIPT] create-autorun.sh

Post by jsteng » Sat Feb 08, 2020 8:07 am

running it via
/autodelete.sh gave me no such file or directory



ps. You might see discrepancy in autorun.log "auto_delete.sh" and the screenshot "autodelete.sh"
That is because, when it failed to run, after several attempts to resolve the problem, I run out of ideas, I renamed the file to "autodelete.sh"...
You do not have the required permissions to view the files attached to this post.

User avatar
OneCD
Ask me anything
Posts: 7541
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Sat Feb 08, 2020 8:14 am

You’re getting closer. Please check the syntax again. ;)

Whenever you wish to run a script located in the current directory, you need to explicitly specify the current directory [./] and script name.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

jsteng
Getting the hang of things
Posts: 59
Joined: Thu Mar 29, 2018 7:48 am

Re: [SCRIPT] create-autorun.sh

Post by jsteng » Sat Feb 08, 2020 8:35 am

"./autodelete.sh" gives me
no such file or directory

User avatar
OneCD
Ask me anything
Posts: 7541
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Sat Feb 08, 2020 8:40 am

Please post a screenshot again.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

jsteng
Getting the hang of things
Posts: 59
Joined: Thu Mar 29, 2018 7:48 am

Re: [SCRIPT] create-autorun.sh

Post by jsteng » Sat Feb 08, 2020 9:59 am

Ok...

Somehow, after opening the sh file with Ultraedit (text editor i am using) then saving it back, I forgot to use dos2unix... thus its not a valid unix file...

now it is ok running on shell.

rebooting QNAP and autorun.sh running it seems OK

BOTTOM LINE: dos2unix
I relied too much on ultraedit to do the auto conversion (from dos to unix file format)

thanks.

azuravian
New here
Posts: 3
Joined: Sun Apr 16, 2017 1:41 am

Re: [SCRIPT] create-autorun.sh

Post by azuravian » Tue Mar 24, 2020 5:55 am

Wow, this helped so much in getting my Windows samba shares to map correctly so that they are accessible to docker containers that need them. Thanks!

User avatar
OneCD
Ask me anything
Posts: 7541
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Tue Mar 24, 2020 5:58 am

No worries. :D

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

Haskell
New here
Posts: 5
Joined: Mon May 27, 2019 2:30 am

Re: [SCRIPT] create-autorun.sh

Post by Haskell » Tue Apr 28, 2020 5:27 am

first of all thank you for writing this script, and helping out who's in need

running scripts on my Qnap at startup has been driving me crazy for sometime, I tried everything and failed, including your method, I have only two scripts which run certain applications in a screen session using '-dmS' flags to run the application with a named-deattached session, in my '/var/logs/autorun.log' I can see that both of my scripts got executed after booting, but checking with 'screen -ls' I can see that nothing is actually running, keep in mind that both of my scripts are executable, and when the boot is completed, if I go to the scripts directory and execute them via './thescript.sh' they'll run just fine, Also if I run the 'autorun.sh' file located in '.../.system/autorun/autorun.sh' it will run my scripts just fine, Maybe at the boot time the scripts are executed using a different user than admin ? even if that's the case, I'm sure that my applications aren't running by checking with 'pidof' or 'ps -a', any ideas ?

Post Reply

Return to “Users' Corner”