LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 06-15-2012, 09:04 AM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Rep: Reputation: 16
script run fine from ./ but when put in cron does not run


Code:
#!/bin/bash

EmailAUFrom=server.address@company.com
EmailAUTo=my.address@company.com

rm /tmp/cert_watch.log /tmp/cert_srch.log
clear

sudo /usr/bin/find / -name *.cer > /tmp/cert_srch.log 2>/dev/null

exit

###

for line in `cat /tmp/cert_srch.log`
do
##   echo "working on cert $line"
  CertExpires=`openssl x509 -in $line -inform PEM -text \
     -noout -enddate | grep "Not After" | awk '{print $4, $5, $7}'`

   TodayPlus90=`date -ud "+90 day" | awk '{print $2, $3, $6}'`

##     echo "Cert Expires ~ " $CertExpires
##     echo "Today Plus 90 ~ " $TodayPlus90

   if [[ "$CertExpires" = "$TodayPlus90" ]]
   then
   echo $line "soon to expire cert being examined" >> /tmp/cert_watch.log
   nail -s "SSL Cert Monitor ~  $line EXPIRES on $CertExpires" -R "$EmailAUFrom" "$EmailAUTo" < /dev/null
   fi
done
this script executes fine manually from >./
but
when I set up cron and run

the file does get deleted and recreated but no data from the find. therefore, the rest of the script does not execute.

FYI: I am running this as a user not administrator and this executes from the users crontab.
 
Old 06-15-2012, 12:01 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
I'd imagine the problem is that you're using "sudo find" - the sudo's going to hang, waiting for the user's password. Is it possible to put it in root's crontab?
 
Old 06-15-2012, 12:53 PM   #3
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by j-me View Post
Code:
#!/bin/bash


sudo /usr/bin/find / -name *.cer > /tmp/cert_srch.log 2>/dev/null
this script executes fine manually from >./
but
when I set up cron and run

the file does get deleted and recreated but no data from the find. therefore, the rest of the script does not execute.

FYI: I am running this as a user not administrator and this executes from the users crontab.
It won't run "sudo /usr/bin/find" because it wants password.

good luck
 
Old 06-15-2012, 01:01 PM   #4
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
true

I can run this fine if looking ONLY in the home directory of the user but NOT outside. I assume because it is wanting a password.

It appears the only option is to run as root cron. Bummer! but understandable. regards
 
Old 06-15-2012, 03:41 PM   #5
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Rep: Reputation: 58
You can always add to /etc/sudoers something like "username ALL=NOPASSWD: ALL" and then it wont ask for pass or of course drop sudo or run the script as root.
 
Old 06-16-2012, 05:49 AM   #6
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,630
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
Quote:
Originally Posted by robertjinx View Post
You can always add to /etc/sudoers something like "username ALL=NOPASSWD: ALL" and then it wont ask for pass
If you do this be aware of the massive security risk - any malicious program can include "sudo rm -rf /" and it will execute without any problem because you've set 'sudo' to not ask for a password. Running the script as root is a better solution.
 
Old 06-16-2012, 10:02 AM   #7
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 561

Rep: Reputation: 58
Of course is a security risk, but it's a security risk if you let it be. There is no security risk if he knows what he's doing, or anyone, if you know how to protect your system.

I'm using this for years and somehow never ever anything happened, I wonder why
 
  


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] Cron run fails at random points, throws: Attempting to re-run cron while.... Nighteyes Linux - Newbie 2 06-22-2012 05:08 AM
Debian daily cron job won't run, but does run in cron.hourly. sandersch Linux - General 7 05-24-2012 01:50 AM
[SOLVED] Partial list with ls-l in bash script run in cron but full list run from command line redgshost Linux - General 29 01-16-2011 12:14 PM
script doesn't run in cron (runs from shell just fine) Timur Sakayev Linux - Software 6 02-26-2007 12:56 PM
php script will not run correctly as cron, fine from cli dtra Linux - Software 2 12-22-2005 07:21 AM


All times are GMT -5. The time now is 05:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration