Need to Restart Service with Password

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to Restart Service with Password
# 1  
Old 06-14-2011
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> ./ ;./

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.


Last edited by pludi; 06-15-2011 at 04:22 AM..
# 2  
Old 06-15-2011
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?

# 3  
Old 06-15-2011
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/ Permission denied
/etc/init.d/functions: line 141: /var/run/ Permission denied

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


Last edited by pludi; 06-15-2011 at 02:15 PM..
# 4  
Old 06-15-2011
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.

# 5  
Old 06-15-2011
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
echo "$component is Running"
echo "$component is NOT Running or NOT a Valid Component"

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Apache service not coming up after restart

When I update the server with new SSL certificates, and restart httpd, I get errors : # service httpd restart Stopping httpd: rm: cannot remove `/usr/local/apache2/bin/httpd/logs/': Not a directory Starting httpd: ... (0 Replies)
Discussion started by: anaigini45
0 Replies

2. Red Hat

Restart service xinit.d or init.d ?

Hello How do I restart init.d ?? (centos 6.5) Thanks (2 Replies)
Discussion started by: mnnn
2 Replies

3. Red Hat

Service restart and check if running

Hello, I'l like to create a script that restart a service (/etc/init.d/httpd restart) and also check if after restart the service is actually running. Sometimes it happen that at the first try the service fails to restart. Thanks (2 Replies)
Discussion started by: bazzola
2 Replies

4. Shell Programming and Scripting

How to restart a service without root access.?

hi , can anyone please tell me to how to restart a service without root or i need a root access for it. as a user i am getting this type of error : nkchand@(tendcer0h1) nkchand $ service /opt/Nimsoft/bin/niminit stop ksh: service: not found. (1 Reply)
Discussion started by: nkchand
1 Replies

5. SuSE

Service restart daily

Hi, Beside using crontab, what is other application we can set it? Normally I check using command crontab -l. Any other path I need to check? Please guide me. Thanks. (2 Replies)
Discussion started by: mzainal
2 Replies

6. Shell Programming and Scripting

Restart IDSM service in WASSERVER

Hello, Currently i am handling admin activity of wasserver, its parts of teamcenter, wasserver is used to maintain IDSM service which is involved in data transfer activity. due to some reason IDSM service gets down and have to restart this service manually. ... (0 Replies)
Discussion started by: chetan0412
0 Replies

7. HP-UX

Script to auto restart a service

Hi All, May i please know if it is possible to write a script to check the log messages and automatically restart a service if it is failed or it is stopped. Appreciate your suggestions. Thanks in advance. regards, Eajaz (2 Replies)
Discussion started by: ajazshariff
2 Replies

8. Solaris

NFS client service restart

Can any one please tell me the command for NFS client service restart.This is to resolve, NFS mount slowness issue.Mount is very slow for both read and write operations.The below commands are not helping out in this situation. ---------- Post updated at 08:59 AM ---------- Previous update was... (1 Reply)
Discussion started by: ksvaisakh
1 Replies

9. Shell Programming and Scripting

Restart a Service!!

Hello, I am trying to write a script which will monitor few processes(winbind) for cpu utilization, If the process consumes more than say 99% cpu for 3 minutes, I want to run a script to restart the service which forks the process. ---------- Post updated at 11:21 AM ---------- Previous update... (5 Replies)
Discussion started by: linuxaddict7
5 Replies

10. UNIX for Dummies Questions & Answers

Service Restart Netbackup

For vertitas netbackup 6.0 I have media server :Solaris Client server: Windows I want to restart the netbackup service on the media server . plz suggest ASAP. (1 Reply)
Discussion started by: saurabh84g
1 Replies
Login or Register to Ask a Question