nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Help with killing

This is a discussion on Help with killing within the Shell scripting forums, part of the Development/Scripting category; HI guys me again my counterstrike script is coming on greatguns now over 600 hundread lines long now (599 of ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 04-12-2006, 06:18 AM
Member
User
 
Join Date: Mar 2006
Posts: 35
Rep Power: 0
sparky
Default Help with killing

HI guys me again my counterstrike script is coming on greatguns now over 600 hundread lines long now (599 of them are coments )
This is what the user see when they log in

What do you wish to do ? anwser 1 to 10

1. Start css server
2. Change rcon pass word
3. View server start details
4. Add user details
5 View user detail
6. Server.cfg tick conf
7. Restart Servers
8. Teamspeak options
9. Search for records
10. Delete records

Answer (or 'q' to quit)?
all i need to do now is sort out options 7 and 8 . but i am having trouble with option 7 stopping and restart servers what i want to happen is if the user chooses to restart server he enters a port number then i need to get the pid number for that server and kill it.
if they want to stop server i need to get two pid numbers and kill

heres the two commands from ps -aux

./srcds_amd -game cstrike -port 27025 +ip 194.105.134.151 +maxplayer
/bin/sh ./srcds_run -game cstrike -port 27025 +ip 194.105.1

to restart i just need to kill top line
to stop server i would kil both

Any help would be great
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-12-2006, 07:48 AM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default Re: Help with killing

Quote:
Originally Posted by sparky
HI guys me again my counterstrike script is coming on greatguns now over 600 hundread lines long now (599 of them are coments )
LOL 599 comments.

Quote:
all i need to do now is sort out options 7 and 8 . but i am having trouble with option 7 stopping and restart servers what i want to happen is if the user chooses to restart server he enters a port number then i need to get the pid number for that server and kill it.
Try netstat to grab pid according to your PORT-NUMBER:
Code:
netstat -p -vant  | grep PORT-NUMBER | awk '{ print $7}' | cut -d'/' -f1
netstat -p -vant  | grep 27025 | awk '{ print $7}' | cut -d'/' -f1
Quote:
to stop server i would kil both
Use killall command:
Code:
killall program-name
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #3 (permalink)  
Old 04-12-2006, 03:36 PM
Member
User
 
Join Date: Mar 2006
Posts: 35
Rep Power: 0
sparky
Default

thanks for your reply.
Not tried your line of code as unsure what it all means

progress:
i.ve used grep to get both lines for port i need
saved them to file
used sed to delete the line with run in it so iam only left with one line.

where i am stuck now is how to get awk to turn $2 in to var so as i can then kill that proccess

Code:
#!/bin/sh
tmpfile=tmpfile.txt
run=run
tmpfile1=tempile1.txt

[ ! -f $tmpfile ] && > $tmpfile
[ ! -f $tmpfile1 ] && > $tmpfile1

echo "Enter a port"
read port

ps auxww | grep $port >> $tmpfile             #gets both line


sed "/$run/d" $tmpfile >> $tmpfile1          #deletes line i don t need
	mv $tmpfile1 $tmpfile                    #1 line left $2 pid number i need

#need to cat $tmpfile then | awk '{print $2}'  
# and kill $2
thanks
Reply With Quote
  #4 (permalink)  
Old 04-13-2006, 01:14 AM
tom tom is offline
Contributors
User
 
Join Date: Jun 2005
Location: London, UK
Posts: 213
Rep Power: 4
tom is on a distinguished road
Default

Quote:
cat $tmpfile then | awk '{print $2}'
Try out

Code:
var=$(cat $tmpfile | awk '{print $2}')
echo $var
Reply With Quote
  #5 (permalink)  
Old 04-13-2006, 01:25 AM
Member
User
 
Join Date: Mar 2006
Posts: 35
Rep Power: 0
sparky
Default

LOL Just came to post i sussed it
just came to me but hay still very new to me
Thanks any way Tom
Reply With Quote
  #6 (permalink)  
Old 04-14-2006, 06:52 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Tom is our new scripting buff
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Killing of a process and send a mail if the process doesnot come up within 2 minutes Prince89 Shell scripting 1 02-11-2008 01:39 PM


All times are GMT +5.5. The time now is 09:25 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36