I do not know how mission critical your script needs to be ran as far as 'it has to be ran at this time then it then has to be send out right away in an email' that may or may not be read until whenever that other person gets around to it. Not to negate the importance of data that it is gathering at a certain time.
I only use one "home made" script within CRON's world. I put it inside of the /etc/cron.weekly and it runs once a week. root side - it is for trimming my sdd hdd. This is on a laptop. So however CRON actually works in what time it gets ran once a week I have not even bothered to look into. due to this laptop can miss whatever that time is. so maybe it does not get ran due to that. I do not even check its log.
But I did just now because of this issue you are having.
Code:
userx%voider ⚡ log ⚡> sudo cat trim.log
*** Fri, 03 Mar 2017 08:58:01 -0400 ***
/: 4.8 GiB (5174210560 bytes) trimmed
/home: 15 GiB (16130535424 bytes) trimmed
*** Fri, 03 Mar 2017 10:11:23 -0400 ***
/: 4.8 GiB (5166546944 bytes) trimmed
/home: 84.6 GiB (90783952896 bytes) trimmed
*** Fri, 10 Mar 2017 14:50:01 -0400 ***
/: 13.8 GiB (14822666240 bytes) trimmed
/home: 71.9 GiB (77222420480 bytes) trimmed
*** Sat, 18 Mar 2017 08:07:01 -0400 ***
/: 13.7 GiB (14731264000 bytes) trimmed
/home: 70.9 GiB (76139053056 bytes) trimmed
*** Mon, 27 Mar 2017 18:50:01 -0400 ***
/: 13 GiB (13977968640 bytes) trimmed
/home: 63 GiB (67591225344 bytes) trimmed
*** Mon, 03 Apr 2017 18:50:01 -0400 ***
/: 12.4 GiB (13296070656 bytes) trimmed
/home: 50.7 GiB (54410817536 bytes) trimmed
*** Tue, 11 Apr 2017 12:27:01 -0400 ***
/: 2.1 GiB (2201567232 bytes) trimmed
/home: 57.6 GiB (61817339904 bytes) trimmed
*** Thu, 20 Apr 2017 16:27:01 -0400 ***
/: 10.7 GiB (11496017920 bytes) trimmed
/home: 54.7 GiB (58755768320 bytes) trimmed
*** Thu, 04 May 2017 08:14:01 -0400 ***
/: 10 GiB (10782162944 bytes) trimmed
/home: 4.7 GiB (5042810880 bytes) trimmed
*** Fri, 12 May 2017 17:27:01 -0400 ***
/: 9.1 GiB (9804017664 bytes) trimmed
/home: 59 GiB (63301070848 bytes) trimmed
*** Fri, 19 May 2017 17:27:01 -0400 ***
/: 9 GiB (9646407680 bytes) trimmed
/home: 52.7 GiB (56586903552 bytes) trimmed
userx%voider ⚡ log ⚡>
It trims both / (root) and /home
as you can see it did not run the very same day of the week because I do not have this thing on 24/7 for it to keep a tight schedule, perhaps that is how CRON works. If it misses that day/time it was suppose to run then run it first chance it gets when having it just sitting in one of the directories to be ran.
now saying that the script of yours does not run the same in a command issued job for CRON.
"it is not giving proper output when i am running through crontab"
which is too vague of a "hey this thing is not working still", Thinking the ones you are telling this to will know just what it is you are talking about without showing what it is doing now against what it is suppose to be doing. One is only left with having to go into dream land to try and figure out what it is actually doing that it is not suppose to be doing.
But, seeings how you have been fiddling with this script for more than a day. what is one more day or two?
if it is a weekly and you run your PC 24/7 it should / is suppose to then run every hour, day, week, month, year at whatever given time.
Even with a user input'ed CRON Job if that PC is not turned on then it still cannot run that job and CRON still has to wait for it to be turned on to do so.
so what is the harm in trying to just add your script into the root sided /etc/cron.xx directory and lets CRON take care of it like that?
your Job is just gathering info and sending an E Mail to someone else. no permissions are really needed to be worried about in setting them on an e mail or having root sending an email a non root user has to read. it is e mail not a file on a system somewhere where permissions are needed to read it depending on where it is at.
that way too it is already root so no password is needed. You'd have to just dig in and find out how exactly does these directories work on getting it to run at a certain time if one is just placed within it to be ran without assigning a job through CRON crontab
this one is mine:
Code:
/etc/cron.weekly:
trim
these are the scripts that the system put in all by itself that I pay no attention to either.
Code:
/etc/cron.daily:
makewhatis shadow updatedb