- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Options for a time out variable for FTP (outgoing)...
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
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
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
03-27-2014 08:31 AM - last edited on 03-27-2014 06:35 PM by Lisa198503
03-27-2014 08:31 AM - last edited on 03-27-2014 06:35 PM by Lisa198503
We have FTP disabled (no entry in inetd.conf) for incoming requests but do allow outgoing FTP. We are running into an issue where sometimes a FTP session (outgoing to various hosts uses different user accounts on internal network) will just hang and not terminate. Is there a global setting somewhere to have all outgoing FTP sessions terminate after so much time has elasped?
Thanks
HPUX 11.31 (Shadow mode user authentification)
P.S. This thread has been moved from HP-UX>System Administration to HP-UX > networking. -HP Forum Moderator
Legalize Freedom
Solved! Go to Solution.
- Tags:
- ftp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2014 12:22 PM
03-28-2014 12:22 PM
Re: Options for a time out variable for FTP (outgoing) sessions?
What you'll need to do is to create a separate ftp script. Then the batch job timer script will start the script in the background (add & at the end). Immediately after starting the ftp script, capture the background PID from $! and start a timer. You check for the existence of the script every second or two until either the BGPID goes away or the timer expires, something like this:
TIMELIMIT=300 # run the ftp job
ftp_script & BGID=$! while [[ $TIMELIMIT -gt 0 ]] do [[ $(ps -p $BGID | grep -c $BGID) -eq 0 ]] && exit TIMELIMIT=$((TIMELIMIT-1)) sleep 1 done # time limit reached, kill the script # Use kill -15, then -1 finally -9 kill -15 $BGID if [[ $(ps -p $BGID | grep -c $BGID) -gt 0 ]] then kill -1 $BGID if [[ $(ps -p $BGID | grep -c $BGID) -gt 0 ]] then kill -9 $BGID fi fi
The script monitors the PID of the ftp script. When it disappears, the script exits normally. But when TIMELIMIT reaches 0, the loop finishes and it then tries 3 ways to kill the script. The reason for 3 ways is that with all networking tools, hangs can be very difficult to kill. If you want, you can just replace the multiple kills with a single kill -9. I prefer a gentler sequence as standard practice.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2014 06:52 PM
03-28-2014 06:52 PM
Re: Options for a timeout variable for FTP (outgoing) sessions?
>something like this:
Some improvements:
>[[ $(ps -p $BGID | grep -c $BGID) -eq 0 ]]
Why use "grep -c"? Why not grep -q -w? -w for whole PID match.
ps -p $BGID | grep -qw $BGID || exit # if not found
And same for:
if ps -p $BGID | grep -qw $BGID; then
Or:
ps -p $BGID | grep -qw $BGID
if [ $? -eq 0 ]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2014 01:12 PM - edited 03-30-2014 08:44 PM
03-29-2014 01:12 PM - edited 03-30-2014 08:44 PM
Solution>> Why use "grep -c"? Why not grep -q -w? -w for whole PID match.
>> ps -p $BGID | grep -qw $BGID || exit # if not found
This is a force of habit because grep -w did not exist before HP-UX 11.11 so I use -c.
Also, ps -p is an exact match (there will be exactly zero or one occurences of the BGID).
The grep is to ignore the header line.
So the first test:
[[ $(ps -p $BGID | grep -c $BGID) -eq 0 ]] && exit
can be futher simplfied to:
ps -p $BGID >/dev/null || exit
and the subsequent tests for kill success can be this:
if ps -p $BGID >/dev/null; then
Years ago, I read that in Unix, if you can't do the same thing at least 3 different ways, you haven't tried hard enough.
So rewritten, it would look like this:
TIMELIMIT=300 # run the ftp job ftp_script & BGID=$! while [[ $TIMELIMIT -gt 0 ]] do ps -p $BGID >/dev/null || exit TIMELIMIT=$((TIMELIMIT-1)) sleep 1 done # time limit reached, kill the script # Use kill -15, then -1 finally -9 kill -15 $BGID if ps -p $BGID >/dev/null; then kill -1 $BGID ps -p $BGID >/dev/null && kill -9 $BGID fi
I turned this into a function and tested it as a tool for handling processes/scripts that may hang.
Since it puts the process into the background, stdout and stderr should be redirected or changed to a logfile or use logger to keep records of the process activity.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2014 11:36 AM
05-07-2014 11:36 AM
Re: Options for a timeout variable for FTP (outgoing) sessions?
You are the man Bill....I remember you way back if this is the same Bill been our here for over a decade. Thanks for the information greatly appreciated. Hope all is well for you and your career.
Mike Bray
Legalize Freedom