Different output when run from crontab


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Different output when run from crontab
# 8  
Old 05-13-2011
So I have found the issue but have no idea how to fix it!

When running from the crontab the output of any command is chopped to a certain length, so the grep on the PS command can not find what it is looking for as the 'uniqueness' of the string is past the chop off point.

I guess this is something to do with the terminal env for the cron.

Does anyone know how I can change that?

Code:
EXAMPLE FROM CRON...

5231 root      345m S    /var/packages/sab2/target/utils/bin/python /volume1/

EXAMPLE FROM COMMAND LINE PS

5231 root      187m S    /var/packages/sab2/target/utils/bin/python /volume1/@appstore/sickbeard/SickBeard.py --quiet


Last edited by simpic; 05-13-2011 at 09:49 AM..
# 9  
Old 05-13-2011
you can try executing the .profile of the corresponding user before the script in the cron entry and try.

Code:
0 19 * * 2 /home/myuser/.profile; /home/myuser/bin/garbage-day-email.sh

# 10  
Old 05-13-2011
Time to look at "man ps" on your computer. There's too much variety in the syntax for "ps" to guess accurately but "ps -w" (wide) is one guess.
# 11  
Old 05-13-2011
Quote:
Originally Posted by methyl
Time to look at "man ps" on your computer. There's too much variety in the syntax for "ps" to guess accurately but "ps -w" (wide) is one guess.
Hi,

I'm afraid as this is running Busy Box it does not have man. And I'm pretty confident it is nothing to do with the actual ps command. It will use the -w command as default. No difference if I include that in the script as an argument.

The issue is around cron not running in an env set terminal.

I tried the
Code:
0 19 * * 2 /home/myuser/.profile; /home/myuser/bin/garbage-day-email.sh

in the crontab with no joy.

It still cuts the output off at 78 characters.

Maybe Busy Box will just not allow it and I'll have to come up with a more intuitive way of checking the process Smilie
# 12  
Old 05-13-2011
Try using -ww ... some versions of the ps command define this as:

-w Wide output. Use this option twice for unlimited width.


The 78 character width is sneakily suspicious to standard tty width.
Why are you so confident it is not the ps command?
My hypothesis of the problem would be the ps command cannot identify the output terminal and so it is defaulting to the default tty settings.

In your script, try experimenting also with the 'tty' command. This will either correct your problem or give you better insight.

Last edited by frankkoenen; 05-13-2011 at 01:11 PM.. Reason: typeo
# 13  
Old 05-13-2011
Try this way. Make a startup script that will start the actual process and stores the PID in a text file.

Later in the cron script you may check for the PID which stored in the text file.

But the problem with this is, when the program crashes and the PID stored in the text file will be reused. And we may end up saying yes for the wrong process.

So check for the possibilities of process crash.

PID text file must be removed when the process stops.
# 14  
Old 05-13-2011
Quote:
Originally Posted by frankkoenen
Try using -ww ... some versions of the ps command define this as:

-w Wide output. Use this option twice for unlimited width.


The 78 character width is sneakily suspicious to standard tty width.
Why are you so confident it is not the ps command?
My hypothesis of the problem would be the ps command cannot identify the output terminal and so it is defaulting to the default tty settings.

In your script, try experimenting also with the 'tty' command. This will either correct your problem or give you better insight.
Thanks for the suggestions, I'll have a play around this weekend.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can't get my crontab to run

I'm trying to get a crontab to run, every Friday at 11am and the problem is that it isn't running at all. 0 11 * * 6 /Users/martinb/Documents/SYSADMIN/Regular-Scripts/Info-And-Backups.sh Here's a link to a screenshot of my script (I've censored my email address). Screen Shot 2017 11 03... (3 Replies)
Discussion started by: $shell_Learner
3 Replies

2. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

3. Shell Programming and Scripting

How to give full access to output files created by .sh script run via crontab?

Hi Expert, I have a .sh script in my home/new_dir/script.sh This script creates number of output files at home/new_dir/email, home/new_dir/logs dir. I am running this script using crontab (owner root). Now this output files are getting created with rw-r----- 1 root root So if i... (2 Replies)
Discussion started by: Jeet1982
2 Replies

4. Shell Programming and Scripting

Why my git command has no output in crontab but works well run this script manually?

cat /home/lyang001/update.sh #!/bin/sh #shopt -s expand_aliases HOME_DIR=/home/lyang001/updates UPDATE_MAIL=${HOME_DIR}/updates.mail rm $UPDATE_MAIL -rf cd $HOME_DIR/wr-kernel git log --no-merges --since="20 day ago" --name-status --pretty=format:"%an %h %s %cd" origin/WRLINUX_5_0_1_HEAD >>... (2 Replies)
Discussion started by: yanglei_fage
2 Replies

5. Shell Programming and Scripting

Who -u gives different output if run from cron than if run from terminal?

If I run 'who -u' interactively or from a script invoked through bash in a tty on my Ubuntu 12LTS box I get an output like this: testuser pts/0 Dec 9 02:32 . 2163 (host.xx.yy) running the same through cron I get: testuser pts/0 2012-12-09 02:32 00:05 2163... (2 Replies)
Discussion started by: latimer
2 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. HP-UX

Crontab do not run on PM hours

Hi All I have a problem, I wonder if you can help me sort it out: I have the following entry in the cron: 00 1,13 * * * /home/report/opn_amt_gestores_credito.ksh > opn_amt_gestores_credito.log But the entry only runs at 01:07 I have stopped the cron deamon, and started, but it still... (39 Replies)
Discussion started by: fretagi
39 Replies

8. Solaris

crontab to run every 20 second

Hi experts, I want to set the crontab for my script which will run every 20 seconds I think below could be the possible one- */3 * * * * /export/home/username/scripts/runing.sh As my system(SOLARIS 9) is live- i am confused to implement before make sure !!! I need... (4 Replies)
Discussion started by: thepurple
4 Replies

9. HP-UX

Run crontab every 6 days

Hi all, I need to run a shell script every 6 days using crontab. I've been searching a bit and found the following syntax for this: * * */6 * * /apps/temp/maxx.sh > /apps/temp/maxx.log 2>&1 respectively * * 0/6 * * /apps/temp/maxx.sh > /apps/temp/maxx.log 2>& Unfortunately when trying to... (8 Replies)
Discussion started by: Endo
8 Replies

10. Shell Programming and Scripting

output from crontab run

Hi, I am trying to schedule a job in linux through the crontab command.My script actually does some text processing and echoes some output.My cron scheduler is working fine,but the output messages(echoes from script) is mailed to my mail account(in unix -/var/local/mail).Is it not possible... (0 Replies)
Discussion started by: DILEEP410
0 Replies
Login or Register to Ask a Question