The logic applies to many other objectives.
And how to read .sh_history of each user from /home/ filesystem? What if there are thousandthousands of them?
#!/bin/ksh
last |head -10|awk '{print $1}'|
while IFS= read -r line
do
su - "$line" -c 'tail .sh_history'
done```
Here is the script https://github.com/imvieira/SysAdmin_DevOps_Scripts/blob/master/get_and_run.shdone
Here is the script.