Having Trouble Getting. Sh Working with Crontab

Having Trouble Getting. Sh Working with Crontab

I've checked this link for suggestions but I can't seem to get a .sh script working. I'm new to Ubuntu and Linux (from Windows).

Why crontab scripts are not working?

Here is the dummy .sh I'm testing.

It's called testing.sh

#! /bin/bash

ls > testing.txt

Here is how my crontab looks like:

SHELL=/bin/bash

* * * * * "/home/name/Desktop/Instragram Scraper/Instagram looter/batch_scripts/testing.sh"

* * * * * "/home/name/Desktop/Instragram Scraper/Instagram looter/batch_scripts/daily_0.sh"

 ****other randoms cron jobs******

I've looked at the environmental paths for cron as well as the shell and but it seems they have variables in common so I'm assuming PATH is not a problem?

Here is Crontab's environmental variables (so I tried changing the shell command by adding it to the top of the cron file):

HOME=/home/name
LOGNAME=name
PATH=/usr/bin:/bin
LANG=en_US.UTF-8
SHELL=/bin/sh
PWD=/home/name

Here is env from the shell:

PATH=/home/name/bin:/home/name/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

SHELL=/bin/bash

Not sure what I'm doing wrong.

EDIT:

It seems the text files are being created under HOME, so I was looking at the wrong place. However when running a real (not dummy) cron command, the cron command doesn't seem to be running these commands from my .sh script:

"instalooter hashtag "donut" "/media/name/data/" -n 100 -j 2 --new"

basically the instalooter command doesn't seem to be running,

which if I run via the cmd line or if I run the same script via command line, those commands have no problem being ran.

Is this an variable problem?

Thank you.

4

1 Answer

You need to get a clear error message in order to solve this, although this appears to be a PATH variable problem(in such case you might need to concatenate path of your program to crontab PATH variable)

To get a clear error message from your command you need to redirect Standard Error Stream of the command to Standard Output Stream and redirect it to a file's input stream this can be achieved with 2>&1 operator, where the numbers represent file descriptors(wont go into details here).

command args > /debug.txt 2>&1

After modifying the the script once the crontab executes your script, you can look at debug.txt for error messages.

Your Answer

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

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.