LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-18-2017, 02:25 AM   #16
sharky
Member
 
Registered: Oct 2002
Posts: 569

Rep: Reputation: 84

Seems the best solution is to use root's crontab. Can you run 'sudo crontab -e'? If so, it eliminates the need for sudo in the script and the need to put your passwd in plain text in the script.
 
Old 05-18-2017, 02:51 AM   #17
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
Did you try to use quotes when piping your password?
I sending my password to sudo command like this:
Code:
echo "password" | sudo <command>
 
Old 05-22-2017, 07:45 AM   #18
Vpawar
LQ Newbie
 
Registered: May 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
yes i tried like same in my script but it is not giving proper output when i am running through crontab
 
Old 05-22-2017, 08:08 AM   #19
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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

Last edited by BW-userx; 05-22-2017 at 08:36 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] crontab not running script coralfang Linux - Software 1 09-10-2015 10:10 AM
Script is not running in Crontab Deepesh_tr Linux - Newbie 8 09-02-2012 07:43 PM
[SOLVED] Crontab Script Not Running th1bill Ubuntu 4 12-10-2010 03:49 PM
crontab not running script sunlinux Linux - Newbie 5 05-18-2010 06:21 AM
Running a script with crontab. glore2002 Slackware 3 06-05-2008 08:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration