SOLVED Cron Job script will not run

Status
Not open for further replies.

Jordan Boxer

Cadet
Joined
Dec 20, 2016
Messages
6
Hi,

I have a script that is designed to pull a couple of spreadsheets via a curl request. I've tested the script multiple times and works perfectly within the shell, however when I try to set it up as a cron job, not only does the script not run at the specified time, it doesn't run at all even when I tell it to "Run Now." I have set the file permissions to 777 and tried multiple syntax changes to my script and I'm still getting nothing.

Here is my /etc/crontab file (the script is fetch-spreadsheet.sh):
Code:
#                                                                                                                                
SHELL=/bin/sh                                                                                                                    
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin                                                                                          
#                                                                                                                                
#minute hour    mday    month   wday    who     command                                                                          
#                                                                                                                                
*/5     *       *       *       *       root    /usr/libexec/atrun > /dev/null 2>&1                                              
#                                                                                                                                
# Save some entropy so that /dev/random can re-seed on boot.                                                                    
*/11    *       *       *       *       operator /usr/libexec/save-entropy > /dev/null 2>&1                                      
#                                                                                                                                
# Rotate log files only at midnight.                                                                                            
0       0       *       *       *       root    newsyslog > /dev/null 2>&1                                                      
#                                                                                                                                
# Perform daily/weekly/monthly maintenance.                                                                                      
1       3       *       *       *       root    periodic daily                                                                  
15      4       *       *       6       root    periodic weekly                                                                  
30      5       1       *       *       root    periodic monthly                                                                
#                                                                                                                                
# Adjust the time zone if the CMOS clock keeps local time, as opposed to                                                        
# UTC time.  See adjkerntz(8) for details.                                                                                      
1,31    0-5     *       *       *       root    adjkerntz -a > /dev/null 2>&1                                                    
                                                                                                                                
0       *       *       *       *       root    /bin/sh /usr/local/sbin/save_rrds.sh > /dev/null 2>&1                            
                                                                                                                                
5       3       *       *       *       root    /bin/sh /usr/local/bin/telemetry-cron.sh > /dev/null 2>&1                        
                                                                                                                                
0       *       *       *       *       root    /usr/local/bin/python /usr/local/bin/mfistatus.py > /dev/null 2>&1              
1,31    *       *       *       *       root    /usr/local/bin/python /usr/local/www/freenasUI/tools/alert.py > /dev/null 2>&1  
                                                                                                                                
15      3       *       *       *       root    /usr/local/bin/python /usr/local/www/freenasUI/tools/cachetool.py expire >/dev/null
2>&1                                                                                                                            
30      3       *       *       *       root    /usr/local/bin/python /usr/local/www/freenasUI/tools/cachetool.py fill >/dev/null 2>
&1                                                                                                                              
45      3       *       *       *       root    /usr/local/bin/python /usr/local/www/freenasUI/middleware/notifier.py backup_db >/de
v/null 2>&1                                                                                                                      
0       3       *       *       *       root    find /tmp/ -iname "sessionid*" -ctime +1d -delete > /dev/null 2>&1              
30      */5     *       *       *       root    /etc/ix.rc.d/ix-kinit renew > /dev/null 2>&1                                    
*/10    *       *       *       *       root    [ -s /tmp/mail.queue ] && /usr/local/bin/python /usr/local/www/freenasUI/tools/mailq
ueue.py                                                                                                                          
45      3       *       *       *       root    /usr/local/libexec/nas/scrub -t 35 freenas-boot                                  
21      15      *       *       1,2,3,4,5       root    PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin
" /mnt/Vol001/scripts/fetch-spreadsheet.sh > /dev/null                                                                          
00      00      *       *       7       root    PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/bin" /usr/l
ocal/libexec/nas/scrub -t 35 Vol001                                                                                              
*       *       *       *       *       root    /usr/local/bin/python /usr/local/www/freenasUI/tools/autosnap.py > /dev/null 2>&1
14      1       *       *       *       root    /usr/local/bin/python /usr/local/www/freenasUI/tools/update_check.py > /dev/null 2>&
1                                                                                                                                
@weekly root /usr/local/sbin/update-smart-drivedb > /dev/null 2>&1


