Help needed with cron and scrip

Status
Not open for further replies.

dragon_0n3

Dabbler
Joined
Jun 2, 2016
Messages
12
Hello, Everyone!
You're probably rolling your eyes just by reading the title...
I've been searching the webz for solution or something remotely similar to what i'm trying for weeks; i came up with *something*, but am still stomped on a couple of things.

Running 9.3-stable as a plex server, i wanted to automate through cron jobs these processes:
1. stop the plex service
2. delete channel cache folders/data
3. restart plex service

i am able to perform 1 & 3 via simple cron job by these commands as root:
a. to stop jexec plexmediaserver_1 service plexmediaserver onestop
b. to restart jexec plexmediaserver_1 service plexmediaserver onestart

However, if i put these lines in a script (clear_plex_cache.sh):

jexec plexmediaserver_1 service plexmediaserver onestop
sleep 5
rm -Rf /mnt/Data1/jails/plexmediaserver_1/var/db/plexdata/Plex Media Server/Plug-in Support/Caches
sleep 5m
jexec plexmediaserver_1 service plexmediaserver onestart

Place the script in /bin, then run the cron with "find /bin --exec clear_plex_cache.sh" nothing happens.

So far, i can stop/restart the service, then delete the cache folders manually via ftp connection, but if i could automate the process, then i'd be that much close to multimedia nirvana!
Thanks for reading, and hope whatever comes out of this will help someone else in the future!
 

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215
Place the script in /bin, then run the cron with "find /bin --exec clear_plex_cache.sh" nothing happens.
Why are you using "find /bin..."? Just call the script directly with the full path.

Also have you?:
Add execution rights to the file: chmod +x your_script.sh

Take a look @Bidule0hm 's "Scripts to report SMART, ZPool and UPS status, HDD/CPU T°, HDD identification and backup the config" - "Script basics" Section for some guidance.
 

dragon_0n3

Dabbler
Joined
Jun 2, 2016
Messages
12
Hey, Mirfster!
Honestly, i used the find command because it seemed to pop up on every thread i read...so i thought it was needed lol
As for permissions (please don't kill me...), i used the ftp client (logged in as root) and gave 777 permission, which seemed to have worked.

So, following the suggested guide, i moved the script to /mnt/data1/scripts/clear_plex_cache.sh instead of /bin , used that line as the command for the cron, and ran the cron as root.
No dice.
 

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215
Well, here is a quick demo:

First I created the "Scripts" folder:
Code:
Welcome to FreeNAS
[root@ASC-FN01] ~# ls /mnt/ASC-Volume01/
./  ../
[root@ASC-FN01] ~# mkdir /mnt/ASC-Volume01/Scripts


Then I added a single line to a new file called "clear_plex_cache.sh" (which is located in the "Scripts" folder):
Code:
[root@ASC-FN01] ~# echo "echo Well Hello There Stud!" > /mnt/ASC-Volume01/Scripts/clear_plex_cache.sh


Then I set the execution rights:
Code:
[root@ASC-FN01] ~# chmod +x /mnt/ASC-Volume01/Scripts/clear_plex_cache.sh


Then I ran it:
Code:
[root@ASC-FN01] ~# /mnt/ASC-Volume01/Scripts/clear_plex_cache.sh
Well Hello There Stud!
[root@ASC-FN01] ~#


P.S. If you want to add multiple lines you can either use nano to open/edit the file or just use ">>" to append lines:
Code:
[root@ASC-FN01] ~# echo "echo Fancy Meeting You Here..." >> /mnt/ASC-Volume01/Scripts/clear_plex_cache.sh
[root@ASC-FN01] ~# /mnt/ASC-Volume01/Scripts/clear_plex_cache.sh
Well Hello There Stud!
Fancy Meeting You Here...
[root@ASC-FN01] ~#
 

dragon_0n3

Dabbler
Joined
Jun 2, 2016
Messages
12
:eek:EUREKA! IT WORKED!:eek:
I got suspicious when i read your last post, as you were editing in terminal....so i did, as well...
What do you know? stupid notepad/notepad++ was adding a stupid ^M at the end of each line!
The commands all worked great individually if running from terminal, but calling the script failed every time!
DAMN YOU, NOTEPAD!:mad:

Anyway, what i learned from this experience:
1. do your research
2. ask when your forehead starts hurting from banging the desk, don't wait for blood
3. DON'T BE LAZY AND USE THE DAMN TERMINAL TO EDIT SCRIPTS!!!!:D

Once i corrected the script, and updated the cron job to point to the new location, it worked without a hitch; the 'cache' folder went bye-bye...
Thank You, Mirfster, for all your help!

Again, hope this helps another n00b in his/her future FreeNAS implementation!
 

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215
Glad you are on track to "multimedia nirvana". Funny that NotePad++ was giving you problems, I use it for pretty much everything, but don't really recall that last time I used if for sh...

Either way, Welcome and enjoy. :)
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
What do you know? stupid notepad/notepad++ was adding a stupid ^M at the end of each line!

Actually it's not the editor who is stupid here because it should have been configured to use unix newline char (\n), not Windows newline chars (\r\n) :)
 

dragon_0n3

Dabbler
Joined
Jun 2, 2016
Messages
12
Actually it's not the editor who is stupid here because it should have been configured to use unix newline char (\n), not Windows newline chars (\r\n) :)

Oh well, did not know those counted! I learned something new, thank you!
And thank you for the constructive criticism.o_O
 

dragon_0n3

Dabbler
Joined
Jun 2, 2016
Messages
12
Glad you are on track to "multimedia nirvana". Funny that NotePad++ was giving you problems, I use it for pretty much everything, but don't really recall that last time I used if for sh...

Either way, Welcome and enjoy. :)
Yep, thanks a bunch!
Right! My notion was that programs like notepad and n++ "strip" formatting like that...oh well, as my stupidity has already been pointed out, what i wanted to do works, and I learned something...that's the most important!
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
My notion was that programs like notepad and n++ "strip" formatting like that...

Nope, a good editor will open a file as it is, it'll not modify it in any way ;)
 
Status
Not open for further replies.
Top