× NETGEAR will be terminating ReadyCLOUD service by July 1st, 2023. For more details click here.
Orbi WiFi 7 RBE973
Reply

Auto-run of custom unix command (custom wget) on NAS OS

Retired_Member
Not applicable

Auto-run of custom unix command (custom wget) on NAS OS

Hello, i am newbie in linux but i know ssh and basic and some advanced commands and i can handle many things with manual 😄

Problem is, that i need to execute 1 basic linux command on my NAS unit READYNAS 312. I DO NEED it to run command repeatedly, in example each 4 hours, or each 1 hour.

wget --user=***** --password=***** http://sledovanitv.cz/vlc/playlist


Code basically downloads CHANNELS PLAYLIST for my IPTV. Dvblink doesnt support HTTP autentificated download, so i have to use this "helpful" script.

I can only acces broadcast / channels from my home IP address. So thats why i use this solution.

As i have checked manually, script works and delivers file. Now i need to automatize it, or hook it up .. somewhere.. give me some hint pls.
Message 1 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

Have you tried using cron?
Message 2 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

Not yet.

I know what CRON is. I am using it with relation to web sites, web hosting and running php scripts there.

But at NAS? I have meanwhile discovered following directories, in directory structure:

/etc/cron.d
/etc/cron.daily
/etc/cron.monthly
/etc/cron.weekly

and file

/etc/crontab

Is there some reference how to use this feature ? All the directories, where i was looking for example file, or inspiration, were empty. Or some manual or else forum page, where it could be described?

I really need just to add that command above to be run each 1 hour. Or maybe 4 hours. Nothing else.
Message 3 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

Cron is used on many different unix systems for scheduling tasks. There is plenty of information on this available on the web.
Message 4 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

Yes, i know, but you could save me a 10 hours of searching.. testing and then fixing my NAS, if something goes terribly wrong.
Maybe this forum was intented to be made for helping people who invested into netgear's products, but then "something has happened" too.
Message 5 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

Things like this are SSH hacks and with these you are expected to have some willingness to find out how to do some things by yourself. Otherwise you probably shouldn't be using SSH.


03 */4 * * * /usr/bin/wget --user=***** --password=***** http://sledovanitv.cz/vlc/playlist


Something like this ought to do it. Best not to run a cron script right on the hour.
Message 6 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

Ok thanks very much. :oops: Yes i have discovered a big number of nice manuals, but when i started searching for solution there (i mean writing code inspired by manuals) it became very stressful process.

I have also discovered, that linux VI editor has been probably replaced with its some newer version inside NAS OS 6.1.9 and i am even unable to switch it from command mode to edit mode now. OMG. These newer versions :slap:

So basically when was trying to help myself alone, only other more and more problems and difficulties, have appeared. Yes i am awared, that the source is my lack of skill and experience with unix systems.

So I have created file called "playlist" which is placed inside /etc/cron.hourly/ and contains only this line:

wget --user=***** --password=*****http://sledovanitv.cz/vlc/playlist -O /apps/dvblink-tv-server/share/playlist


I was not absolutely sure, if script is executed every hour, but i am convinced, because locally saved file (playlist) changes its content regularly and solution works. Yes it would be nicer to run it not exactly on each hour X:00.
Message 7 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

Instructions for using vi are on the MAN page for it which you can find using google on the web. There is also a vi cheat sheet on the web.

Try creating a file in /etc/cron.d with the contents I suggested above.
Message 8 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

Hello, yes i know that VI, has online manual and i was already browsing it before, but i found it not user friendly at all and i was unable to find there the switch button key, between edit, insert modes (any other then escape, or insert maybe). They have changed this completely between versions, now it is painful to use it, so i cant use it at all.. Previous versions worked very well and seamless. Back to topic..

i realized, that my file was not run repeatedly by cron, it wasnt run repeatedly at all.

So i have created file "playlist" inside "cron.d" directory with the following content:

 03 */4	* * *	root	/usr/bin/wget --user=*** --password=*** http://sledovanitv.cz/vlc/playlist -O /apps/dvblink-tv-server/share/playlist

- i have tried both with ROOT user typed in (above) and or without it

but problem is, that if i run it by command "run-parts /etc/cron.d/" then it returns execute error, code1.

I have set "chmod +x playlist" for it.

I have also tried to rename "playlist" file inside cron.d folder to "playlist.sh" and then "chmod +x", but then when i run-parts, it gives no error code and target file doesnt change. (so it is not executed OK)

When i have tried multiple times to run the command standalone, it works ok and changes file content (here) /usr/bin/wget --user=*** --password=*** http://sledovanitv.cz/vlc/playlist -O /apps/dvblink-tv-server/share/playlist[/code]

EDIT: only bright idea, i currently have, is to put whole command into .sh file and let cron to execute just this .sh file.. if that can make any difference? I will test and post results.

EDIT2: it doesnt work. Execute error code 1, altough standalone running .sh script works. This is exactly what i hate about linux...


#!/bin/sh
/usr/bin/wget --user=mail@address.com --password=***** http://sledovanitv.cz/vlc/playlist -O /apps/dvblink-tv-server/share/playlist

Message 9 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

