-1

I am facing issue with script execution in cron. Same script working fine on terminal and cron under bash version 4.3. But cron is failing for lower bash version.

I want to save command output in file in script like

#!/bin/bash
newendcount=$(/bin/cat error_files.log | wc -l)
echo $newendcount > /tmp/var.txt

with terminal it is working fine but with cron it not storing line count value, instead giving 0 as result. But same script working properly on terminal.

cronjob is like

* * * * * /bin/bash script.sh > /tmp/output.txt

I editing this question. As I got a solution to my issue. it was because of environment variable mismatch. I have added a line " . /root/.profile " at top of script and now cron is working as expected

Sunil Bhoi
  • 189
  • 1
  • 1
  • 9
  • I tried with steps given in link. The problem here is same script and cron working on ubuntu 14 but cron failed in ubuntu 12. – Sunil Bhoi Apr 06 '18 at 13:05
  • I got solution for the issue. it was because of environment variable mismatch. I have added a line " . /root/.profile " at top of script and now cron is working as expected – Sunil Bhoi Apr 26 '18 at 14:03

1 Answers1

1

You probably need to add the full path to error_files.log as it is unlikely to be in the working directory for the cron job.

user460788
  • 41
  • 1
  • I have tried by giving full path still same issue. – Sunil Bhoi Apr 06 '18 at 13:04
  • I got solution for the issue. it was because of environment variable mismatch. I have added a line " . /root/.profile " at top of script and now cron is working as expected – Sunil Bhoi Mar 13 '19 at 06:46