0

我想在 bash 脚本中获取 ftp 的 pid ...在 solaris 上运行

这是我的脚本:

#!/usr/bin/bash
...
ftp -inv $FTPDEST <<EOF
user $USER $PASS
put $file
EOF

我想获取 ftp 命令的 pid,以便在检查它是否挂起并杀死它之后。我有一个服务器崩溃,因为当 ftp 断开连接时大约有 200 个 ftp 进程打开。对于某些人ftp 进程保持打开的原因。

谢谢马里奥

4

1 回答 1

0

这似乎是您所描述的,但可能不是您真正需要的。这是一种黑客行为......

#!/usr/bin/bash
trap 'exit 0' SIGUSR1   # this is the normal successful exit point

 # trigger the trap if ftp in a background process completes before 10 seconds    
(ftp -inv $FTPDEST <<-EOF 2>>logfile
user $USER $PASS
put $file
EOF 
kill -s SIGUSR1 $PPID ) &   # last line here shuts process down.  and exits with success

childpid=$!    # get the pid of the child running in background
sleep 10       # let it run 10 seconds

kill $childpid # kill off the ftp command, hope we get killed of first
wait
exit 1    # error exit ftp got hung up

父级等待 10 秒,而 ftp 子级在 10 秒内完成以成功退出。
成功意味着孩子向父母发送一个 SIGUSR1 信号,然后通过陷阱退出。

如果子进程花费的时间太长,父进程会终止慢速 ftp 子进程并错误退出。

于 2013-08-07T02:46:42.787 回答