Kind of a newbie to bash, sorry.

I wanted to generate a script to enter all directories under current_directory with "bifn*0.2e" in the name and then automatically delete files every minute with "acc" in the name. These are continuously being generated by another process. This is what I have and it seems to work.


while true
    find /current_directory/bifn*0.2e* -name '*acc*' -mmin +1 -delete
    sleep 60

However, after I ran the script ./auto_remove, I did a Ctrl+Z and bg to keep it in the background running. I wanted this script to continue removing files even after I exit the terminal. That part works too. But now I cannot kill what it is doing, nor do I see evidence the script is going (except that the acc files are being removed!). I have tried typing ps fjx or jobs. I have also tried re-running the script with the find line commented out.

So, please help me to stop what it is doing! And, for future use, how can I more elegantly do what I want to do while being able to terminate it when needed?

  • Did you invoke jobs in the shell that started the script? – Kamil Maciorowski Feb 4 at 19:47
  • No. I exited that terminal before I knew I what I was doing! – cmc0605 Feb 4 at 19:48
  • I would expect ps fjx to show /bin/bash ./auto_remove among other entries. Does ps fjx | grep auto_remove show anything besides the grep itself? – Kamil Maciorowski Feb 4 at 20:00
  • No, I'm on a remote connection sops fjx shows sshbd: <my_username>@pts/36 and -bash and _ ps fjx. ps fjx | grep auto_remove shows _ grep auto_remove – cmc0605 Feb 4 at 20:14
  • Also, pstree -pa <my_username> does not give me any evidence this exists: sshbd,13042 ├─bash,13043 └─bash,13706 └─pstree,22852 -pa my_username – cmc0605 Feb 4 at 21:12

Well, I found the problem with terminating. I had to login to the particular node that was executing that script, to then execute kill. I still am not sure how to avoid this in the future.

| improve this answer | |

Half of the script is unnecessary. Remove all checks for time. Just set it to check for name and delete. Then set it in the crontab on each minute. If you want to stop it for some reason, just stop the cron by commenting the execution line and restart the cron

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.