Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-01-2012, 12:18 PM   #1
Srinivas Gadi
LQ Newbie
Registered: Dec 2012
Posts: 22

Rep: Reputation: Disabled
Crontab is giving different result when execute the script on terminal

Hi All

I wonder when I execute the below command on terminal

SFILE=$(ls -lrt /auto/Gtl-Techmate/gtlnetwork/Techmate/Data/ | tail -2 | head -1 | awk -F " " '{print $8}')
echo $SFILE


If i put the same in a script and execute through crontab,been receiving a mail with the output "06:32" rather than "Atlas_Tool_Error_Report_30_Nov.csv"

i don't have any clue why it is happening like this,is there any thing wrong with my crontab, please suggest
Old 12-01-2012, 01:42 PM   #2
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The process environment under cron will almost certainly differ from the process environment of an interactive user.
For starters, it is very common for the ls command to be aliased in shell startup scripts, so relying on the format of it's output is a recipe for failure and instability. You seem to rely on the order of sorting in it's output, and using that to extract a positional element of it's output. The existence of any file that breaks that condition will break your code (and that may be what you're seeing here). You need to find a more rigorous way of characterizing the component of interest. It looks like you are trying to detect a filename based on a date. Composing the filename using specified formatting from the date command might be a better idea. If you need to extract information about that file, then parsing the output of stat will probably give you more consistent results.
Setting environment variables in your script so that they explicitly duplicate the condition of your development shell will probably go a long way toward solving your problem.

--- rod.
Old 12-03-2012, 02:08 PM   #3
Srinivas Gadi
LQ Newbie
Registered: Dec 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled

Thank you for your advice, got a date logic to fulfill my request
Old 12-28-2012, 02:51 PM   #4
Srinivas Gadi
LQ Newbie
Registered: Dec 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled

Have a one more question.

Please refer my code
while read line
echo "$i:$line";ssh $line 'nvidia-smi |grep -i MB | cut -c40-55'
let i++
done < ~/hostnames

There are ~100 server , i want remotely loginto all servers one by one and get the nvidia details, when i execute the above scrips it just fetch the details from one server post it quite, it does not heading to second server listed in hostnames file.

Please correct where i was wrong and wt should i do to fulfill my request


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 doesn't execute self-written script Annielover Linux - Newbie 12 05-18-2012 07:24 AM
I cant get crontab to execute my rsync script.... Theatre Linux - Server 3 09-10-2011 06:19 AM
My script not giving result with 2 or more arguments baigmd Programming 2 10-27-2009 01:41 AM
crontab doesn't execute python script right msegmx Linux - Newbie 13 05-04-2009 10:29 AM
Script doesn't execute in crontab jis0501 Linux - General 2 08-04-2007 08:09 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:02 PM.

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