Sponsored Content
Top Forums Shell Programming and Scripting Different output when run from crontab Post 302521820 by simpic on Thursday 12th of May 2011 11:21:42 AM
Old 05-12-2011
Different output when run from crontab

Hi,

I have a script which checks to see if an app is running and will restart it if it is not.

For some reason when I run it from the crontab it always says it is not running.

The script is as follows: -

Code:
#!/bin/sh
#
# The following script will look for the PID of SickBeard and output the result

PROGRAM="SickBeard"
PROGRAM1="/volume1/@appstore/sickbeard/SickBeard.py"
LOG_DIR="/volume1/@appstore/"
LOG_FILE="sb_monitor.log"
APPCHK=$(ps | grep $PROGRAM1 | grep -v "grep $PROGRAM1" | wc -l)
SUPPORTSTAFF="me@me.com"

# The 'if' statement below checks to see if the process is running
# with the 'ps' command.  If the value is returned as a '0' then
# an email will be sent and the process will be safely restarted.

echo "Number of processes running =$APPCHK"

if [ $APPCHK = '0' ];

then

# Write datestamp & output to log file
echo "$(date +%c) $*" >> $LOG_DIR/$LOG_FILE
echo "$PROGRAM is not running">> $LOG_DIR/$LOG_FILE

# Send an email to advise SickBeard was down
echo "$PROGRAM is not running" | /opt/bin/nail -s "$LOG_FILE" -a $LOG_DIR/$LOG_FILE $SUPPORTSTAFF

# Start SickBeard
echo "$(date +%c) $*"
echo "Starting $PROGRAM"
/var/packages/sab2/target/utils/bin/python /volume1/@appstore/sickbeard/SickBeard.py --quiet &

else

# When Sickbeard is running write to log file to say all is fine
echo "$(date +%c) $*" >> $LOG_DIR/$LOG_FILE
echo "$PROGRAM is running">> $LOG_FILE
echo "No action taken...">> $LOG_FILE
echo "$PROGRAM is running"
echo "No action taken..."

fi

exit

The crontab entry is: -

Code:
#minute        hour        mday        month        wday        who        command
0        0        *        *        *        root        /usr/sbin/ntpdate -b pool.ntp.org
*/1        *        *        *        *        root        /volume1/@appstore/sickbeard_Monitor.sh >> /volume1/@appstore/log.txt 2>&1


The logic will always return APPCHK=0 when run from the crontab.

Any ideas?
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.10 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 05:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy