Restarting service using command works fine but using the same command in shell script fails to restart
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Restarting service using command works fine but using the same command in shell script fails to restart
Script being used is shown below,
#!/bin/bash
ps auxw | grep ESDEMO | grep -v grep > /dev/null
if [ $? != 0 ]
then
casstart
echo "service was not running and has been restarted"
else
echo "service is running on $(hostname) as on $(date)"
fi
====================================================================
On executing this script to restart ESDEMO, I am getting the error - "/opt/microfocus/cobol/bin/casstart32: error while loading shared libraries: libcasmfsysv.so: cannot open shared object file: No such file or directory".
Verified PATH Environment variable.
"/opt/microfocus/cobol/bin" is set correctly.
At the same time, I am able to start the service manually in putty just by giving casstart + Enter.
But getting the above mentioned error while executing using the script.
Please help in resolving this issue at the earliest.
Normally in startup scripts it is better to provide the full path as depending on where and when the script gets executed, some items / variables may not be available.
Thanks for the response. I tried giving full path and placed the script in the /root path.
Now on executing ./xx.sh from root path, the service is getting restarted as expected.
But on using root crontab, restart is not working.
crontab -l
*/5 * * * * /root/xx.sh
xx.sh:
#!/bin/bash
export LD_LIBRARY_PATH=/opt/microfocus/cobol/lib
ps auxw | grep ESDEMO | grep -v grep > /dev/null
if [ $? != 0 ]
then
cd /opt/microfocus/cobol/bin
./casstart
echo "service was not running and has been restarted"
else
echo "service is running on $(hostname) as on $(date)"
fi
Please help on this.
The error that I am getting is:
CASMG99999E 0000,Message file missing. 12:15:01
CASMG99999E CF0038,casstart,ESDEMO,0000 12:15:01
Last edited by UserLinux123; 04-26-2016 at 06:23 AM.
Reason: Added error message.
Those would appear to be error messages from the program you are running. I would suggest going to their web site and looking for information as this is not longer an issue with linux
or the way the script is being run .. that I can tell
I would make 2 other suggestions:
1. Look up the pgrep function as it removes the need for multiple greps and the use of ps
2. Just supply the full path to run casstart instead of cd'ing into the directory - - /opt/microfocus/cobol/bin/casstart
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.