-1

I have started working on Linux recently. I'm looking for a solution for monitoring a folder for zipped files and unzip them. I have created a simple script(say unzip.sh) to unzip the files but there is no fix time at which zipped are received, so I want to use a script that checks for zipped files and calls this unzip.sh script if found any zipped files. Thanks.

#!/bin/sh
cd <dir name>
for i in `find . -name "*.gz"`; do
    gunzip $i
done
Socowi
  • 25,550
  • 3
  • 32
  • 54
  • 2
    You can use `inotifywait` to do things only when new files are placed inside a folder. See [this answer](https://superuser.com/a/959040/652023). – Socowi Jun 22 '18 at 12:29
  • you can use schedule the script in `crontab`. – User123 Jun 22 '18 at 12:35
  • [How to run a shell script when a file or directory changes?](https://stackoverflow.com/q/4060212/608639) and friends like [linux bash filesystem notification](https://www.google.com/search?q=linux+bash+filesystem+notification). – jww Jun 23 '18 at 05:33

1 Answers1

-1

crontab is what you need

Build a simple textfile like this:

*/5 * * * * bash /path/to/your/script.sh

Assuming you called this file my.cron, then you can install it with

crontab my.cron

The script will then run every 5 minutes. here some more examples: https://crontab.guru/examples.html

Stop it again with

crontab -r
frank
  • 1,007
  • 1
  • 6
  • 13