Hi All, I hv unix status.sh script to check my applications status. When I was trying to run the same script in different mode as #!bin/sh & #!bin/bash Am seeing the different functionality. #!bin/bash - Checking n giving output perfectly #!bin/sh - Applications are live, though it is sayin dead n restarting. Pls advice me.. Thanks a lot Cheers jowsaki
Hi Sham bash is Bourne Again Shell (the spelling is deliberate homage to Mr Bourne who wrote the original Bourne Shell: sh). Bash is supposed to be compatible with sh, but with extensions to sh to make bash easier to work with. If you use one of these extensions in bash, then the script will no longer work in sh (or may work differently, but that is rare). The simplest solution is that since your script works with bash, use bash If you really want to get it working with sh, then post the lines from the script file that are failing (including any setup code) and we can try and advise you. Regards, Andrew
Hi Andrew, This is my sample .sh file. (a) When I was trying to run this in !/bin/bash mode, it is working. (b) When I was trying to run under cron job, it is always stating that driver is dead n restarting even it is live. /opt/emg/bin/emg.sh qim status - this will return "qim is running".
#!/bin/bash statusqim="$(/opt/emg/bin/emg.sh qim status)" echo "$statusqim" if [ "$statusqim" = "qim is running" ] then echo "QIM is live" else echo "QIM is dead" /opt/emg/bin/emg.sh qim restart fi Is anything wrong in my .sh Pls advice me. Tks Jowsaki [ June 12, 2003: Message edited by: Sham Jowsaki ]
Hi Jowsaki I cannot see anything wrong with the script you have provided. You should be getting an email each time this script runs (unless you have turned that feature off). Does the email show the text "qim is running"? My suspicion would be that there might be a problem in the /opt/emg/bin/emg.sh script. Do you want to post it as well? Regards, Andrew
Hi Andrew, Thanks for your reply. I can post the script, it does not matter. The thing the same script am able to run as ./driveremg.sh manually, things are thru.. only am getting problem while runnin the same script under crontab. Any solution? I think that crontab is not accepting "qim is runnin" = "qim is running" statement. Advice me.. thanks Jowsaki
Hi Jowsaki I think that crontab is not accepting "qim is runnin" = "qim is running" statement. Cron is just a scheduler, and crontab is just the configuration file for that scheduler. Neither of them read your file. What is more likely to be a problem is how cron runs your script. From an old solaris man page for crontab:
The shell is invoked from your $HOME directory with an arg0 of sh. Users who desire to have their .profile executed must explicitly do so in the crontab file. cron supplies a default environment for every shell, defining HOME, LOGNAME, SHELL(=/bin/sh), TZ, and PATH. The default PATH for user cron jobs is /usr/bin; while root cron jobs default to /usr/sbin:/usr/bin. The default PATH can be set in /etc/default/cron; see cron(1M).
There are several things here that might indicate where the problem is:
it starts as sh, not bash: does it honour your request to swap to bash? You might be able to test around this by changing your crontab entry to "bash -c /opt/emg/bin/emg.sh" (or whatever your script is called).
it starts with a very minimal path. This is another reason for using explicit paths to executables in your scripts. This should not cause a problem with the script you posted, but might be in the other script.
it starts without your profile being loaded - if you need anything from your profile (not apparent in the script you posted) then you will have to load it manually.