Newbie Script Help
Hi as part of an assessment I have been asked to create a bash shell script but im RUBBISH at scripting!
I need to create a script that will kill processes of a given name using the commands (among others possibly) pidof, ps -ef and awk. Any help would be greatly appreciated! |
Quote:
If you want hints, read the man pages on the commands you listed, along with the kill and killall commands. There are also THOUSANDS of bash scripting tutorials you can easily find with Google...have you looked at any of them? |
Hi thanks for the reply, so far I have the following:
#!/bin/bash PROCESS_NAME="$1" ps -ef | grep "$PROCESS_NAME" | awk '{print $1}' (like I said RUBBISH!) |
Quote:
http://tldp.org/LDP/abs/html/ Unless you practice and solve problems on your own, you'll NEVER be good at it. |
TBOne has it right. Break your requirements down into individual steps and figure out how to do them first. Then assemble them into your final script.
I don't think it will hurt to give you a couple of quick tips too. 1) Notice how one of the processes you get in the output is the search process itself? How can you eliminate that? 2) It's not generally necessary to use grep and awk together. awk can do its own line matching. 3) Don't try to do everything at once. Break the script up into smaller steps. Capture your output into variables, or an array, if you get a list of values. Then process those. I highly recommend the BashGuide for learning the basic concepts, and the related FAQ and Pitfalls pages for overcoming common issues and errors: http://mywiki.wooledge.org/BashGuide http://mywiki.wooledge.org/BashFAQ http://mywiki.wooledge.org/BashPitfalls |
Thanks David, I am going to spend a bit of time on this tonight, I will post my results later.
|
All times are GMT -5. The time now is 12:13 AM. |