Odd results when my script runs from cron..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Odd results when my script runs from cron..
# 8  
Old 02-26-2013
What system are you on? My top doesn't have -q switch (running linux).
What does -q switch do?

Does the script run ok when you run it from CL (no cron)?

What exactly is your cron entry?
Try to redirect stdout and stderr of the script to a file for debugging. Also specify the MAILTO and SHELL variable in cron, eg.
Code:
MAILTO=<user>@domain.com
SHELL=/bin/ksh
15/* * * * * /usr/apps/client/bin/gatherOSKPI.sh >> /home/user/gather.log 2>> /home/user/gatherErr.log

And see whether you will capture anything interesting.

Next step would be to set the verbose mode on in the script:
Code:
#!/bin/ksh
set -x
...

and/or simplify/comment out the lines to try to find the culprit.
# 9  
Old 02-26-2013
mirni

We are running this on Solaris 2.10

The cron command is:
0,15,30,45 * * * * /usr/apps/client/bin/gatherOSKPI.sh

As I had it explained by the admin that was helping me, the -q flag remove delays when top refreshes, so I am guessing it can be removed. I don't use more than a single response from top in my script. I put it there because the admin recommended it.

I'll check on if i can make use of the mailto or verbose methods without interrupting their work. as I said, they are letting me stretch "if" I can learn on my own.

Marc
# 10  
Old 02-27-2013
Are you sure your ps excerpt is correct and complete? I see process 26858 three times, but I am missing the grep command from that pipe. As the top process is hogging CPU time like mad, the -n1 switch seems not to work...
Suspicion: one of the (intermittend) processes that top shows in the first five lines has a character (combination) in it that prevents one of the commands in the pipe to finish and thus keeps the entire pipe open.
btw - that construct of 4 loooong pipes could (and should, for clarity, simplicity, maintainability) be reduced to one single top execution, piped to one single elaborate awk statement, either printing to those tmp files, or, feeding values to the desired variables immediately.
# 11  
Old 02-27-2013
Rudi,

Actually, I cut the ps results down to what I thought was relevant

As for making the awk more efficient, I'm learning as I go here and not sure how I would combine all three items into one. But I know you're right and hope to learn better as I go.

As for the issue, we've cleaned up the script a bit on our end, killed off the lingering processes and the admin I'm dealing with found some environmental issues ( He was not specific ) and restarted the cronjob for this script. So we are in "watch mode" again as he says it may have been an unrelated OS issue after all.

So thank you all for your input, but it appears that my script may have only been to blame until the admins could find out what the real issue was.. :\

Thank you all for your help!

Marc
# 12  
Old 02-27-2013
Just to set you on the right track: That repeated top | head 5 | grep CPU | awk | awk... could be reduced to a single top | awk 'NR> 5 {exit} /CPU/ { ... split (...) ...} /Memory/ { ... split(...) ...} etc.
Did you ever consider the vmstat command (if available on your system) that hands you out the desired info on a silver plate, and can run in intervals as desired?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script runs manually, but not from cron

Hi, I "borrowed" a script I found online, to start a SAP router application on a Solaris 11 (SPARC) server. The script runs fine when calling it manually, but when I schedule it to run from cron, it doesn't. I don't see any warning or failure messages anywhere, just nothing happens. ... (11 Replies)
Discussion started by: bredman
11 Replies

2. Shell Programming and Scripting

Cron to run 3rd Tuesday of every odd months

Hi, I need to schedule a script to run on the 3rd tuesday of every odd months at 9 am. min, hour would be - 0 9 month would be - 1,3,5,7,9,11 Can someone suggest how I can schedule it to 3rd tuesday? Thanks. (8 Replies)
Discussion started by: member2014
8 Replies

3. Shell Programming and Scripting

Script runs in command-line fine but times out in CRON?

Hi, I have a script that seems to run to completion when in the command-line, but when it is run using the cron, it seems to time out. They both start and run fine, but on the CRON it stops prematurely. The script hits an API every few seconds and grabs data. Does anyone have any idea on... (4 Replies)
Discussion started by: phpchick
4 Replies

4. AIX

Script runs in shell but not cron

We run some menu driven software that has the ability to batch menu paths and generate reports quickly. Normally you run a batch like: $ BATCH BATCHNAME The batch program then prompts you for the date you want the report run for. I got some help from some folks on IRC to do the following: BATCH... (2 Replies)
Discussion started by: herot
2 Replies

5. Shell Programming and Scripting

Shell Script runs good manually but not through Cron tab

Hello Every one, I have a shell script which is running fine manually, but its giving me hard time when running tru cron job. :wall:. Am using #!/usr/bin/ksh >echo $SHELL /usr/bin/ksh Cron Job is as below, it execues but dosent do what i want it to do. 47 15 * * *... (1 Reply)
Discussion started by: naren.chowdhary
1 Replies

6. Shell Programming and Scripting

CRON shell script only runs correctly on command line

Hi, I'm new to these forums, and I'm hoping that someone can solve this problem... To make things short: I have DD-wrt set up on a router. I'm trying to run a script in CRON that fetches the daily password from my database using SSH. CRON is set like so(in web interface): * * * *... (4 Replies)
Discussion started by: louieaw
4 Replies

7. Shell Programming and Scripting

Script runs fine, but not in a cron

Okay, I have the following script that runs fine from a command line as well as an executable .sh file. It just moves any file/folder with movie* in the name to a folder called _Movies. The issue I'm running into is when it's call from a cron. find /mnt/HD_a2/BT/complete -iname "movie.*" -exec... (4 Replies)
Discussion started by: sammyk
4 Replies

8. Solaris

SFTP errorcode 1 when run on cron but runs manually

I am trying to run a sript on cron to SFTP data to a company. Private and public keys are set up. When I run this manully it works fine, however it was failing when run on cron. I have narrowed down the problem - it fails at the code that says if the error code is 0 then continue . . . I... (2 Replies)
Discussion started by: Heidi.Ebbs
2 Replies

9. UNIX for Advanced & Expert Users

Old cron entry still runs, but shouldnt

Hello, I'm running OSF1 V4.0 alpha. We used to have a job running from the cron at 6am everyday. We have removed the job from the crontab file, but the job still runs at 6am everyday. The job was in the root's crontab file. I cant figure out why this job is still running after we removed it... (3 Replies)
Discussion started by: xadamz23
3 Replies

10. UNIX for Dummies Questions & Answers

What user runs cron?

I have a command that is found in /usr/ud51/bin called stopudt which safely stops idle database users (let's writes finish, etc). If I login as root and issue stopudt the process is stopped. I put a script in cron to run it and it says stopudt not found. /usr/ud51/bin is in root's PATH. ... (10 Replies)
Discussion started by: michieka
10 Replies
Login or Register to Ask a Question