假如我想批量kill ascp进程
#!/bin/bash# Get PIDs of all running ascp processes
pids=$(ps -ef | grep '[a]scp' | awk '{print $2}')# Loop through each PID and try to terminate the process gracefully
for pid in $pids; doecho "Attempting to gracefully terminate ascp process with PID: $pid"kill -15 $pid
donesleep 5# Check if processes are still running and forcefully terminate if necessary
for pid in $pids; doif kill -0 $pid 2>/dev/null; thenecho "Forcefully terminating ascp process with PID: $pid"kill -9 $pidfi
doneecho "All ascp processes have been handled."
- Save the script as
terminate_ascp.sh
. - Make it executable:
chmod +x terminate_ascp.sh
. - Run the script:
./terminate_ascp.sh
. You might need to usesudo
if the processes are not owned by your user.