Script is not working from cron while working manually

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 01-23-2012
Script is not working from cron while working manually

Hello,

I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me

1) How could I check my script when it is running from cron like whether the variable are getting populated or not?
2) The solution to connect to mks when running it from cron

Code:
MKS_Connection()
{
si connect --hostname=si.worldspan.com --port=7001 --user=LinuxAutomation --password=Linux4tw --yes
ReturnCode=$?;
if [[ "${ReturnCode}" -ne "0" ]];then
echo "Issue found during connection" | mail -s "MKS Connection issue1 from STP" rohit.singh2@travelport.com
exit 1;
else
echo "Connection to MKS Client is in progress" |mail -s "MKS Connection1 FROM STP" rohit.singh2@travelport.com
fi
}
MKS_Connection

Cron entry

Code:
*/2 * * * * /tmp/connect>/dev/null 2>&1

# 2  
Old 01-23-2012
This question is so common it's in our FAQ.

cron's environment is extremely minimal. The programs you want probably aren't in PATH anymore. Either set a proper PATH by various means -- a manual PATH=... statement, . /etc/profile to get your system defaults, and so forth -- or call programs by their absolute paths.
# 3  
Old 01-23-2012
Can u tell me how could I this

Code:
(1) DEV BU002: /projects/splash
[splashuser@vlllll] $ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/c098659/bin:/projects/splash/bin:/opt/MKS/IntegrityClient/bin:/mnt/splash/runtime/scripts:/projects/splash/bin:/opt/MKS/IntegrityClient/bin
 
Below is the location of my script (1) DEV BU002: /projects/splash/delta
[splashuser@vllll] $ ll -tr
total 32
-rwxr-xr-x 1 splashuser splash   545 Jan 19 20:47 FetchCode.config
drwxr-xr-x 2 splashuser splash  4096 Jan 20 19:36 ProjectSandbox
drwxr-xr-x 2 splashuser splash  4096 Jan 20 19:43 PN_Release
drwxr-xr-x 5 splashuser splash  4096 Jan 20 20:00 CheckoutRepo
-rwxr-xr-x 1 splashuser splash 15590 Jan 23 17:54 FetchCodesvnmks

 
(1) DEV BU002: /projects/splash/delta
[splashuser@vhldvgfbu002] $ ll -tr
total 32
-rwxr-xr-x 1 splashuser splash   545 Jan 19 20:47 FetchCode.config
drwxr-xr-x 2 splashuser splash  4096 Jan 20 19:36 ProjectSandbox
drwxr-xr-x 2 splashuser splash  4096 Jan 20 19:43 PN_Release
drwxr-xr-x 5 splashuser splash  4096 Jan 20 20:00 CheckoutRepo
-rwxr-xr-x 1 splashuser splash 15590 Jan 23 17:54 FetchCodesvnmks

# 4  
Old 01-23-2012
The location of your script is irrelevant...

What your script probably needs is this line, before you start trying to run anything in it:

Code:
PATH="/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/c098659/bin:/projects/splash/bin:/opt/MKS/IntegrityClient/bin:/mnt/splash/runtime/scripts:/projects/splash/bin:/opt/MKS/IntegrityClient/bin"

When you login as a user, you get this PATH by default, but scripts in cron get a much more minimal PATH. This can be rectified in various ways, the most obvious just by setting the PATH variable, otherwise by loading it through various means.
Login to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Similar Threads More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Automating pbrun /bin/su not working, whenever manually it is working using putty jorgejac Shell Programming and Scripting 14 12-03-2015 02:32 PM
Pattern not working in Cron script ssk250 Shell Programming and Scripting 3 12-02-2015 06:53 AM
Execution problem with Cron: Script works manually but not w/Cron. Why? okonita UNIX for Dummies Questions & Answers 3 04-15-2015 05:55 PM
Script (with sql queries) not working using cron nypreH Shell Programming and Scripting 4 10-17-2012 02:00 AM
Script working when run manually but not in crontab showing path not found raj_saini20 Shell Programming and Scripting 3 07-17-2012 06:47 AM
Script not working in cron but working fine manually jasperux Shell Programming and Scripting 2 07-05-2012 01:37 AM
Email Script not working when added to cron[solved] rakeshkumar UNIX for Dummies Questions & Answers 0 05-23-2012 10:10 AM
Getting issue while running it from cron while manually working fine anuragpgtgerman Shell Programming and Scripting 1 01-23-2012 03:06 PM
stdout redirect is working buy direct script exec but not in cron calibal Shell Programming and Scripting 5 06-28-2010 06:17 AM
Shell script not working in cron malikp Shell Programming and Scripting 4 01-22-2010 11:00 AM
Script not working when called by cron cooldude Shell Programming and Scripting 4 02-18-2009 11:20 AM
sudo command is not working inside a script when placed in cron usha rao Shell Programming and Scripting 5 02-12-2009 12:02 PM
running script in cron - with ssh commands - not working frustrated1 Shell Programming and Scripting 31 09-16-2008 11:14 AM
script not working in CRON abhijeetkul Shell Programming and Scripting 5 07-13-2006 06:48 AM
Can run script Manually, but not through Cron? MadHatter Shell Programming and Scripting 4 10-19-2005 11:08 AM
All times are GMT -4. The time now is 11:10 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.