Cron does not start after reboot

Questions about SNMP, Power, System, Logs, disk, & RAID.
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Cron does not start after reboot

Post by pwilson »

Phifer wrote:Yes,

http://forum.qnap.com/viewtopic.php?f=2 ... 78#p466472
I'll provide another when I get back to the dorms. I am on my phone right now.
My fault. I missed it. Thanks.
I actually want to see it after it has been run by Cron. Running them manually does nothing to troubleshoot Cron.

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Cron does not start after reboot

Post by Phifer »

No worries. I did add it again using Remote Desktop.

http://forum.qnap.com/viewtopic.php?f=2 ... 15#p466485
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Cron does not start after reboot

Post by pwilson »

Phifer wrote:No worries. I did add it again using Remote Desktop.

http://forum.qnap.com/viewtopic.php?f=2 ... 15#p466485
If those were run by Cron, then you've proven that the script itself is actually being run, so now you simply need to troubleshoot your scripts. Simply bear in mind that Cron does not use your "Custom" $PATH, so you need to use "absolute" paths to all the executable commands you want your script to run.

I know nothing about "filebot", so I can't help much with it, but I would be more than happy to check the syntax of any of your scripts you decide to share here.

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Cron does not start after reboot

Post by Phifer »

Looked again when I got home. Looks like it only keeps the most recent log. These were completed with Cron. I am rebooting now and will look again in the morning. I have also pasted the scripts in case you see anything that needs fixed.

Code: Select all

-rw-r--r--    1 admin    administ         0 Mar  5 18:52 /tmp/-sh.ran
-rw-r--r--    1 admin    administ         0 Mar  5 22:28 /tmp/remove.sh.ran
-rw-r--r--    1 admin    administ         0 Mar  5 22:30 /tmp/ts.sh.ran
ts.sh

Code: Select all

#!/bin/sh
#
# Filebot Cleanup script
#
/share/CACHEDEV1_DATA/.qpkg/Optware/bin/filebot -script fn:amc --output "/share/Multimedia" --log-file amc.log --action move --conflict override --def music=y --def subtitles=en  --def artwork=y --def clean=y  --def plex=localhost:Vtsm5xKx1g7hz4 -non-strict "/share/Download/transmission/completed" --def excludeList=amctrans.txt
#
/bin/touch /tmp/$(/usr/bin/basename $0).ran
#done
remove.sh (removes finished torrents from transmission so filebot can move them without error)

Code: Select all

# !/bin/sh

# script to check for complete torrents in transmission folder, then stop and move them

# get torrent list from transmission-remote list
# delete first / last line of output
# remove leading spaces
# get first field from each line
TORRENTLIST=`transmission-remote -n admin:admin -l | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f1`

# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
  echo "Checking torrent ID $TORRENTID..."

  STARTED=`transmission-remote -n admin:admin -t $TORRENTID -i | grep "Id: $TORRENTID"`
  echo " - started state = $STARTED"

  COMPLETED=`transmission-remote -n admin:admin -t $TORRENTID -i | grep "Finished"`
  echo " - completed state = $COMPLETED"

  if [ "$STARTED" != "" ]; then
    echo "Torrent #$TORRENTID is started"
    if [ "$COMPLETED" = "" ]; then
      echo "Torrent #$TORRENTID is still running"
    else
      echo "Torrent #$TORRENTID is $COMPLETED"
      transmission-remote -n admin:admin -t $TORRENTID --stop
      transmission-remote -n admin:admin -t $TORRENTID --remove
    fi
  fi
done
/bin/touch /tmp/$(/usr/bin/basename $0).ran
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
User avatar
pwilson
Guru
Posts: 22533
Joined: Fri Mar 06, 2009 11:20 am
Location: Victoria, BC, Canada (UTC-08:00)

Re: Cron does not start after reboot

Post by pwilson »

Phifer wrote:Looked again when I got home. Looks like it only keeps the most recent log. These were completed with Cron. I am rebooting now and will look again in the morning. I have also pasted the scripts in case you see anything that needs fixed.

Code: Select all

-rw-r--r--    1 admin    administ         0 Mar  5 18:52 /tmp/-sh.ran
-rw-r--r--    1 admin    administ         0 Mar  5 22:28 /tmp/remove.sh.ran
-rw-r--r--    1 admin    administ         0 Mar  5 22:30 /tmp/ts.sh.ran
This is correct, it only records the "last" time it was run. If you want to log it to a file, then that is more complicated. If you log to the RAMdisk you could overfill the RAMDisk, causing a "crash", while if you log it to the HDD's, then it will "wake up the drives" which would prevent "spindown". My method while only saving the date/time of the "last run" (ran), consumes no space, as it is a zero-byte file, that merely consumes space for the filename/date/time which is merely a few bytes, which is therefore unlikely to overfile your RAMDisk.
Phifer wrote: ts.sh

