Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I write a script that basically just runs pkill -HUP inetd? I want to restart inetd via a script so I can schedule it to run at a particular time. I tried to write it myself, but I'm getting a "Hangup" error.

share|improve this question
    
Could you show us a example of what you've tried? Maybe someone could show you what you did wrong, just asking us to script for you sounds lazy. You may learn something useful for the future. –  llua Apr 5 '12 at 3:31
    
What exactly did you do (are you running the script from a shell? from a crontab?), and what was the exact error message you got? I can't think of an use case where you would need a script instead of just running pkill directly –  Michael Mrozek Apr 5 '12 at 4:32
    
I tried following mini script but it doesn't seems to work. #!/usr/local/bin/bash PKILL="/usr/bin/pkill -HUP inetd" MAIL="/usr/bin/mail" USER="ian@mail-server.com" sudo $PKILL $MAIL -s "inetd restarted on mail-server" $USER < /dev/null exit 0 –  Ian Apr 5 '12 at 4:36
    
What is your operating system? –  Nils Apr 5 '12 at 19:45
1  
@Ian Edit your question. Copy-paste your script, the way you run it, and the error message you get. –  Gilles Apr 5 '12 at 23:18
add comment

1 Answer 1

#!/usr/local/bin/bash
PID=`pidof inetd`
MAIL="/usr/bin/mail"
USER="ian@mail-server.com"
sudo kill -s HUP $PID
$MAIL -s "inetd restarted on mail-server" $USER < /dev/null
exit 0

If pidof is available.

share|improve this answer
    
Thanks llua, it works with no issues. Just out of curiosity can you tell why we can't use pkill instead kill? Thanks once again. Ian –  Ian Apr 5 '12 at 7:02
    
Do you mind pasting the full output of the error? or was the full error returned to you was "Hangup". –  llua Apr 5 '12 at 20:06
    
Sorry I was away for few days. Yes, "Hangup" was the total message. I am running the script on Solaris 5.7 by the way. Thanks for your assistance. –  Ian Apr 11 '12 at 4:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.