LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 04-23-2014, 06:12 AM   #1
mitter1989
Member
 
Registered: Sep 2013
Posts: 47

Rep: Reputation: Disabled
Question Script is not running properly through crontab but working from command line


Hi Folks,

I have been facing an issue, I have wrote a very simple script which is running fine if run manually but its not working while run through crontab :

Is there any issue with awk?

#!/bin/bash
LOGSD=`date +%Y%m%d`
IN=$(less *$LOGSD.gz |awk '{ SUM += $7} END { print SUM/1024/1024 }')
echo "IN : $IN" >> /home/output.txt



Thanks in advance.
 
Old 04-23-2014, 06:31 AM   #2
eudald
LQ Newbie
 
Registered: Apr 2014
Posts: 10

Rep: Reputation: 1
Hi mitter1989,
first of all I would recommend you to put {} to delimit your variables, in case of.

Could it be possible that the problem belongs to not finding this file in the appropriate path? Try to always work with absolute paths.

Regards,
Eudald
 
Old 04-23-2014, 07:25 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As hinted, the cron environment is notoriously limited, so always use full absolute paths to all cmds and files, unless you have otherwise amended the env first eg by sourcing stuff that sets up a better env.
 
Old 04-23-2014, 08:36 AM   #4
mitter1989
Member
 
Registered: Sep 2013
Posts: 47

Original Poster
Rep: Reputation: Disabled
Question

Hi eudald,

Thanks for your reply.

I used absolute path too but not work for me.

I put this command in my script :

less /disk1/log/*20140423.gz | /bin/awk '{ SUM += $7 } END { print SUM/1024/1024 }' > /home/output.txt


It has created an empty file which means cron is running but awk is not working as desired.


While running this script manually it is working absolutly fine, but it is not when running through cron.

can u please guide me or can u share command to get this done? why it happens?
 
Old 04-23-2014, 01:07 PM   #5
yo8rxp
Member
 
Registered: Jul 2009
Location: Romania
Distribution: Ubuntu 10.04 Gnome 2
Posts: 102

Rep: Reputation: 31
so what if putting da' script into a shell file ,and inside after #!/bin/bash put some cd towards it's own absolute path ?
Not sure but could be that DASH cannot compute well math as BASH does.

Then rerun cron in this way

Code:
30 04 * * * /home/proxima1/bkp_script/bkp.sh
____________________
Sorry for quick jump , missed that you allready run shell file via cron ....hummm!

Are ya sure you edited root crontab instead of regular user crontab ?

Last edited by yo8rxp; 04-23-2014 at 01:18 PM.
 
Old 04-23-2014, 01:46 PM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The less command must be tied to a screen in order to work properly and this condition is not true for crontab jobs. Try zcat instead.
 
Old 04-24-2014, 12:16 AM   #7
mitter1989
Member
 
Registered: Sep 2013
Posts: 47

Original Poster
Rep: Reputation: Disabled
Thumbs up

Thank you folks...

Issue got resolved with zcat command as suggested by colucix.


Thank you colucix for your kind support and I will keep posting such issues...
 
  


Reply



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] Problem with crontab:: command not executed properly via crontab Ankush Seth Linux - Newbie 11 11-11-2013 06:25 AM
From command line to a crontab script alaios Programming 12 04-20-2013 04:02 AM
my database export shell script run from command line but not form crontab saifee Linux - General 11 01-29-2012 09:24 AM
running a php script from command line leicaphotos Linux - Newbie 1 10-10-2008 01:24 PM
auto running a script from command line millionknives Slackware 7 10-03-2005 10:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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