- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script in cron job kills needed processes
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
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
01-30-2006 03:56 AM
01-30-2006 03:56 AM
Script in cron job kills needed processes
Do I need to recycle cron?
Here is the script:
#!/usr/bin/sh
# kill_nonterm_procs
#
ps -ef | grep "?" > /tmp/RUNPROCS
cat /tmp/RUNPROCS | awk '{ print $1 }' > /tmp/RUNPROCS_USERS
cat /tmp/RUNPROCS_USERS |
grep -v mfg |
grep -v mls |
grep -v root |
grep -v adusys |
grep -v pedi53 |
grep -v pedi54 |
grep -v lp |
grep -v tngadmin|
grep -v ftp |
grep -v patrol |
grep -v patuser |
grep -v jzbnvs |
grep -v grep | sort -u > /tmp/RUNPROCS_USERS_CLEAN
if [ -s /tmp/RUNPROCS_USERS_CLEAN ]
then
for i in `cat /tmp/RUNPROCS_USERS_CLEAN`
do
echo `date` >>/tmp/GG
echo `ps -fu $i | grep -v UID | grep "?"` >> /tmp/GG
PROCS=`ps -fu $i | grep "?" | grep -v PID | grep -v grep | sort -u | awk '{print $2 }'`
if [ -n "$PROCS" ]
then
kill -15 $PROCS
else
:
fi
done
rm /tmp/RUNPROCS
rm /tmp/RUNPROCS_USERS
rm /tmp/RUNPROCS_USERS_CLEAN
else
exit 2
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 03:57 AM
01-30-2006 03:57 AM
Re: Script in cron job kills needed processes
crontabl -l > cronfile
edit cronfile to make changes
crontab cronfile
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 03:59 AM
01-30-2006 03:59 AM
Re: Script in cron job kills needed processes
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 04:01 AM
01-30-2006 04:01 AM
Re: Script in cron job kills needed processes
Question is, why are you wanting to kill processes not attatched to a terminel?
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 04:13 AM
01-30-2006 04:13 AM
Re: Script in cron job kills needed processes
I need to run this script every 30 minutes because there are thousands of users who connect to the server using a windows telnet client and do not log out. Their session shows in "ps -ef" with a question mark.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 04:47 AM
01-30-2006 04:47 AM
Re: Script in cron job kills needed processes
who -p
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 04:49 AM
01-30-2006 04:49 AM
Re: Script in cron job kills needed processes
who -du
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 05:10 AM
01-30-2006 05:10 AM
Re: Script in cron job kills needed processes
Otherwise, the ps way may be the only way....
Which user is it still killing?
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 05:25 AM
01-30-2006 05:25 AM
Re: Script in cron job kills needed processes
Instead of making an exclusion list and killing everyone else I think I would make an inclusion list, set up in a for loop, and use ps -fu instead of -ef
That way you are certain that you are only killing user processes for those users its ok to kill those processes for and that your not missing that should be killed just because the processes happens to have one of your excluded strings in description.
#!/usr/bin/sh
for user in user1 user2 user3 user4 user5
do
ps -fu $user | get process list to kill
kill process list
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 06:03 AM
01-30-2006 06:03 AM
Re: Script in cron job kills needed processes
The script works fine when run manually meaning it excludes the newly added user (in my case user "tngadmin").
The problem occurs when run from cron. I re-read the crontab file with "crontab -e" but it keeps killing the newly added to the exclusion list user "tngadmin".
So I am wondering if I need to recycle cron at a suitable time tonight!?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 06:16 AM
01-30-2006 06:16 AM
Re: Script in cron job kills needed processes
/sbin/init.d/cron stop ; /sbin/init.d/cron start
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 06:32 AM
01-30-2006 06:32 AM
Re: Script in cron job kills needed processes
I'd NOT delete the files in /tmp and see if the give you a clue as to which step in your script isn't excluding tngadmin and work forward from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 06:41 AM
01-30-2006 06:41 AM
Re: Script in cron job kills needed processes
Usually problems arise in scripts run from cron because of sparse environments. You get a VERY BASIC environment in cron.
Why not try this:
Modify the first line of the script to read
#!/usr/bin/sh -x
The '-x' will force you into 'debug mode'. Then modify your cron job so that you get an e-mail with the results of the run.
1 2 * * * scriptname 2>&1 | mailx -s "script output" youremailaddresshere
Then have a look at what you received to see if you can trace where the problem lies.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 06:48 AM
01-30-2006 06:48 AM
Re: Script in cron job kills needed processes
Possible solution for the telnet users:
1) Configure the applicaiton to terminate after a certain number of minutes of inactivity.
2) Configure the variable TMOUT for all users in their environment prior to running any application.
These two steps will self terminate sessions that have been left idle.
Good Luck,
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2006 07:16 AM
01-30-2006 07:16 AM