Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am new in writing shell script i write a script like this

#!/bin/bash
PID=$(ps -ef | grep "sh gps.sh" | grep -v grep | awk '{print $2}')
if [ -z $PID ]
then
    cd /opt/etrans/cronjobs
    cnt=$(echo "select 'count '||count(*) from schema.table where c_is_processed ='N'" | psql | grep count |awk '{print $2}')
    echo "Out side of if count is $cnt" | cat >> /opt/cronlog/unprocess_data_process.log # for log writing
    if [ $cnt -ge 5000 ]
            then
            echo "Inside manual gps" | cat >> /opt/cronlog/unprocess_data_process.log # for log writing
            sh manual_gps.sh
        else
        echo "Inside gps" | cat >> /opt/cronlog/unprocess_data_process.log # for log writing
                sh gps.sh
        fi
else
 echo "gps Process is Running with PID=$PID"
fi
exit

when I run the .sh file manually it runs file and I can see all the counts in my log file but when I run it from crontab it is not printing the counts.

share|improve this question
    
How did you install the cronjob? –  i08in Jan 16 at 8:47
    
possible duplicate of Reasons why crontab does not work –  c0rp Jan 16 at 8:51
add comment

1 Answer 1

up vote 0 down vote accepted

I suppose the reason is your cron environment. Maybe it does not know where the psql command is. Try adding another script to your cron, with this command:

which psql >> some_temp_file

Also read this wiki question

share|improve this answer
    
Hi friends i have solved it by bringing the environment into my class path and source that environment its look like #!/bin/bash export PATH=$PATH:$HOME/bin export PGPORT=5432 export PGDATABASE=database_name –  smn_onrocks Jan 16 at 10:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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