Need to Restart Service with Password

Hi All,

Requirement : I need to check for some services in my environment and restart the service if its not running.

I have written script to check the script if its running or not. While if its not running i need to restart it using ./start command. But it will ask for password prompt and i need to enter if that action to complete.

It looks like this

/x/web/STAGE2SC5895/amqriskmerchantvettingd> ./shutdown.sh ;./start.sh

Shutting down amqriskmerchantvettingd. [Tue Jun 14 16:18:47 PDT 2011]

PATH is /sbin:/usr/sbin:/x/opt/pp/bin:/usr/local/bin:/usr/X11R6/bin:/usr/bin:/bin
LD_LIBRARY_PATH is /x/opt/pp/lib:/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib
Starting amqriskmerchantvettingd log. [Tue Jun 14 16:18:56 PDT 2011]
Starting up amqriskmerchantvettingd. [Tue Jun 14 16:18:57 PDT 2011]
No authorization code is specified: please enter keys locally.
Recovering key, 1 share required.
Please enter a share password:
Incomplete key found. Brute-forcing the remainder of the key bits...
........
Successfully retrieved key from local passwords.

Can any one help me for writting script for same.

Thanks,
Pradeep

Hi,
Is it necessary to write a script because commands like following will easily give you the desired output

 service --status-all | grep service name 

.

Also do you want a script which automatically supplies password when asked for?

Regards,
Mayur

Thanks Mayur for your response.

Actually I newbie to shell. and when i tried your code i am getting permission error.

stage2sc5895 143 /x/web/STAGE2SC5895/merchantvettingserv> service --status-all | grep merchantvettingserv
/etc/init.d/ip6tables: line 45: /etc/sysconfig/ip6tables-config: Permission denied
/etc/init.d/iptables: line 45: /etc/sysconfig/iptables-config: Permission denied
grep: /etc/openldap/slapd.conf: Permission denied
/etc/init.d/functions: line 141: /var/run/syslogd.pid: Permission denied
/etc/init.d/functions: line 141: /var/run/klogd.pid: Permission denied

If you give a sample code it will great help. even for password.

Thanks,
Pradeep

Hi,
I haven't come with the script yet but to just give you a simple solution try this

 ps aux | grep service name 

Also last command didn't work because you must running as normal user but not root so don't worry. Will let you ASAP about script.

Regards,
Mayur

Thanks Mayur,

I already written script like this to check the service

         read component
            if ps ax | grep -v grep | grep -w $component > /dev/null
            then
                    echo "$component is Running"
            else
                    echo "$component is NOT Running or NOT a Valid Component"
            fi

i need a restart script in else part to restart the service.

Thanks,
Pradeep