0

The script below enters the if loop only if the size of the array is zero .. When the script is executed manually , the script gives the correct output.. But when I run the same script using cronjob. By default it is executing the else loop.

printf "%s\n" "${var[@]}"
if [ ${#var[@]} == 0 ];then
   echo "empty"
   #mailx -s "ALL RUNNING" e.nolan.mit@mobily.com.sa < /apps/lp/Start_Services/running.txt
else
   echo "else part"
   printf "%s\n" "${var[@]}" > filename.txt
   mailx -r scm.admin@mobily.com.sa  -s "RHINE1  10.14.11.77 LOYALTY SERVER" e.nolan.mit@mobily.com.sa < /apps/lp/Start_Services/scm/filename.txt
   echo "I am here"
fi 
1

When you execute a cron job, usually is a best practice to specify the full path for files. Most likely the problem is here:

printf "%s\n" "${var[@]}" > filename.txt

If you try redirecting the output to /apps/lp/Start_Services/scm/filename.txt, it's likely that you'll get the proper output.

  • printf "%s\n" "${var[@]}" if [ ${#var[@]} == 0 ];then echo "empty" echo "I am in if loop date " > ifloop.txt mailx -r scm.admin@mobily.com.sa -s "ALL RUNNING" e.nolan.mit@mobily.com.sa < /apps/lp/Start_Services/running.txt else echo "else part" echo "I AM IN Else loop date " > elsepart.txt printf "%s\n" "${var[@]}" > /apps/lp/Start_Services/scm/filenameC.txt mailx -r scm.admin@mobily.com.sa -s "RHINE1 10.14.11.77 LOYALTY SERVER" e.nolan.mit@mobily.com.sa < /apps/lp/Start_Services/scm/filenameC.txt echo "I am here" fi – Emelyn DSilva Dec 13 '16 at 13:03
  • I have changed according to the above comment but still the cronjob is taking the last 3 values of the array and entering the else loop... – Emelyn DSilva Dec 13 '16 at 13:05
  • we have assigned values to the array only if it enters the if loop for ex – Emelyn DSilva Dec 13 '16 at 13:07
  • ps -ef|grep LPMREDSUP |grep -v grep if [ $? -ne 0 ] then var[32]="process LPMREDSUP not running" fi echo "*************************************" echo "" ps -ef|grep LPAPDELPT | grep -v grep if [ $? -ne 0 ] then var[33]="process LPAPDELPT not running " – Emelyn DSilva Dec 13 '16 at 13:07
  • if the service is running then the value of the array is empty... – Emelyn DSilva Dec 13 '16 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.