LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 11-23-2013, 12:54 AM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
problem with shell script


Hi,

I have prepared a shell script where i need to pull the data from a pipe seperated file and display it to the dashboard. when i run the shell script from my folder it runs and shows all the graphs on dashboard..however, when new data file comes in and the script runs from cron scheduler, it doesn't pull that data and we can't see the pie chart and graphs on dashboard. but when i run the same script from my folder where it is prepared, it shows all details on dashboard.. what could be the reason and how to sort it?

need your help..
Thanks in advance.
Santosh
 
Old 11-23-2013, 05:40 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
There can be many reason why it does not run correctly when started from cron.

These are probably most common:
- Unlike the shell cron has a very minimal user environment. Basically only HOME, (a limited) PATH and USER are available.
- The line used in crontab might not be correct.

Without seeing the script and the way this script is run from cron we cannot help you any further.
 
Old 11-23-2013, 11:33 PM   #3
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Smile Problem with shell script

Hi,
Thanks for your quick reply, i'll post my script and the path mentioned in the cron here, by tomorrow as today i am on vacation.

Need your help to sort this issue,thanks a lot in advance :-)
 
Old 11-25-2013, 12:24 AM   #4
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
problem with shell script

Hi,
now for its alternate run it is displaying dashboard graphs. however if i run this from my folder it runs always. need your help.

The line used in crontab is:
15 * * * * /home/www/BCARD/scripts/ssa/BIR_Kenya_Login_Mon.sh > /home/www/BCARD/scripts/ssa/BIR_Kenya_Login_Mon.log 2>&1

and here is the script:
#!/bin/ksh

#Script for Login Monitoring Kenya Success Failure Pie chart

cd /home/www/BCARD/data/ssa


echo "<chart caption='' animation='1' baseFontSize ='11' isbold='1' showValues='1' showNames='1' showPercentageValues='0' decimalPrecision='0' pieRadius='120' bgColor='999999,FFFFFF' bgAlpha='50' showlabels='1' startingAngle='85' slicingDistance='10' chartTopMargin='0' chartbottomMargin='0' enablesmartlabels='1' manageLabelOverflow='0' formatNumberScale='0' showZeroPies='0' showlegend='0' clickURL='N-http://cemv.barclaycard.co.uk/BCARD/custom/CEMV/LMKENYA/Index.html'>">kenya.sf.today.pie.xml

color[2]='7F38EC'
color[3]='810541'

lbl[2]='SUCCESS'
lbl[3]='FAILURE'

## Remove any carriage return characters and save the file as LM_Succ_Fail_Tdy.TMP.txt and use the same instead of original file

tr -d '\r' < /home/www/BCARD/data/lmkenya/LM_Succ_Fail_Tdy.txt > /home/www/BCARD/data/lmkenya/LM_Succ_Fail_Tdy.TMP.txt

for line in $(cat /home/www/BCARD/data/lmkenya/LM_Succ_Fail_Tdy.TMP.txt)
do
for i in $(seq 2 1 3)
do
val=$(echo $line|cut -d '|' -f$i)
echo "<set label='${lbl[$i]}' value='$val' isSliced='1' color='${color[$i]}'/>" >>kenya.sf.today.pie.xml
done
done

echo "<styles>" >>kenya.sf.today.pie.xml
echo " <definition>" >>kenya.sf.today.pie.xml
echo " <style name='myCaptionFont' type='font' size='14' bold='1' underline='1' />" >>kenya.sf.today.pie.xml
echo " <style name='MyLabel' type='font' size='10' color='000000' bold='1' />" >>kenya.sf.today.pie.xml
echo " <style name='myFont' type='font' size='10' bold='1' underline='0' />" >>kenya.sf.today.pie.xml
echo " <style name='myBevel' type='Bevel'/>" >>kenya.sf.today.pie.xml
echo " </definition>" >>kenya.sf.today.pie.xml
echo " <application>" >>kenya.sf.today.pie.xml
echo " <apply toObject='Caption' styles='myCaptionFont' />" >>kenya.sf.today.pie.xml
echo " <apply toObject='DATALABELS' styles='MyLabel' />" >>kenya.sf.today.pie.xml
echo " <apply toObject='Background' styles='myBevel' />" >>kenya.sf.today.pie.xml
echo " <apply toObject='legend' styles='myFont' />" >>kenya.sf.today.pie.xml
echo " </application>" >>kenya.sf.today.pie.xml
echo "</styles>" >>kenya.sf.today.pie.xml
echo "</chart>" >>kenya.sf.today.pie.xml


#Script for RAG Status of Login Monitoring Kenya Success Failure Pie Title Chart


echo "<chart manageResize='1' bgAlpha='50' pallette='1' bgColor='999999,FFFFFF' bgAlpha='45' bgRatio='50,45' bgAngle='90'>" >kenya.sf.today.title.dp.xml
echo "<annotations>" >>kenya.sf.today.title.dp.xml
echo " <annotationGroup id='Grp1'>" >>kenya.sf.today.title.dp.xml
echo " <annotation type='rectangle' x='1' y='1' toX='467' toY='30' radius='5' color='EEF5FA,4DAFE4' fillAngle='90' fillRatio='10,80,10'/>" >>kenya.sf.today.title.dp.xml
echo " </annotationGroup>" >>kenya.sf.today.title.dp.xml
echo " <annotationGroup id='Grp2'>" >>kenya.sf.today.title.dp.xml
echo " <annotation type='text' x='200' y='15' fontSize='18' bold='1' label='KENYA' color='000000'/>" >>kenya.sf.today.title.dp.xml
echo " </annotationGroup>" >>kenya.sf.today.title.dp.xml
echo " <annotationGroup id='Grp3'>" >>kenya.sf.today.title.dp.xml



