Yes, I know that - what you have to do is make sure that the scipt that is being run by the cron daemon is fully aware of your environment. At the moment it is unaware of the location of the Parameter_Test.ini file.
only the problem is it not executing the script via cron job, when I run it manually it is deleting the folders on different servers based on my .Parameter_Test.ini
The problem you have is what i call "Cron Problem Number One" and if you search this forum for this you will find lots and lots of threads similar to yours. Here is the long version of the explanation:
Every session has a certain "environment": environment variables set to some value, a current working directory, etc.. When you start a script manually you (implicitly) rely on this environment to be what it is:
When you start a script you had to log on before. The login process places you in a certain directory (your homedir), so the current working directory is preset to this. Then your ~/.profile-script is executed, which will set some environment variables. At last your (login)-shell is started and it is configured via some additional configuration file (bash uses /etc/bashrc and ~/.bashrc, KornShell uses ~/.kshrc or whatever your environment variable "ENV" points to, etc.). All these rc-files further set your environment by declaring variables, adding aliases and so on.
All this is done before you start your script and so your environment is already set to some state, which the script - being invoked out of this enviroment - inherits. In fact this is what the keyword export is for. You sure have seen something like this in a configuration file:
The "export" keyword marks a variable to be inherited from a process started out of this environment. Otherwise the content of the variable would not be known in the environment of the newly created process. You can (and should) try this out by setting a variable inside your shell and then call another shell and see if the variable is known there to understand the effect.
Back to the starting process: when your script is started from the cron-daemon instead of from some interactive session the picture changes radically: cron is a child process of init, which has only the minimum possible environment. cron inherits this minimum environment and subsequently passses it to its children - every cron-script. You have to make up for this lack of environment yourself, by setting the necessary variables within your script yourself.
Just as an example:
This says: load a file located at "." - in other words, "from my current directory". Your current directory is your HOME dir when you log on interactively, but when the script is executed from cron this is "/". This was, what gull04 was trying to tell you. If you want to use the script in cron always use absolute paths:
Hello,
I am trying to run a script through crontab and it runs the first time and then it does not run.
I tried to run a simple script (as shown below) and I see the same issue.
#!/bin/ksh
clear
echo "Good Morning, World." > /tmp/test123
Crontab Entry:
30 09 * * *... (9 Replies)
I have a script (/home/admin/run_bkup.sh) that I can run manually to kick off an executable job. I want to run it in crontab, but it doesn't work.
Here's the script:
shell=/bin/bash
today=$(date +"%m-%d-%y")
/opt/CPsuite-R77/fw1/bin/upgrade_tools/upgrade_export mgt-svr-bkup-$today << EOF
y... (18 Replies)
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)
Hello Gurus,
I have written small script which will start the given service if its stop .Its running fine when manually executed but its unable to run from crontab.
#!/bin/bash
SERVICENAME=rsyslog
service $SERVICENAME status > /dev/null
SYSLOGSTATUS=`echo $?`
COUNT=0
THRESHOLD=3
if ... (4 Replies)
Hello Team,
As a part of my job we have made a script to automate a service to restart frequently.
Script having two functions when executing it's should find the existing service and kill it, then start the same service . Verified the script it's working fine when executing... (18 Replies)
Hello Guys,
I have scratched my head alot on this but couldn't find clue what's wrong. Can you please help me with this? My problem is as following.
1) When I manually execute following script it runs successfully with below output.
bash-3.00# more smssend
#!/bin/bash
echo -e "<Request... (16 Replies)
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)
hello,
i recently switched to a new ec2 box and transferred the cronjobs from the old box. For some reason one of the scripts won't work but it runs manually from the command line. I've read from previous threads it might be an environment issue but I added a line with the path to the script... (2 Replies)
Hello all,
I'm new here and have a question if you don't mind helping me. I have a script that will work if I kick if off manually but not from Cron. My cron entry is this:
05,20,35,50 * * * * /scripts/status.sh > /dev/null 2>&1
The first script (works fine) is this:
#!/bin/sh
#
#... (14 Replies)
Hi all
I have this inside a shell script (bash):
cd DIRECTORY
find . -maxdepth 1 | sed 's#./##' | /usr/bin/xargs -I '{}' chown -Rv '{}' /DIRECTORY/'{}'
All the directories in this location are named after usernames, so it simply sets the owner to that of the username of the folder.
It... (5 Replies)