Here is my script (with the curl requests edited for security purposes):
Code:
#!/bin/sh                                                                                                                        
#                                                                                                                                
currentdate=$( date "+%Y-%m-%d" )                                                                                                
previousdate=$( date -v-3d "+%Y-%m-%d" )                                                                                        
yesterdaydate=$( date -v-1d "+%Y-%m-%d" )                                                                                        
filename1=analysis-${currentdate}.xlsx                                                                                          
filename2=transactions-${currentdate}.xlsx                                                                                      
filename3=analysis-${yesterdaydate}.xlsx                                                                                        
filename4=transactions-${yesterdaydate}.xlsx                                                                                    
echo                                                                                                                            
echo "Fetching $filename1"                                                                                                      
echo                                                                                                                            
curl -u xxx:xxx -O "xxx" "https://www.xxx.com/api/xxx" -o $filename1                                                                                    
echo                                                                                                                            
echo "Fetching $filename2"                                                                                                      
echo                                                                                                                            
curl -u xxx:xxx -O "xxx" "https://www.xxx.com/api/xxx" -o $filename2                                                                                  
echo                                                                                                                            
echo "Deleting yesterday's file: $filename3"                                                                                    
echo                                                                                                                            
rm $filename3                                                                                                                    
echo                                                                                                                            
echo "Deleting yesterday's file: $filename4"                                                                                    
echo                                                                                                                            
rm $filename4


So what gives? I'm honestly totally stuck right now and I'm not sure what to do. Any help would be much appreciated.

PS: I set up the cron job via the GUI

Thanks,

Jordan
 
Last edited:

Jordan Boxer

Cadet
Joined
Dec 20, 2016
Messages
6
Anything in /var/log/messages when you try to run now? I know this bug is slated to be fixed in the next update and am not sure if it is related: https://bugs.freenas.org/issues/20260.
Huh, it looks like it ran earlier? But why didn't the file save.. Do I need to specify the location elsewhere?
Code:
Feb 24 09:24:18 ashwood cronjob: Fetching analysis-2017-02-24.xlsx                                                                 
Feb 24 09:24:18 ashwood cronjob:                                                                                                   
Feb 24 09:24:18 ashwood cronjob: curl: Remote file name has no length!                                                             
Feb 24 09:24:18 ashwood cronjob: curl: try 'curl --help' or 'curl --manual' for more information                                   
Feb 24 09:24:18 ashwood cronjob:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                   
Feb 24 09:24:18 ashwood cronjob:                                  Dload  Upload   Total   Spent    Left  Speed                     
100 22549  100 22549    0     0   4513      0  0:00:04  0:00:04 --:--:--  4513                                                     
Feb 24 09:24:23 ashwood cronjob:                                                                                                   
Feb 24 09:24:23 ashwood cronjob: Fetching transactions-2017-02-24.xlsx                                                             
Feb 24 09:24:23 ashwood cronjob:                                                                                                   
Feb 24 09:24:23 ashwood cronjob: curl: Remote file name has no length!                                                             
Feb 24 09:24:23 ashwood cronjob: curl: try 'curl --help' or 'curl --manual' for more information                                   
Feb 24 09:24:23 ashwood cronjob:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current                   
Feb 24 09:24:23 ashwood cronjob:                                  Dload  Upload   Total   Spent    Left  Speed                     
100  4966  100  4966    0     0   3179      0  0:00:01  0:00:01 --:--:--  3181                                                     
Feb 24 09:24:25 ashwood cronjob:                                                                                                   
Feb 24 09:24:25 ashwood cronjob: Deleting yesterday's file: analysis-2017-02-23.xlsx                                               
Feb 24 09:24:25 ashwood cronjob:                                                                                                   
Feb 24 09:24:25 ashwood cronjob: rm: analysis-2017-02-23.xlsx: No such file or directory                                           
Feb 24 09:24:25 ashwood cronjob:                                                                                                   
Feb 24 09:24:25 ashwood cronjob: Deleting yesterday's file: transactions-2017-02-23.xlsx                                           
Feb 24 09:24:25 ashwood cronjob:                                                                                                   
Feb 24 09:24:25 ashwood cronjob: rm: transactions-2017-02-23.xlsx: No such file or directory
 

sthames42

Cadet
Joined
Jul 20, 2017
Messages
3
I am having the same problem but all I'm getting in /var/log/messages is this:
Jul 20 14:23:13 backup1 kernel: pid 39270 (python3.6), uid 0: exited on signal 6 (core dumped)

This is not the script I want to run but this is what I am testing with:
#!/bin/sh

I'm stuck and cannot use cron which I need to do.
Please help.

Running 11.0-STABLE on HP Proliant DL380-G5.
Boot device is mirrored USB drives.
 
Last edited:
D

dlavigne

Guest
Please create a separate thread with the details of your hardware, OS build version, and the script you are trying to run.
 
Status
Not open for further replies.
Top