Shell Scripts - Killing a job....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Shell Scripts - Killing a job....
# 1  
Old 05-03-2011
Shell Scripts - Killing a job....

Hello all,

I need to write a shell script that does the following; Allows you to kill a job,(1) listing only the jobs you own, (2) asks for which job to kill, (3) kills the job and (4) confirms kill...

I am not sure if I need to first run the job command and pipe it with kill? Which options to include to make it most efficient and if this can be done all in one script? IF I should be using kill at all? Any help would be greatly appreciated.... I am struggling with this one. Thanks in advance, citizencro
# 2  
Old 05-04-2011
sounds like homework....

what have you got so far?
written any code at all?


read up on "kill" command and the "ps" command.
# 3  
Old 05-04-2011
ok I know that I can display all running processes with ps -ux. I can display only the processes that I am running by ps -U citizencro. I can kill what process I want with with kill -9 %pid and it will display that it was killed. I don't get how I can pipe the two together where it asks me out of my jobs which one do I want to kill, then kills and confirms it?
# 4  
Old 05-05-2011
Please define "job".
You mention the "jobs" command which suggests that you may mean background jobs started by your current session.
If not, by "job" do you actually mean "process"?

What Operating System and version do you have?
# 5  
Old 05-05-2011
I mean background jobs started by my session. I thought I would need to include processes with that also. I am using putty to access our server.
# 6  
Old 05-09-2011
something like this maybe?

Code:
#!/usr/bin/ksh
clear
ps -ef  | grep citizencro | awk '{print $2}' >> /tmp/proclist
echo "The following pids are owned by citizencro"
cat /tmp/proclist
echo "Which one would you like to kill?"
read PROCKILL
echo "you are going to kill the following pid $PROCKILL, type yes to continue"
read CONTINUE
case $CONTINUE in
 yes|Yes|Y)
kill -9 $PROCKILL
;;
 *)
exit 1
;;
esac
PROCNUM=`ps -ef  | grep -v grep | grep $PROCKILL | wc -l`
clear
echo "there are $PROCNUM process running with the $PROCKILL pid"


Last edited by sboots; 05-09-2011 at 03:50 PM..
# 7  
Old 05-09-2011
Quote:
Originally Posted by citizencro
Hello all,

I need to write a shell script that does the following; Allows you to kill a job,(1) listing only the jobs you own, (2) asks for which job to kill, (3) kills the job and (4) confirms kill...

I am not sure if I need to first run the job command and pipe it with kill? Which options to include to make it most efficient and if this can be done all in one script? IF I should be using kill at all? Any help would be greatly appreciated.... I am struggling with this one. Thanks in advance, citizencro
"jobs" is specific shell and according to me only jobs command is enough so need a script "is really necessary"..i dont know but maybe this script(exshell) can give an idea..
https://www.unix.com/shell-programmin...al-script.html

regards
ygemici
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Executing python scripts via cron job

Hi, I'm executing a python script via cron job. The way it is set up is, I'm editing a file called local00 22 * * * root su - -c "/opt/setup_dir/bin/run_bkp -p" When this job executes, the command-specific logfile and the syslog (where the logs are supposed to go) show half of the logs(no... (2 Replies)
Discussion started by: ashwini.engr07
2 Replies

2. UNIX for Advanced & Expert Users

Issue while killing the process using autosys job

Hi, I have one autosys job that will retrieve the proccess id's and will kill those processess as follows, pid=`/usr/ucb/ps -auwwxx | grep MAIN |nawk '{print $2}'` kill -9 pid but after executing this particular job, its status is showing as TE(terminated) and the kill process is... (3 Replies)
Discussion started by: Kattoor
3 Replies

3. Shell Programming and Scripting

cron job is not working for two scripts

Hi Gurus, I have a test unix server in which currently some unix cronjob are running. I have written two script one is a shell script in which env variable are there (in that i am exporting those variables). I have also written a perl script . when i am running at the shell manually like... (5 Replies)
Discussion started by: sanjay.login
5 Replies

4. Shell Programming and Scripting

Paid job for bash shell scripts

Job ad removed (1 Reply)
Discussion started by: starmation
1 Replies

5. Shell Programming and Scripting

Killing a shell script

Hi, If I have a large shell script running as root, say for example like one that copies a ton of files, how would I kill the shell script and any processes that it created? Thanks (7 Replies)
Discussion started by: pcwiz
7 Replies

6. UNIX for Dummies Questions & Answers

CRON job to execute all scripts in a directory

Hi everyone: I'm trying to make a CRON job that will execute Fridays at 7am. I have the following: * 7 * * 5 I've been studying up on CRON and I know to have this in a file and then "crontab filename.txt" to add it to the CRON job list. The CRON part I believe I understand, but I would... (6 Replies)
Discussion started by: Annorax
6 Replies

7. Solaris

killing a unix job after the job process gets completed

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. Thanks... (7 Replies)
Discussion started by: dtazv
7 Replies

8. Shell Programming and Scripting

check if job still alive and killing it after a certain walltime

Hi! I'm using a script to start a process that might run forever if some parameters are given wrong (it's part of an optimization). I would now like to have the process killed after a certain walltime in that case. So far I get it done with the following lines ./My_process.e & pid=`ps -ef |... (3 Replies)
Discussion started by: ciwstevie
3 Replies

9. Shell Programming and Scripting

killing unix job after the job process completes

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. ... (1 Reply)
Discussion started by: dtazv
1 Replies

10. Shell Programming and Scripting

Killing processes in scripts

I have a small problem. It's annoying though. I wrote this shell script: # # This script will accept two arguments. The first is a flag and the # second is a time interval. The only valid flag is '-t' which means # the user will specify the interval in seconds, otherwise the # default is 600... (3 Replies)
Discussion started by: el_toro
3 Replies
Login or Register to Ask a Question