- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: check process
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:00 PM
09-20-2005 06:00 PM
in and it lookes like this
0:30 54545
0:44 66788
0:50 23233
i need to read every line in the file and get the time and if the process is greater then 0:30 to kill the process id
the script looks like this
cat bbb | while read line
do
#kill -9 $i
done
i don't how to take of the hour , ask about it and kill the process
can you please help me and another question
did i do the loop ok did i need the pipe before the while
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:16 PM
09-20-2005 06:16 PM
Re: check process
while read time pid
do
sec=$(echo $time | cut -d":" -f1)
[[ $sec -gt 30 ]] && kill -9 $pid
done <
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:21 PM
09-20-2005 06:21 PM
Re: check process
# awk '{ split($1,a,":"); if ( a[2] > 30 ) { print "kill -9 " $2 } }'
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:27 PM
09-20-2005 06:27 PM
Re: check process
perl -ne '($time,$pid)=split; @min=split(/:/,$time); kill 9,$pid if $min[1] > 30;'
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:40 PM
09-20-2005 06:40 PM
Re: check process
I use your script , but I tried to echo the $sec , all sec are "0" ( it should be 30 , 44 , 50 ) , so no one record greater than 30 , could suggest what is wrong ? thx
while read time pid
do
sec=$(echo $time | cut -d":" -f1)
[[ $sec -gt 30 ]] && kill -9 $pid
done <
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 06:42 PM
09-20-2005 06:42 PM
Re: check process
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 07:02 PM
09-20-2005 07:02 PM
Re: check process
it works now , it I want to script to check the process 3 times in very 1 minutes , the crontab job only can run 1 time in 1 minute , could suggest what can I do ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 07:05 PM
09-20-2005 07:05 PM
Re: check process
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 07:07 PM
09-20-2005 07:07 PM
Re: check process
do
while read time pid
do
sec=$(echo $time | cut -d":" -f2)
[[ $sec -gt 30 ]] && kill -9 $pid
done <
sleep 20
done
this will run in an infinite loop until you interrupt it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 08:14 PM
09-20-2005 08:14 PM
Re: check process
the process can run repeatedly now , but if I add it to the cron , the process will run many many times , so I think it can't be add to the crontab , could suggest if not add to the crontab , how to make sure the job is keep on running ? thx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 08:25 PM
09-20-2005 08:25 PM
Re: check process
#!/bin/ksh
# psck.ksh
while [ TRUE ]
while read time pid
do
ps -ef | grep -q $pid |grep -v grep
if [[ $? -eq 0 ]]
then
sec=$(echo $time | cut -d":" -f1)
[[ $sec -gt 30 ]] && kill -9 $pid
echo "$pid is killed @ $(date)" >>/tmp/logfile
fi
done <
sleep 60
done
# end
Run this script as,
# chmod +x psck.ksh
# ./psck.ksh &
# tail -f /tmp/logfile give details of process which killed.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 08:46 PM
09-20-2005 08:46 PM
Re: check process
your explaination is very detail , but I am not too understand how to make sure the script is running in the system if not add it to the crontab ? thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2005 10:34 PM
09-20-2005 10:34 PM
Re: check process
So make a loop in that script which runs 3 times.
Now add that script in cron scheduled for every minute.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2005 01:04 AM
09-21-2005 01:04 AM
Re: check process
By the way: are you sure you want to use kill -9? It is a very bad command to use against programs, especially databases and other applications that use shared application resources. It is strongly recommended that you use kill -15, followed by a kill -1 (if kill -15 doesn't work) and finally kill -9 as a last resort.
Bill Hassell, sysadmin