LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-22-2014, 11:45 AM   #1
thealmightyos
Member
 
Registered: Mar 2009
Distribution: CentOS 6.5 / 7
Posts: 119

Rep: Reputation: 1
Question crontab + scripts with variables


I am very, very confused.

I have a very simple script that I want cron to run. This script takes the output of another script I created (that WILL run in cron) and outputs it to a file as well as prints the file to my local printer.

Here is the script:
Code:
_now=$(date +"%Y_%m_%d-%I%p")
_file="eDMStatus_$_now.txt"

/home/TheAlmightyOS/edm_reports/report.sh > "$_file" 
lp /home/TheAlmightyOS/edm_reports/"$_file"
I run this script from the command line and it does exactly what it is intended to do. However, the moment I put it in crontab.... nothing.

I tested my crontab entry by replacing this file with report.sh >> crontest.log and it worked flawlessly. So the cron setup is not the issue. I think it is something in my script it doesn't like. Any suggestions?
 
Old 08-22-2014, 11:58 AM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 172

Rep: Reputation: 56
Do you know where it is getting stuck? Is it running report.sh, but not printing, or doing neither?

The script will create the file in whatever directory you're in (I believe it defaults to your home directory when running from cron). It's possible your file is not where your script is trying to print it from.

Have you tried setting your PATH variable in the script? I've found this can also often causes issues when running from cron.

Last edited by thesnow; 08-22-2014 at 12:03 PM. Reason: path
 
1 members found this post helpful.
Old 08-22-2014, 02:55 PM   #3
thealmightyos
Member
 
Registered: Mar 2009
Distribution: CentOS 6.5 / 7
Posts: 119

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by thesnow View Post
Do you know where it is getting stuck? Is it running report.sh, but not printing, or doing neither?

The script will create the file in whatever directory you're in (I believe it defaults to your home directory when running from cron). It's possible your file is not where your script is trying to print it from.

Have you tried setting your PATH variable in the script? I've found this can also often causes issues when running from cron.
You just solved it! I changed
Code:
/home/TheAlmightyOS/edm_reports/report.sh > "$_file"
to
Code:
/home/TheAlmightyOS/edm_reports/report.sh > /home/TheAlmightyOS/edm_reports/"$_file"
and now it is printing.

Changed my settings back to 30 8,13,17 * * * so I am not printing out a ream of paper every hour and looks like it is good. Thanks for the help!
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Export variables within the script. How to crontab it? rs232 Linux - Newbie 4 07-23-2012 05:00 AM
some cool crontab scripts djgerbavore Linux - Newbie 1 05-25-2005 10:14 AM
/etc/crontab & environment variables gepesz Linux - Software 3 09-03-2004 02:26 AM
Setting global variables from a crontab job davee Programming 2 10-06-2003 08:05 AM
crontab and scripts Kent Emia Linux - General 6 10-02-2003 06:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:24 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