Code: Select all

#!/bin/sh
#
# Filebot Cleanup script
#
/share/CACHEDEV1_DATA/.qpkg/Optware/bin/filebot -script fn:amc --output "/share/Multimedia" --log-file amc.log --action move --conflict override --def music=y --def subtitles=en  --def artwork=y --def clean=y  --def plex=localhost:Vtsm5xKx1g7hz4 -non-strict "/share/Download/transmission/completed" --def excludeList=amctrans.txt
#
/bin/touch /tmp/$(/usr/bin/basename $0).ran
#done
remove.sh (removes finished torrents from transmission so filebot can move them without error)

Code: Select all

# !/bin/sh

# script to check for complete torrents in transmission folder, then stop and move them

# get torrent list from transmission-remote list
# delete first / last line of output
# remove leading spaces
# get first field from each line
TORRENTLIST=`transmission-remote -n admin:admin -l | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f1`

# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
  echo "Checking torrent ID $TORRENTID..."

  STARTED=`transmission-remote -n admin:admin -t $TORRENTID -i | grep "Id: $TORRENTID"`
  echo " - started state = $STARTED"

  COMPLETED=`transmission-remote -n admin:admin -t $TORRENTID -i | grep "Finished"`
  echo " - completed state = $COMPLETED"

  if [ "$STARTED" != "" ]; then
    echo "Torrent #$TORRENTID is started"
    if [ "$COMPLETED" = "" ]; then
      echo "Torrent #$TORRENTID is still running"
    else
      echo "Torrent #$TORRENTID is $COMPLETED"
      transmission-remote -n admin:admin -t $TORRENTID --stop
      transmission-remote -n admin:admin -t $TORRENTID --remove
    fi
  fi
done
/bin/touch /tmp/$(/usr/bin/basename $0).ran
I don't need to worry about this issue. I "hardlink" my files from my Transmission "Completed" folder to my Multimedia share, so that I can play with them immediately (even if they are still seeding). I can then delete them in Transmission at my own whim, as they are already in my Movie folder (within my Multimedia share)

ie:

Code: Select all

ln /share/Download/transmission/completed/MyCoolMovie.mp4 /share/Multimedia/Video/Movies/HD/MyCoolMovie.mp4
Because I "hardlink" the files, I can delete either filename, and the file stays where it is. Also because I "hardlink" rather than "copy" the files, they consume no additional space whatsoever. Also you can "hardlink" a file of any size in 0.1secs. If you "copy" them, then you are in fact making a second copy, so it has to "copy" the entire file "contents" of the file, rather than just creating a secondardy "filename" for the exact same physical file. This is particularly useful with large files like BD Rips. It takes a while to "copy" a 25GB file, even on my TS-470 Pro. A hardlink is "instant"!

Understanding the subtle differences between the "cp" (copy), "mv" (move), and "ln" (link) commands and using each one appropriately can greatly improve your life. Similarly understanding the differences between a "hardlink" and a "symlink" and using these appropriately is also important. If you don't understand the differences, you should not attempt to emulate my method; using these inappropriately can cause data loss.

Be particularly careful not to place files in your RAMDisk by accident, as this will crash the NAS if you overfill it. When it doubt you can use the "df -h" command to check it. For example you probably don't know that "/var/log" is part of the RAMDisk, but you can verify this at your end with:

Code: Select all

df -h /var/log


This command will return:

Code: Select all

df -h /var/log
Filesystem            Size  Used Avail Use% Mounted on
none                  200M  150M   51M  75% /
The NAS runs off a RAMDisk, so the root directory (/) of the filesystem is in fact a RAMDisk.
It's a pity File Station doesn't provide a method of creating "hardlinks" nor "symlinks".

Patrick M. Wilson
Victoria, BC Canada
QNAP TS-470 Pro w/ 4 * Western Digital WD30EFRX WD Reds (RAID5) - - Single 8.1TB Storage Pool FW: QTS 4.2.0 Build 20151023 - Kali Linux v1.06 (64bit)
Forums: View My Profile - Search My Posts - View My Photo - View My Location - Top Community Posters
QNAP: Turbo NAS User Manual - QNAP Wiki - QNAP Tutorials - QNAP FAQs

Please review: When you're asking a question, please include the following.
Phifer
Getting the hang of things
Posts: 84
Joined: Sun Nov 02, 2014 7:13 pm

Re: Cron does not start after reboot

Post by Phifer »

I did reboot last night and did not run any commands after. I got up this morning and got the following.

Code: Select all

-rw-r--r--    1 admin    administ         0 Mar  6 08:28 /tmp/remove.sh.ran
-rw-r--r--    1 admin    administ         0 Mar  6 08:30 /tmp/ts.sh.ran
This means that Cron is working now. To make sure I performed another reboot and once again did not run the restart command for Cron. At the next half hour the results were:

Code: Select all

-rw-r--r--    1 admin    administ         0 Mar  6 09:28 /tmp/remove.sh.ran
-rw-r--r--    1 admin    administ         0 Mar  6 09:30 /tmp/ts.sh.ran
I know we made some changes to my ts.sh script that uses filebot, and also changed the path in cron.
Whatever we did it is working correctly now. Thank you for your help.
I will look into hardlinks, but currently I use filebot because it not only moves my files, but fixes filenames, grabs subtitles, artwork, and tells plex to rescan my library.
TS-651 / (1) 8gb stick crucial ram / (2) 3tb WD red hard drives (Raid1) / (4) 10tb HGST Deskstar NAS 7200 rpm (Raid5) / FW QTS 4.2.5 / OSX Operating system
One Ethernet port connected to my private network
ayone
First post
Posts: 1
Joined: Fri Aug 12, 2016 1:54 pm

Re: Cron does not start after reboot

Post by ayone »

I also have same problem.
My python script does not work unless I execute "/etc/init.d/crond.sh restart" after every reboot.
I have confirmed added line exists in "/etc/config/crontab" .
Any solution yet ?
davep89
New here
Posts: 8
Joined: Sun Jul 29, 2012 4:42 pm

Re: Cron does not start after reboot

Post by davep89 »

Hi Phifer, on the off chance you're still interested in this thread, did you ever resolve this? I have exactly the same issue.

Regards

David
solitone
Starting out
Posts: 28
Joined: Mon Dec 05, 2016 1:57 pm

Re: Cron does not start after reboot

Post by solitone »

As it was suggested, this problem depends on a PATH variable that does not contain /opt/bin or /opt/sbin.

You could correct all your scripts, so that they reference absolute paths rather than relative. However this may be annoying, especially if you're using scripts for standard Linux systems, which you'd rather leave unchanged--e.g. backup2l.

I advise you to write a script that calls the external script, and reinitialise in your script the PATH variable. Then cron starts your script which in turn starts the standard one, and the PATH variable now is complete in both.

To value the path variable you need something like this:

Code: Select all

# !/bin/sh
PATH=/opt/bin:/opt/sbin:$PATH
filebot -script fn:amc --output "/share/Multimedia" --log-file amc.log --action move --conflict override --def music=y --def subtitles=en --def artwork=y --def clean=y  --def plex=localhost:Vtsm45VGesUxKx1g7hz4 -non-strict "/share/Download/transmission/completed" --def excludeList=amctrans.txt
mclancer99
New here
Posts: 3
Joined: Fri Aug 04, 2017 4:03 am

Re: Cron does not start after reboot

Post by mclancer99 »

I changed my two scripts to absolute paths and they still do not run after a reboot. It's so frustrating.

It doesn't look like pwilson posts here anymore, can anyone else help?

My Crontab

Code: Select all

# m h dom m dow cmd
0 3 * * * /usr/local/sbin/ImR_all -soft /Qmultimedia
0 2 * * * /sbin/qfstrim
0 3 * * 0 /etc/init.d/idmap.sh dump
0 4 * * * /sbin/hwclock -s
0 3 * * * /sbin/vs_refresh
0 3 * * * /sbin/clean_reset_pwd
0-59/15 * * * * /etc/init.d/nss2_dusg.sh
30 7 * * * /sbin/clean_upload_file
0-59/10 * * * * /etc/init.d/storage_usage.sh
30 3 * * * /sbin/notice_log_tool -v -R
0-59/20 3 * * * /sbin/adjust_time
*/10 * * * * /sbin/config_cache_util 0
24 * * * * /sbin/qddns_check 2>/dev/null
*/10 * * * * /share/CACHEDEV1_DATA/media/scripts/DownloadFiles.sh && /share/CACHEDEV1_DATA/media/scripts/ProcessIncoming.sh
0 9,21 * * * /sbin/notify_update -m -s -p 1>/dev/null 2>&1
* * * * * /var/cache/netmgr/lock_timer.sh
* * * * * /var/cache/netmgr/detect_defaultgw_internet.sh
4 3 * * 3 /etc/init.d/backup_conf.sh
42 10 * * * /mnt/ext/opt/QcloudSSLCertificate/bin/ssl_agent_cli
35 7 * * * /sbin/qsyncsrv_util -c  > /dev/null 2>/dev/null
DownloadFiles.sh (downloads files from a remote server)

Code: Select all

#!/bin/bash

cd /share/CACHEDEV1_DATA/media/incoming

lftp -p port -u username,password ftp://123.456.78.9 << EOF

set mirror:use-pget-n 8
set ftp:sync-mode off
set ftp:use-mdtm off
set ssl:verify-certificate no
set ftp:ssl-allow true
set ftp:ssl-force true

mirror -c -P1  --Remove-source-files --Remove-source-dirs --no-empty-dirs --no-perms        /files/Sonarr/     /share/CACHEDEV1_DATA/media/incoming

quit
EOF

# Pass back the return code from lftp so errors are reported
exit $?
ProcessIncoming.sh (moves the download files and applies permissions)

Code: Select all

#!/bin/bash

cd /share/CACHEDEV1_DATA/media/incoming 

# Additional processing can be inserted here (like renaming if needed).

# Copy the finished files over into position
tar cf - . | (cd /share/CACHEDEV1_DATA/media/recordedtv ; tar xf - )

# Delete local files
rm -rf *

cd /share/CACHEDEV1_DATA/media

chmod -R 777 recordedtv
chown -R admin:administrators recordedtv

# All done, exit cleanly
exit 0
Edit:
I tried pwilson's tests and:

Looks like cron is running

Code: Select all

[~] # /bin/ps w | grep cron | grep -v grep
14177 admin      1908 S   /usr/sbin/crond -l 9 -c /tmp/cron/crontabs
I added this to my scripts

Code: Select all

/bin/touch /tmp/$(/usr/bin/basename $0).ran
But when I check if the scripts ran I get

Code: Select all

[~] # ls -alF /tmp/*.ran
-rw-r--r--    1 admin    administ         0 Aug  9 12:20 /tmp/DownloadFiles.sh.ran
Looks like the first script tries to run? I'm not sure if the second script would show up here because I have them running together in cron. The scripts run fine if I manually restart cron, so I don't know what the problem is.
mclancer99
New here
Posts: 3
Joined: Fri Aug 04, 2017 4:03 am

Re: Cron does not start after reboot

Post by mclancer99 »

I have spent countless hours trying to figure this out. @Phifer and I cannot be the only ones who have had this problem. Someone please help, I'll try anything at this point.
User avatar
Toxic17
Ask me anything
Posts: 6469
Joined: Tue Jan 25, 2011 11:41 pm
Location: Planet Earth
Contact:

Re: Cron does not start after reboot

Post by Toxic17 »

mclancer99 wrote:It doesn't look like pwilson posts here anymore, can anyone else help?
You are correct - pwilson passed away a few years back.

I suggest you contact QNAP support rather that try to reopen old threads.

https://helpdesk.qnap.com/index.php?/Tickets/Submit
Regards Simon

Qnap Downloads
MyQNap.Org Repository
Submit a ticket • QNAP Helpdesk
QNAP Tutorials, User Manuals, FAQs, Downloads, Wiki
When you ask a question, please include the following


NAS: TS-673A QuTS hero h5.1.2.2534 • TS-121 4.3.3.2420 • APC Back-UPS ES 700G
Network: VM Hub3: 500/50 • UniFi UDM Pro: 3.2.9 • UniFi Network Controller: 8.0.28
USW-Aggregation: 6.6.61 • US-16-150W: 6.6.61 • 2x USW Mini Flex 2.0.0 • UniFi AC Pro 6.6.62 • UniFi U6-LR 6.6.62
UniFi Protect: 2.11.21/8TB Skyhawk AI • 3x G3 Instants: 4.69.55 • UniFi G3 Flex: 4.69.55 • UniFi G5 Flex: 4.69.55
mclancer99
New here
Posts: 3
Joined: Fri Aug 04, 2017 4:03 am

Re: Cron does not start after reboot

Post by mclancer99 »

Toxic17 wrote:
You are correct - pwilson passed away a few years back.

I suggest you contact QNAP support rather that try to reopen old threads.

https://helpdesk.qnap.com/index.php?/Tickets/Submit
I'm very sorry to hear that. He seemed like a very knowledgeable person with a good heart and enjoyed helping others. We clearly need more people like him.

I made the jump to QNAP after many years and several NASes with Synology. In my experience, the forums are not only faster, but have many users with far more experience than the average support tech, much like pwilson.

Seeing as other users have had this same issue going back at least a few years, it does not seem like QNAP cares to fix the problem.

But sure, I will contact QNAP support.
ethanopp
Starting out
Posts: 14
Joined: Wed Feb 22, 2017 11:22 am

Re: Cron does not start after reboot

Post by ethanopp »

Anyone ever get a solution for this?

...I am having same issue. New lines are in crontab file after reboot but they don't run until I manually shh and run "crontab /etc/config/crontab && /etc/init.d/crond.sh restart"
ethanopp
Starting out
Posts: 14
Joined: Wed Feb 22, 2017 11:22 am

Re: Cron does not start after reboot

Post by ethanopp »

mclancer99?
Post Reply

Return to “System & Disk Volume Management”