-1

ive written a couple a couple of scripts. are they going to work indefinatly and will them eventually overload the CPU?

firstly this is on a local nas that for some reason the manufacturer does not give root access or su i have an admin account so i cant just call the script with cron

first script

#!/bin/bash
#connect to server download files

rsync -ae "ssh -p 10045 -T -o Compression=no -x" --progress appbox@filebot.witzend007.appboxes.co:/APPBOX_DATA/apps/rutorrent.witzend007.appboxes.co/torrents/completed/toNAS /mnt/md0/User/admin/home/incomingdata/ --delete

wait

#copy files to temp folder
cp -r /mnt/md0/User/admin/home/incomingdata/toNAS /mnt/md0/User/admin/home/incomingdata/temp

wait

#Start Filebot and organise and rename files to plex library
~/filebot-portable/filebot.sh -script fn:amc --output "/mnt/md0/public/Media" --action move -non-strict "/mnt/md0/User/admin/home/incomingdata/temp" --log-file amc.log --def excludeList=amc.txt

wait

#remove temp folder/files

rm -r /mnt/md0/User/admin/home/incomingdata/temp

wait

#start sleep script
( "/mnt/md0/User/admin/home/filebot-portable/martinsleep.sh" )

calls the second script (which waits set time and recalls the first script)

#!/bin/bash

sleep 60
wait
( "/mnt/md0/User/admin/home/filebot-portable/martinsamc.sh" )

and then i exit vssh using

  • ctrl-z
  • bg
  • disown

this method is working the script is continuing to run in the background with vssh closed down

i do plan on changing the sleep time to 30mins my worry is that this is just opening tonnes of scripts and will eventually eat resources

Is there a better way of me achieving this?

  • 1
    What do you think the wait command does? It's currently a no-op because there's nothing to wait for. – roaima Jan 17 at 23:26
  • well some of the commands take a while to complete and i thought wait allows the last command to complete before doing the next command – Martin Robertson Jan 17 at 23:28
  • 1
    Each command completes before the script progresses to the next item – roaima Jan 17 at 23:31
  • lol i did say i was a n00b i must of misunderstood it somewhere my worry is that my second command would start before the rsync had completed and started moving around half downloaded data. thanks – Martin Robertson Jan 17 at 23:34
0

Your scripts keep calling each other, so eventually you'll run out of stack space or memory (but probably not for many years).

As better coding, you should consider using a single script that pauses for a minute before looping:

#!/bin/bash
incoming=/mnt/md0/User/admin/home/incomingdata

while :
do
    # connect to server download files
    rsync -ae "ssh -p 10045 -T -o Compression=no -x" --progress  --delete appbox@filebot.witzend007.appboxes.co:/APPBOX_DATA/apps/rutorrent.witzend007.appboxes.co/torrents/completed/toNAS "$incoming/"

    # copy files to temp folder
    cp -r "$incoming/toNAS/." "$incoming/temp"

    # Start Filebot and organise and rename files to plex library
    ~/filebot-portable/filebot.sh -script fn:amc --output "/mnt/md0/public/Media" --action move -non-strict "$incoming/temp" --log-file amc.log --def excludeList=amc.txt

    # remove temp folder/files
    rm -r "$incoming/temp"

    # Wait 60 seconds
    sleep 60
done
  • thanks for the update i can see now how easy youve made this look. i had seen this method but didnt know how to write it. i couldnt see how it restarts the script so wasnt sure if it would work or not. thanks – Martin Robertson Jan 17 at 23:37
  • @MartinRobertson you don't need to restart the script. You start this one off and it loops forever (the while : is a lazy shorthand for while true). – roaima Jan 17 at 23:53
  • Out of interest, what make is your NAS that doesn't permit shell access? I've got QNAPs around all of our offices globally and they do allow SSH access to crontab, etc. – roaima Jan 17 at 23:55
  • its a tnas terramaster wish i hadnt bothered its been one thing after the other. i have ssh access but only user admin cant sudo, su or access cron cant actually do alot with it. – Martin Robertson Jan 18 at 0:53
  • btw thank you after viewing my process with ps auxf i could see my script was just one long line after another. yours works so much better so thanks again. – Martin Robertson Jan 18 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.