Did you remember to add a blank line to the end of the script?
Message 10 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

I have added empty line to both files.. (one in cron.d directory) called playlist


6 * * * * root /usr/local/bin/playlist.sh



and the second file with script itself called playlist.sh


#!/bin/sh

/usr/bin/wget --user=mail@address.com --password=***** http://sledovanitv.cz/vlc/playlist -O /apps/dvblink-tv-server/share/playlist



but result is still


run-parts: failed to exec /etc/cron.d/playlist: Exec format error
run-parts: /etc/cron.d/playlist exited with return code 1
Message 11 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

Ah, looks like the line is formatted incorrectly.

Perhaps fix the gaps between characters to appropriate lengths. You can see for example the gap between the first and second * is much bigger than the gap between e.g. the 2nd and 3rd one.
Message 12 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

I have taken that line directly fron "crontabs" file, copy and pasted and edited only ending - target script. 😄 It only uses tabulators as spaces, thats why it looks (at this forum) broken.

I have also already tried line, that you have posted here..

I have also checked files, for encoding, it is UTF8 without BOM, so it is correct and same type as original linux files are.

I browsed dozens of pages with that fault, but they refer to missing first script line, or problem with paths in linux 😞 mostly ..

I am suspicious to problem with paths? But how that could be, if standalone .sh script works ok, if it is run.

EDIT: this is original crontabs file, just for check, i have never edited it or changed its content, before.

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

Message 13 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

What happens if you change

/usr/local/bin/playlist.sh

to

sh /usr/local/bin/playlist.sh
Message 14 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

I already had this bright idea, but i have tried once again, with same result.

I would target on adding cron directly to crontabs. But it is a file. How can i test it? Like i test folders by "run-parts /etc/cron.d" it doesnt work. Is there some way?

I go sleep now, i have spent whole night with that.. so i like this cron very much.
Message 15 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

Asked a friend about this to see if he had any ideas on it and got this response:

None at all, works for me every way I test it. The only thing that *may* be a problem is that even if one invokes run-parts manually, it will check whether the script is actually up for execution and if it isn't it will simply do nothing. Also, even when script execution is set to "* * * * *" and the script already has been executed within the same minute, run-parts will again do nothing.
Message 16 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

I see, but for me it just DOESNT WORK.

Because i regularly check target file source code, i know what i am talking about.

Target file changes only when target .sh script is executed by "sh playlist.sh" manually (i did check target file content again).

Target file has not changed its content since i went sleep yesterday (10 hours+). So probably, because of nature of links inside the target file (they contain tokens), i will be unable to watch iptv soon again (within 24hours at most).
Message 17 of 20
super_poussin
Virtuoso

Re: Auto-run of custom unix command (custom wget) on NAS OS

follow this

1st create a file without extensions in /etc/cron.d for example /etc/cron.d/tvdownload containing


15 * * * * root /bin/sh /tmp/toto.sh


toto.sh will be run every hour +15 Minutes

toto.sh located in /tmp for my example contain :


/usr/bin/wget --user=toto --password=tooto http://www.xyz.com -O /tmp/index.html


then do a

/etc/init.d/cron restart


you can use this command to monitor

journalctl -f



Feb 10 18:15:01 Biniou CRON[8234]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 10 18:15:01 Biniou CRON[8235]: (root) CMD (/bin/sh /tmp/toto.sh)
Feb 10 18:15:03 Biniou CRON[8234]: pam_unix(cron:session): session closed for user root
Feb 10 18:17:01 Biniou CRON[8270]: pam_unix(cron:session): session opened for user root by (uid=0)
Feb 10 18:17:01 Biniou CRON[8271]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Feb 10 18:17:01 Biniou CRON[8270]: pam_unix(cron:session): session closed for user root
Message 18 of 20
Retired_Member
Not applicable

Re: Auto-run of custom unix command (custom wget) on NAS OS

Good news!

I have discovered that fact about different EOL (end of lines) that use dos, windows, and unix. Sry i never heard of it and never noticed. I know just various encoding types differencies, but not this. So altough i use notepad++ on windows and then i transfer files to NAS, it was new thing for me and i have just hit "convert EOL for unix" inside this great program and saved both files.

Then, i have added cron and i have added script to my NAS. Both with empty ending line and now also with correct EOL.

I have tested through running command "run-parts /etc/cron.d" and it was givimg me still same error (FUNNY). SO THIS CRON TESTING METHOD DOESNT WORK and i warn everyone!

Because i have waited a few minutes and finally, target file has changed its content (just after schedule time). Voila, problem solved.

Thanks for your time anyway, it was really hard for me and i believe also for you.. you are patient person. Also big curse is that "ofically described method to test crons" didnt worked.

And big thanks for CTLJOURNAL -F, because i have discovered error reports with that first, it has reported "info about missing wrong end of lines".
Message 19 of 20
mdgm-ntgr
NETGEAR Employee Retired

Re: Auto-run of custom unix command (custom wget) on NAS OS

See my previous post for an explanation of why that testing method didn't work for you. Glad it is now resolved.
Message 20 of 20
Top Contributors
Discussion stats
  • 19 replies
  • 5985 views
  • 0 kudos
  • 3 in conversation
Announcements