crontab runs only one line in iterated program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting crontab runs only one line in iterated program
# 1  
Old 05-01-2011
Error crontab runs only one line in iterated program

I have a crontab as below:

Code:
PATH=/usr/local/sbin:/bin/:..... etc etc
0 8 * * * /home/user/jobs/poll.sh 2>/dev/null 1>/dev/null

Now the script poll.sh is called at correct time and executes.
This is how poll.sh looks like

Code:
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games .... BIG path 

# Just load required envn variables
. ~user/.envvariables

# Now execute a perl program and email me the output ... 
VAL=$(~users/jobs/fetchNprocess.pl 2>/dev/null) 
echo $VAL | mail -s "Processed data for today: `date`" dummy@newsasnow.com 2>/dev/null 1>/dev/null

#### Here are some method already tried

#### Just do everything in one line
# ~users/jobs/fetchNprocess.pl 2>/dev/null | mail -s "Processed data for today: `date`" dummy@newsasnow.com 2>/dev/null 1>/dev/null

### Process and send as body 
# mail -s "Processed data for today: `date`" dummy@newsasnow.com < `echo $VAL` 2>/dev/null 1>/dev/null

the output of the perl program (fetchNprocess.pl) is as below(when I run manually not cron):
Code:
Processing DATA for 1: 123324534 213w1312  asdasd  [DONE]

Processing DATA for 2: 123324534 213w1312  asdasd  [DONE]

Processing DATA for 3: 123324534 213w1312  asdasd  [DONE]

Processing DATA for 4: 123324534 213w1312  asdasd  [DONE]

Processing DATA for 5: 123324534 213w1312  asdasd  [DONE]

5

The output contains many lines also empty lines The output I get after cron runs in only first line in my email.
Code:
Processing DATA for 1: 123324534 213w1312  asdasd  [DONE]

It does not process all the lines ...

When I run the same program manually it works fine.
As far as crontab goes I took care of path and right env variables.


Any suggestion what could have cause the perl program to do only one iteration.

Other details of the server
Code:
Ubuntu 9.10
Linux 2.6.37-server #1 SMP i686 GNU/Linux
perl, v5.10.0 built for i486-linux-gnu-thread-multi
GNU bash, version 4.0.33(1)-release (i486-pc-linux-gnu)

# 2  
Old 05-01-2011
Give a try replacing :

Code:
VAL=$(~users/jobs/fetchNprocess.pl 2>/dev/null)  echo $VAL | mail -s "Processed data for today: `date`" dummy@newsasnow.com

with
Code:
>/tmp/fetchNprocess.tmp ~users/jobs/fetchNprocess.pl >>/tmp/fetchNprocess.tmp 2>/dev/null && cat /tmp/fetchNprocess.tmp | mail -s "Processed data for today: `date`" dummy@newsasnow.com/
rm /tmp/fetchNprocess.tmp

# 3  
Old 05-01-2011
Thanks for your reply . Yes that is one way

I am looking for a way to have without any temp file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Where can I find the program that runs the -wc command?

Hey guys, I was wondering. When I enter a command in the terminal -wcl for a word count, where is that program located in the kernel? (7 Replies)
Discussion started by: Circuits
7 Replies

2. UNIX for Advanced & Expert Users

Script only runs first time through crontab

Hello, I am trying to run a script through crontab and it runs the first time and then it does not run. I tried to run a simple script (as shown below) and I see the same issue. #!/bin/ksh clear echo "Good Morning, World." > /tmp/test123 Crontab Entry: 30 09 * * *... (9 Replies)
Discussion started by: hasn318
9 Replies

3. Shell Programming and Scripting

Job runs manually, doesn't work in crontab

I have a script (/home/admin/run_bkup.sh) that I can run manually to kick off an executable job. I want to run it in crontab, but it doesn't work. Here's the script: shell=/bin/bash today=$(date +"%m-%d-%y") /opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export mgt-svr-bkup-$today << EOF y... (18 Replies)
Discussion started by: df08388
18 Replies

4. UNIX for Dummies Questions & Answers

Script runs manually but not from crontab in UNIX

Hi Guys, I am executing the script called Delet.sh manually it is successfully completing the task but it is failing to run vi cron tab, I tried to pass PATH & .profile before execution but no luck, Any suggestions? Script below #!/usr/bin/ksh #set -x # Purpose : Delete folders file from... (9 Replies)
Discussion started by: Anilsa77
9 Replies

5. Shell Programming and Scripting

Script runs good manually but failing via crontab

Hello Gurus, I have written small script which will start the given service if its stop .Its running fine when manually executed but its unable to run from crontab. #!/bin/bash SERVICENAME=rsyslog service $SERVICENAME status > /dev/null SYSLOGSTATUS=`echo $?` COUNT=0 THRESHOLD=3 if ... (4 Replies)
Discussion started by: kapil514
4 Replies

6. Shell Programming and Scripting

Script runs fine manually but not in crontab

Hello Guys, I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following. 1) When I manually execute following script it runs successfully with below output. bash-3.00# more smssend #!/bin/bash echo -e "<Request... (16 Replies)
Discussion started by: umarsatti
16 Replies

7. Shell Programming and Scripting

Script runs manually but not correctly from crontab

Hello all, I'm new here and have a question if you don't mind helping me. I have a script that will work if I kick if off manually but not from Cron. My cron entry is this: 05,20,35,50 * * * * /scripts/status.sh > /dev/null 2>&1 The first script (works fine) is this: #!/bin/sh # #... (14 Replies)
Discussion started by: hs3082
14 Replies

8. Shell Programming and Scripting

Script runs manually but not correctly from crontab

Hi all I have this inside a shell script (bash): cd DIRECTORY find . -maxdepth 1 | sed 's#./##' | /usr/bin/xargs -I '{}' chown -Rv '{}' /DIRECTORY/'{}' All the directories in this location are named after usernames, so it simply sets the owner to that of the username of the folder. It... (5 Replies)
Discussion started by: fakesy
5 Replies

9. UNIX for Advanced & Expert Users

Minutes a program runs.

I have a ksh script that executes a program with a predetermined timeout in minutes. If the program takes longer then the timeout then it still completes with a return code of 0. :confused: I would like to determine how long the program ran. Then if it takes longer than the timeout I would... (7 Replies)
Discussion started by: 2dumb
7 Replies

10. Shell Programming and Scripting

Check if a program runs on unix

Hi guys, I had a question last week where I asked how I check from a website hosted on windows if a process is running on on of our unix servers. Vino and Shell Life kindly replied with a perl script: if qm') -gt 0 ] ; then echo "Site is up" else echo "Site is down." # start the... (1 Reply)
Discussion started by: drchris
1 Replies
Login or Register to Ask a Question