for line in $(cat /home/www/BCARD/data/lmkenya/LM_Succ_Fail_Tdy.TMP.txt)
do

vals=$(echo $line|cut -d '|' -f2)
valf=$(echo $line|cut -d '|' -f3)
tot=$(($vals + $valf))

failper=$(awk -v tot=$tot -v failures=$valf '
BEGIN {
printf "%.0f\n", failures / tot * 100
exit
}')

# echo "$failper"

if [[ $failper -ge 20 ]]
then
echo " <annotation type='circle' color='FF0000' x='320' y='14' radius='14' />" >>kenya.sf.today.title.dp.xml
else
echo " <annotation type='circle' color='8BBA00' x='320' y='14' radius='14' />" >>kenya.sf.today.title.dp.xml
fi
echo " </annotationGroup>" >>kenya.sf.today.title.dp.xml

done

echo "</annotations>" >>kenya.sf.today.title.dp.xml
echo "<styles>" >>kenya.sf.today.title.dp.xml
echo " <definition>" >>kenya.sf.today.title.dp.xml
echo " <style name='Anim1' type='animation' param='_x' start='-50' wait='0' duration='4' easing='regular'/>" >>kenya.sf.today.title.dp.xml
echo " <style name='Anim2' type='animation' param='_y' start='-30' wait='1' duration='4' easing='regular'/>" >>kenya.sf.today.title.dp.xml
echo " <style name='Anim3' type='animation' param='_xScale' start='0' end='100' wait='1' duration='4'/>" >>kenya.sf.today.title.dp.xml
echo " <style name='Anim4' type='animation' param='_alpha' start='0' wait='1' duration='4'/>" >>kenya.sf.today.title.dp.xml
echo " <style name='Anim5' type='animation' param='_y' start='-50' wait='1' duration='4'/>" >>kenya.sf.today.title.dp.xml
echo " <style name='myCaptionFont' type='font' size='16' bold='1' underline='0' color='0000FF'/>" >>kenya.sf.today.title.dp.xml
echo " <style name='myBevel' type='Bevel'/>" >>kenya.sf.today.title.dp.xml
echo " </definition>" >>kenya.sf.today.title.dp.xml
echo " <application>" >>kenya.sf.today.title.dp.xml
echo " <apply toObject='Caption' styles='myCaptionFont' />" >>kenya.sf.today.title.dp.xml
echo " <apply toObject='Background' styles='myBevel' />" >>kenya.sf.today.title.dp.xml
echo " <apply toObject='label' styles='myCaptionFont' />" >>kenya.sf.today.title.dp.xml
echo " </application>" >>kenya.sf.today.title.dp.xml
echo "</styles>" >>kenya.sf.today.title.dp.xml
echo "</chart>" >>kenya.sf.today.title.dp.xml

chmod ugo+rwx *xml
chmod ugo+rwx /home/www/BCARD/data/lmkenya/LM_Succ_Fail_Tdy.TMP.txt


cd /home/www/BCARD/data/ssa/
#To Populate Today's date and Time
cd /home/www/BCARD/custom/CEMV/SSA/
last_date=$(date)
echo '<?xml version="1.0"?>'>LastUpdatedDate.xml
echo "<root>">>LastUpdatedDate.xml
echo "<date>">>LastUpdatedDate.xml
echo "<LastUpdatedDt>$last_date</LastUpdatedDt>">>LastUpdatedDate.xml
echo "</date>">>LastUpdatedDate.xml
echo "</root>">>LastUpdatedDate.xml
###############################################################################################
 
Old 11-25-2013, 04:36 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
I don't see anything that might be a problem (CLI or cron related).

Have you checked the difference between a CLI run and a run from cron (check created output files and cron related logs)? And does the user that runs the cron job have access to the directories/files in question?
 
Old 11-26-2013, 01:47 AM   #6
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
problem with shell script

Hi,

Still for few runs it shows data and for few it doesn't, when it runs successfully in the logs it shows value for "SUCCESS and FAILURE"
because i echoed them in the script, and when it doesn't show data on pie chart then there is no no value in log file, it means in the script sometimes it is reading the data file and sometimes it doesn't.

also regarding the cron, i asked the person who has set up these scripts, however he is telling that he has used the same userid that i am using. is there any way to check, which ID has set up the cron for above scripts? so that we can also know that these scripts are also scheduled by the same userid?
 
Old 11-26-2013, 03:16 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by santosh0782 View Post
Still for few runs it shows data and for few it doesn't, when it runs successfully in the logs it shows value for "SUCCESS and FAILURE" because i echoed them in the script, and when it doesn't show data on pie chart then there is no no value in log file, it means in the script sometimes it is reading the data file and sometimes it doesn't.
If that is the case then I tend to say that the script (with or without cron) isn't the problem, but the input file is. It might not be there or it might be different somehow.

Quote:
also regarding the cron, i asked the person who has set up these scripts, however he is telling that he has used the same userid that i am using. is there any way to check, which ID has set up the cron for above scripts? so that we can also know that these scripts are also scheduled by the same userid?
For the user that is logged in you can execute crontab -l. All the user crontabs are located in (depends a bit on the distro used): /var/spool/cron/crontabs (Do not edit these files by hand!!).
 
2 members found this post helpful.
Old 11-26-2013, 11:35 PM   #8
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Smile Issue Resolved

Hi,

As advised by you, there was issue with input file,now i am using the original file name instead of redirecting it to the another file and reading it from there and it is working fine. Thanks a lot for all your help. During our discussion i learnt many things from you. Thanks a lot once again.

Thanks & Regards,
Santosh
 
  


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
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 10:12 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 08:58 PM
Shell script problem canishk Programming 9 08-27-2009 03:20 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM


All times are GMT -5. The time now is 06:47 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration